schema_sentinel.metadata_manager.model.table_constraint API documentation

# schema_sentinel.metadata_manager.model.table_constraint

View Source

     1import json
     2
     3import sqlalchemy as db
     4from sqlalchemy import ForeignKey, select
     5
     6from . import CommonBase
     7
     8
     9class TableConstraint(CommonBase):
    10    __tablename__ = "table_constraints"
    11    table_constraint_id = db.Column(db.String, primary_key=True)
    12    table_constraint_schema_id = db.Column(db.String, ForeignKey("schemas.schema_id"))
    13    table_id = db.Column(db.String, ForeignKey("tables.table_id"))
    14    table_constraint_name = db.Column(db.String)
    15    constraint_type = db.Column(db.String)
    16    is_deferrable = db.Column(db.String, default="NO")
    17    initially_deferred = db.Column(db.String, default="NO")
    18    enforced = db.Column(db.String, default="NO")
    19    comment = db.Column(db.String)
    20    created = db.Column(db.String)
    21    last_altered = db.Column(db.String)
    22    rely = db.Column(db.String)
    23
    24    def save(self, session) -> None:
    25        if not session.execute(self.exists()).first():
    26            session.add(self)
    27            session.commit()
    28
    29    def exists(self) -> str:
    30        return select(TableConstraint).filter_by(table_constraint_id=self.table_constraint_id)
    31
    32    def __get_id__(self) -> str:
    33        id = json.loads(self.table_id)
    34        id["table_constraint_name"] = self.table_constraint_name
    35        return json.dumps(id)

class TableConstraint(schema_sentinel.metadata_manager.model.CommonBase): View Source

    10class TableConstraint(CommonBase):
    11    __tablename__ = "table_constraints"
    12    table_constraint_id = db.Column(db.String, primary_key=True)
    13    table_constraint_schema_id = db.Column(db.String, ForeignKey("schemas.schema_id"))
    14    table_id = db.Column(db.String, ForeignKey("tables.table_id"))
    15    table_constraint_name = db.Column(db.String)
    16    constraint_type = db.Column(db.String)
    17    is_deferrable = db.Column(db.String, default="NO")
    18    initially_deferred = db.Column(db.String, default="NO")
    19    enforced = db.Column(db.String, default="NO")
    20    comment = db.Column(db.String)
    21    created = db.Column(db.String)
    22    last_altered = db.Column(db.String)
    23    rely = db.Column(db.String)
    24
    25    def save(self, session) -> None:
    26        if not session.execute(self.exists()).first():
    27            session.add(self)
    28            session.commit()
    29
    30    def exists(self) -> str:
    31        return select(TableConstraint).filter_by(table_constraint_id=self.table_constraint_id)
    32
    33    def __get_id__(self) -> str:
    34        id = json.loads(self.table_id)
    35        id["table_constraint_name"] = self.table_constraint_name
    36        return json.dumps(id)

The base class of the class hierarchy.

When called, it accepts no arguments and returns a new featureless instance that has no instance attributes and cannot be given any.

TableConstraint(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in `kwargs`.

Only keys that are present as attributes of the instance's class are allowed. These could be, for example, any mapped columns or relationships.

table_constraint_id
table_constraint_schema_id
table_id
table_constraint_name
constraint_type
is_deferrable
initially_deferred
enforced
comment
created
last_altered
rely
def save(self, session) -> None: View Source

    25    def save(self, session) -> None:
    26        if not session.execute(self.exists()).first():
    27            session.add(self)
    28            session.commit()

def exists(self) -> str: View Source

    30    def exists(self) -> str:
    31        return select(TableConstraint).filter_by(table_constraint_id=self.table_constraint_id)