diff --git a/db_revisions/env.py b/db_revisions/env.py index e441084..ca3bdf0 100644 --- a/db_revisions/env.py +++ b/db_revisions/env.py @@ -4,7 +4,8 @@ from sqlalchemy import engine_from_config from sqlalchemy import pool from alembic import context -from src.models import Base + +from src.entities.models import Base # this is the Alembic Config object, which provides # access to the values within the .ini file in use. diff --git a/db_revisions/versions/ed7dcc6128bc_create_a_baseline_migrations.py b/db_revisions/versions/ed7dcc6128bc_create_a_baseline_migrations.py deleted file mode 100644 index c05c2c4..0000000 --- a/db_revisions/versions/ed7dcc6128bc_create_a_baseline_migrations.py +++ /dev/null @@ -1,79 +0,0 @@ -"""Create a baseline migrations - -Revision ID: ed7dcc6128bc -Revises: -Create Date: 2023-10-18 11:13:57.509078 - -""" -from typing import Sequence, Union - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision: str = "ed7dcc6128bc" -down_revision: Union[str, None] = None -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -def upgrade() -> None: - denied_domains = op.create_table( - "denied_domains", - sa.Column("domain", sa.String(), nullable=False), - sa.Column("event_time", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True), - sa.PrimaryKeyConstraint("domain", name="denied_domains_pkey"), - ) - op.create_index("ix_denied_domains_domain", "denied_domains", ["domain"], unique=True) - op.bulk_insert(denied_domains, [{"domain": "gmail.com"}, {"domain": "yahoo.com"}, {"domain": "aol.com"}]) - - financial_institutions = op.create_table( - "financial_institutions", - sa.Column("lei", sa.String(), nullable=False), - sa.Column("name", sa.String(), nullable=False), - sa.Column("event_time", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True), - sa.PrimaryKeyConstraint("lei", name="financial_institutions_pkey"), - ) - op.create_index("ix_financial_institutions_lei", "financial_institutions", ["lei"], unique=True) - op.create_index("ix_financial_institutions_name", "financial_institutions", ["name"], unique=False) - op.bulk_insert( - financial_institutions, - [ - {"lei": "TEST1LEI", "name": "Test 1"}, - {"lei": "TEST2LEI", "name": "Test 2"}, - {"lei": "TEST3LEI", "name": "Test 3"}, - ], - ) - - financial_institutions_domains = op.create_table( - "financial_institutions_domains", - sa.Column("domain", sa.String(), nullable=False), - sa.Column("lei", sa.String(), nullable=False), - sa.Column("event_time", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True), - sa.ForeignKeyConstraint( - ["lei"], - ["financial_institutions.lei"], - ), - sa.PrimaryKeyConstraint("domain", "lei", name="financial_institution_domains_pkey"), - ) - op.create_index( - "ix_financial_institution_domains_domain", "financial_institutions_domains", ["domain"], unique=False - ) - op.create_index("ix_financial_institution_domains_lei", "financial_institutions_domains", ["lei"], unique=False) - op.bulk_insert( - financial_institutions_domains, - [ - {"domain": "test1.local", "lei": "TEST1LEI"}, - {"domain": "test2.local", "lei": "TEST2LEI"}, - {"domain": "test3.local", "lei": "TEST3LEI"}, - ], - ) - - -def downgrade() -> None: - op.drop_table("financial_institutions_domains") - - op.drop_table("financial_institutions") - - op.drop_table("denied_domains") diff --git a/src/entities/models/dto.py b/src/entities/models/dto.py index d78fd6c..82fc5df 100644 --- a/src/entities/models/dto.py +++ b/src/entities/models/dto.py @@ -73,7 +73,7 @@ def from_claim(cls, claims: Dict[str, Any]) -> "AuthenticatedUser": ) @classmethod - def parse_institutions(cls, institutions: List[str] | None) -> List[str]: + def parse_institutions(cls, institutions: Optional[List[str]] = None) -> List[str]: """ Parse out the list of institutions returned by Keycloak diff --git a/src/models.py b/src/models.py deleted file mode 100644 index 0c5a2fb..0000000 --- a/src/models.py +++ /dev/null @@ -1,49 +0,0 @@ -from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy import Column, DateTime, ForeignKey, Index, PrimaryKeyConstraint, String -from sqlalchemy.sql import func - -Base = declarative_base() -metadata = Base.metadata - - -class Financial_Institutions(Base): - __tablename__ = "financial_institutions" - lei = Column(String, nullable=False) - name = Column(String, nullable=False) - event_time = Column(DateTime(timezone=True), server_default=func.now()) - __table_args__ = ( - PrimaryKeyConstraint("lei", name="financial_institutions_pkey"), - Index("ix_financial_institutions_lei", "lei", unique=True), - Index("ix_financial_institutions_name", "name"), - ) - - def __repr__(self): - return f"lei: {self.lei}, name: {self.name}" - - -class Financial_Institutions_Domains(Base): - __tablename__ = "financial_institutions_domains" - domain = Column(String, nullable=False) - lei = Column(String, ForeignKey("financial_institutions.lei")) - event_time = Column(DateTime(timezone=True), server_default=func.now()) - __table_args__ = ( - PrimaryKeyConstraint("domain", "lei", name="financial_institution_domains_pkey"), - Index("ix_financial_institution_domains_domain", "domain"), - Index("ix_financial_institution_domains_lei", "lei"), - ) - - def __repr__(self): - return f"lei: {self.lei}, domain: {self.domain}" - - -class Denied_Domains(Base): - __tablename__ = "denied_domains" - domain = Column(String, nullable=False) - event_time = Column(DateTime(timezone=True), server_default=func.now()) - __table_args__ = ( - PrimaryKeyConstraint("domain", name="denied_domains_pkey"), - Index("ix_denied_domains_domain", "domain", unique=True), - ) - - def __repr__(self): - return f"domain: {self.domain}"