schema_sentinel.metadata_manager.model.constraint API documentation

# schema_sentinel.metadata_manager.model.constraint

View Source

     1import json
     2
     3import sqlalchemy as db
     4from sqlalchemy import ForeignKey, select
     5
     6from . import CommonBase
     7
     8
     9class Constraint(CommonBase):
    10    __tablename__ = "constraints"
    11    constraint_id = db.Column(db.String, primary_key=True)
    12    table_id = db.Column(db.String, ForeignKey("tables.table_id"))
    13    constraint_name = db.Column(db.String)
    14    constraint_type = db.Column(db.String)
    15    constraint_details = db.Column(db.String)
    16    reference_key = db.Column(db.String, ForeignKey("constraints.constraint_id"))
    17    comment = db.Column(db.String)
    18    update_rule = db.Column(db.String, default="NO ACTION")
    19    delete_rule = db.Column(db.String, default="NO ACTION")
    20    created = db.Column(db.String)
    21
    22    def save(self, session) -> None:
    23        if not session.execute(self.exists()).first():
    24            session.add(self)
    25            session.commit()
    26
    27    def exists(self) -> str:
    28        return select(Constraint).filter_by(constraint_id=self.constraint_id)
    29
    30    def __get_id__(self) -> str:
    31        id = json.loads(self.table_id)
    32        id["constraint_name"] = self.constraint_name
    33        return json.dumps(id)

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

    10class Constraint(CommonBase):
    11    __tablename__ = "constraints"
    12    constraint_id = db.Column(db.String, primary_key=True)
    13    table_id = db.Column(db.String, ForeignKey("tables.table_id"))
    14    constraint_name = db.Column(db.String)
    15    constraint_type = db.Column(db.String)
    16    constraint_details = db.Column(db.String)
    17    reference_key = db.Column(db.String, ForeignKey("constraints.constraint_id"))
    18    comment = db.Column(db.String)
    19    update_rule = db.Column(db.String, default="NO ACTION")
    20    delete_rule = db.Column(db.String, default="NO ACTION")
    21    created = db.Column(db.String)
    22
    23    def save(self, session) -> None:
    24        if not session.execute(self.exists()).first():
    25            session.add(self)
    26            session.commit()
    27
    28    def exists(self) -> str:
    29        return select(Constraint).filter_by(constraint_id=self.constraint_id)
    30
    31    def __get_id__(self) -> str:
    32        id = json.loads(self.table_id)
    33        id["constraint_name"] = self.constraint_name
    34        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.

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

constraint_id
table_id
constraint_name
constraint_type
constraint_details
reference_key
comment
update_rule
delete_rule
created
def save(self, session) -> None: View Source

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

def exists(self) -> str: View Source

    28    def exists(self) -> str:
    29        return select(Constraint).filter_by(constraint_id=self.constraint_id)