-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ticket 37 - move init.sql from sbl-project repo to user-fi-management
- Loading branch information
Nargis Sultani
committed
Oct 17, 2023
1 parent
0c9ef87
commit 773cbb0
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
from dotenv import load_dotenv | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from sqlalchemy.orm import sessionmaker | ||
|
||
ENV = os.getenv("ENV", "LOCAL") | ||
|
||
if ENV == "LOCAL": | ||
load_dotenv("src/.env.local") | ||
else: | ||
load_dotenv() | ||
|
||
DATABASE_URL = os.environ.get("INST_CONN") | ||
|
||
engine = create_engine(DATABASE_URL) | ||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | ||
|
||
Base = declarative_base() | ||
|
||
def init_db(): | ||
Base.metadata.create_all(engine) | ||
|
||
def get_db(): | ||
db = SessionLocal() | ||
try: | ||
yield db | ||
except: | ||
db.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
from sqlalchemy import Column, DateTime, ForeignKeyConstraint, Index, PrimaryKeyConstraint, String | ||
from sqlalchemy.sql import func | ||
from db.database import Base | ||
|
||
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", postgresql_using='gin', unique=True), | ||
Index('ix_financial_institutions_name', "name", postgresql_using='gin'), | ||
{"schema": "fi"} | ||
) | ||
|
||
class Financial_Institutions_Domains(Base): | ||
__tablename__ = 'financial_institutions_domains' | ||
domain = Column(String, nullable=False) | ||
lei = Column(String, nullable=False) | ||
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", postgresql_using='gin'), | ||
Index('ix_financial_institution_domains_lei', "lei", postgresql_using='gin'), | ||
ForeignKeyConstraint(["lei"], ["financial_institutions.lei"]), | ||
{"schema": "fi"} | ||
) | ||
|
||
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", postgresql_using='gin', unique=True), | ||
{"schema": "fi"} | ||
) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: '3' | ||
|
||
services: | ||
pg_user_fi: | ||
image: postgres | ||
ports: | ||
- "5432:5432" | ||
environment: | ||
POSTGRES_USER: fi | ||
POSTGRES_PASSWORD: fi | ||
POSTGRES_DB: financial_institutions | ||
volumes: | ||
- db:/var/lib/postgresql/data | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters