Source code for luna_handlers.db.models
from typing import List
from sqlalchemy import Column, String, TIMESTAMP, Boolean, Integer, Index, MetaData
from sqlalchemy.dialects.oracle import CLOB
from sqlalchemy.ext.declarative import declarative_base
from crutches_on_wheels.utils.db_functions import currentDBTimestamp
from db.models_config import DBConfig
Base = declarative_base()
# raw sql function to get utc timestamp for creating/updating table columns
DB_CURRENT_TIMESTAMP = currentDBTimestamp(DBConfig.dbType) if DBConfig.dbType else None
[docs]class Handler(Base):
"""
Database table model for handlers.
"""
__tablename__ = "handler"
Base.metadata = MetaData()
#: str: handler id, uuid4 in format "xxxxxxxx-xxxx-4xxx-{8-9}xx-xxxxxxxxxxxx"
handler_id = Column(String(36), primary_key=True)
#: str: account uuid4 in format "xxxxxxxx-xxxx-4xxx-{8-9}xx-xxxxxxxxxxxx", to which this handler belong
account_id = Column(String(36), nullable=False)
#: DateTime: date and time of creation handler
create_time = Column(TIMESTAMP, server_default=DB_CURRENT_TIMESTAMP, nullable=False)
#: DateTime: date and time of last change of the handler
last_update_time = Column(TIMESTAMP, server_default=DB_CURRENT_TIMESTAMP, nullable=False)
#: str: a client handler description
description = Column(String(128), index=True)
#: str: json with policies
policies = Column(CLOB) if DBConfig.dbType == "oracle" else Column(String)
#: bool: whether a handler is dynamic
is_dynamic = Column(Boolean, nullable=False)
ix_handler_account_id_create_time = Index("ix_handlers_account_id_create_time", "account_id", "create_time")
[docs] @classmethod
def getColumnNames(cls) -> List[str]:
"""
Get all column name of table.
Returns:
list of column name in order as in db
"""
return cls.__table__.columns._data._list
[docs]class Verifier(Base):
"""
Database table model for verifiers.
"""
__tablename__ = "verifier"
Base.metadata = MetaData()
#: str: verifier id
verifier_id = Column(String(36), primary_key=True)
#: str: account id
account_id = Column(String(36), nullable=False)
#: DateTime: verifier creation time
create_time = Column(TIMESTAMP, server_default=DB_CURRENT_TIMESTAMP, nullable=False)
#: DateTime: verifier last update time
last_update_time = Column(TIMESTAMP, server_default=DB_CURRENT_TIMESTAMP, nullable=False)
#: str: verifier description
description = Column(String(128), index=True)
#: str: verifier policies
policies = Column(CLOB) if DBConfig.dbType == "oracle" else Column(String)
#: int: verifier version
version = Column(Integer, server_default="0", nullable=False)
ix_verifier_account_id_create_time = Index("ix_verifier_account_id_create_time", account_id, create_time)
[docs] @classmethod
def getColumnNames(cls) -> List[str]:
"""
Get all column name of table.
Returns:
list of column name in order as in db
"""
return cls.__table__.columns._data._list