schema_sentinel.metadata_manager.model.referential_constraint API documentation

# schema_sentinel.metadata_manager.model.referential_constraint

View Source

     1import json
     2
     3import sqlalchemy as db
     4from sqlalchemy import ForeignKey, select
     5
     6from . import CommonBase
     7
     8
     9class ReferentialConstraint(CommonBase):
    10    __tablename__ = "referential_constraints"
    11    referential_constraint_id = db.Column(db.String, primary_key=True)
    12    foreign_key_constraint_id = db.Column(db.String, ForeignKey("constraints.constraint_id"))
    13    unique_constraint_id = db.Column(db.String, ForeignKey("constraints.constraint_id"))
    14    fk_name = db.Column(db.String)
    15    pk_name = db.Column(db.String)
    16
    17    match_option = db.Column(db.String)
    18    update_rule = db.Column(db.String)
    19    delete_rule = db.Column(db.String)
    20    comment = db.Column(db.String)
    21    created = db.Column(db.String)
    22    last_altered = 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(ReferentialConstraint).filter_by(
    31            foreign_key_constraint_id=self.foreign_key_constraint_id,
    32            unique_constraint_id=self.unique_constraint_id,
    33        )
    34
    35    def __get_id__(self) -> str:
    36        return json.dumps(
    37            {
    38                "foreign_key_constraint_id": json.loads(self.foreign_key_constraint_id),
    39                "unique_constraint_id": json.loads(self.unique_constraint_id),
    40            }
    41        )

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

    10class ReferentialConstraint(CommonBase):
    11    __tablename__ = "referential_constraints"
    12    referential_constraint_id = db.Column(db.String, primary_key=True)
    13    foreign_key_constraint_id = db.Column(db.String, ForeignKey("constraints.constraint_id"))
    14    unique_constraint_id = db.Column(db.String, ForeignKey("constraints.constraint_id"))
    15    fk_name = db.Column(db.String)
    16    pk_name = db.Column(db.String)
    17
    18    match_option = db.Column(db.String)
    19    update_rule = db.Column(db.String)
    20    delete_rule = db.Column(db.String)
    21    comment = db.Column(db.String)
    22    created = db.Column(db.String)
    23    last_altered = 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(ReferentialConstraint).filter_by(
    32            foreign_key_constraint_id=self.foreign_key_constraint_id,
    33            unique_constraint_id=self.unique_constraint_id,
    34        )
    35
    36    def __get_id__(self) -> str:
    37        return json.dumps(
    38            {
    39                "foreign_key_constraint_id": json.loads(self.foreign_key_constraint_id),
    40                "unique_constraint_id": json.loads(self.unique_constraint_id),
    41            }
    42        )

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.

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

referential_constraint_id
foreign_key_constraint_id
unique_constraint_id
fk_name
pk_name
match_option
update_rule
delete_rule
comment
created
last_altered
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(ReferentialConstraint).filter_by(
    32            foreign_key_constraint_id=self.foreign_key_constraint_id,
    33            unique_constraint_id=self.unique_constraint_id,
    34        )