-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ticket 37 - move init.sql from sbl-project repo to user-fi-management #43
Changes from 6 commits
773cbb0
00dfe44
f2903db
c56f813
7baf240
82b91ac
c6b2045
f034fd4
bafe7b7
1e09290
90ff315
ddee750
b6925c8
f86ae50
3884e1e
c145f8b
02f731f
256ade4
30cac53
7d49ae4
1a6bda4
85639a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
"""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"}, | ||
], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lchen-2101 do you still want to keep these test data? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This data was part of init.sql in sbl-project. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's remove the test data. |
||
) | ||
|
||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you check if drop_table instruction includes drop_index ? |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this file created? we already have all the models. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did we create a new models file when we already have all the models?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I didn't see the existing models, will modify it.