schema_sentinel.metadata_manager.model.column_constraint API documentation

# schema_sentinel.metadata_manager.model.column_constraint

View Source

     1import json
     2
     3import sqlalchemy as db
     4from sqlalchemy import ForeignKey, select
     5
     6from . import CommonBase
     7
     8
     9class ColumnConstraint(CommonBase):
    10    __tablename__ = "column_constraints"
    11    column_constraint_id = db.Column(db.String, primary_key=True)
    12    pk_constraint_id = db.Column(db.String, ForeignKey("constraints.constraint_id"))
    13    fk_constraint_id = db.Column(db.String, ForeignKey("constraints.constraint_id"))
    14    pk_column_id = db.Column(db.String, ForeignKey("columns.column_id"))
    15    fk_column_id = db.Column(db.String, ForeignKey("columns.column_id"))
    16    pk_name = db.Column(db.String)
    17    fk_name = db.Column(db.String)
    18
    19    key_sequence = db.Column(db.String)
    20    comment = db.Column(db.String)
    21    created = db.Column(db.String)
    22    deferrability = db.Column(db.String)
    23    rely = db.Column(db.String)
    24    update_rule = db.Column(db.String)
    25    delete_rule = db.Column(db.String)
    26
    27    def save(self, session) -> None:
    28        if not session.execute(self.exists()).first():
    29            session.add(self)
    30            session.commit()
    31
    32    def exists(self) -> str:
    33        return select(ColumnConstraint).filter_by(column_constraint_id=self.column_constraint_id)
    34
    35    def __get_id__(self) -> str:
    36        pk_column_id = json.loads(self.pk_column_id)
    37        fk_column_id = json.loads(self.fk_column_id)
    38        return json.dumps(
    39            {
    40                "pk_column_id": pk_column_id,
    41                "pk_name": self.pk_name,
    42                "fk_column_id": fk_column_id,
    43                "fk_name:": self.fk_name,
    44            }
    45        )

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

    10class ColumnConstraint(CommonBase):
    11    __tablename__ = "column_constraints"
    12    column_constraint_id = db.Column(db.String, primary_key=True)
    13    pk_constraint_id = db.Column(db.String, ForeignKey("constraints.constraint_id"))
    14    fk_constraint_id = db.Column(db.String, ForeignKey("constraints.constraint_id"))
    15    pk_column_id = db.Column(db.String, ForeignKey("columns.column_id"))
    16    fk_column_id = db.Column(db.String, ForeignKey("columns.column_id"))
    17    pk_name = db.Column(db.String)
    18    fk_name = db.Column(db.String)
    19
    20    key_sequence = db.Column(db.String)
    21    comment = db.Column(db.String)
    22    created = db.Column(db.String)
    23    deferrability = db.Column(db.String)
    24    rely = db.Column(db.String)
    25    update_rule = db.Column(db.String)
    26    delete_rule = db.Column(db.String)
    27
    28    def save(self, session) -> None:
    29        if not session.execute(self.exists()).first():
    30            session.add(self)
    31            session.commit()
    32
    33    def exists(self) -> str:
    34        return select(ColumnConstraint).filter_by(column_constraint_id=self.column_constraint_id)
    35
    36    def __get_id__(self) -> str:
    37        pk_column_id = json.loads(self.pk_column_id)
    38        fk_column_id = json.loads(self.fk_column_id)
    39        return json.dumps(
    40            {
    41                "pk_column_id": pk_column_id,
    42                "pk_name": self.pk_name,
    43                "fk_column_id": fk_column_id,
    44                "fk_name:": self.fk_name,
    45            }
    46        )

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.

ColumnConstraint(**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.

column_constraint_id
pk_constraint_id
fk_constraint_id
pk_column_id
fk_column_id
pk_name
fk_name
key_sequence
comment
created
deferrability
rely
update_rule
delete_rule
def save(self, session) -> None: View Source

    28    def save(self, session) -> None:
    29        if not session.execute(self.exists()).first():
    30            session.add(self)
    31            session.commit()

def exists(self) -> str: View Source

    33    def exists(self) -> str:
    34        return select(ColumnConstraint).filter_by(column_constraint_id=self.column_constraint_id)