Source code for luna_accounts.db.accounts_db_tools.models.accounts_models

from luna_db_tools.functions import currentDBTimestamp
from sqlalchemy import ForeignKey, Column, String, TIMESTAMP
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.dialects.oracle import CLOB

from .config import DBConfig

# raw sql function to get utc timestamp for creating/updating table columns
DB_CURRENT_TIMESTAMP = currentDBTimestamp(DBConfig.dbType) if DBConfig.dbType else None

Base = declarative_base()


[docs] class Account(Base): """ Account table """ __tablename__ = "account" __table_args__ = {"comment": "Table with accounts."} account_id = Column(String(36), primary_key=True, comment="account id") login = Column(String(128), nullable=False, unique=True, index=True, comment="login") password = Column(String(128), nullable=False, comment="password") description = Column(String(128), nullable=True, comment="description") account_type = Column(String(16), nullable=False, comment="account type") create_time = Column(TIMESTAMP, server_default=DB_CURRENT_TIMESTAMP, index=True, nullable=False, comment="date and time: account create time") last_update_time = Column(TIMESTAMP, server_default=DB_CURRENT_TIMESTAMP, index=True, nullable=False, comment="date and time: account last update time")
[docs] class Token(Base): """ Token table """ __tablename__ = "token" __table_args__ = {"comment": "Table with tokens."} token_id = Column(String(36), primary_key=True, comment="token id") account_id = Column(String(36), ForeignKey("account.account_id", ondelete="CASCADE"), nullable=False) permissions = Column(CLOB() if DBConfig.dbType == "oracle" else String(), comment="permissions", nullable=False) expiration_time = Column(TIMESTAMP, index=True, nullable=True, comment="token expiration time") description = Column(String(128), nullable=True, comment="description") visibility_area = Column(String(16), nullable=False, comment="token visibility area") create_time = Column(TIMESTAMP, server_default=DB_CURRENT_TIMESTAMP, index=True, nullable=False, comment="date and time: token create time") last_update_time = Column(TIMESTAMP, server_default=DB_CURRENT_TIMESTAMP, nullable=False, comment="date and time: token last update time")