From bbce0d0b2c938c4e0c42116c82ca382fe4adb692 Mon Sep 17 00:00:00 2001 From: Nargis Sultani Date: Wed, 1 May 2024 10:43:33 -0400 Subject: [PATCH 1/4] Ticket 188 - fixed local dev .env file loading, also updated DB_SCHEMA in .env.local --- db_revisions/env.py | 2 +- src/.env.local | 2 +- src/sbl_filing_api/config.py | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/db_revisions/env.py b/db_revisions/env.py index 2dbd0676..a76ced67 100644 --- a/db_revisions/env.py +++ b/db_revisions/env.py @@ -26,7 +26,7 @@ if ENV == "LOCAL": file_dir = os.path.dirname(os.path.realpath(__file__)) - load_dotenv(f"{file_dir}/../src/sbl_filing_api/.env.local") + load_dotenv(f"{file_dir}/../src/.env.local") else: load_dotenv() diff --git a/src/.env.local b/src/.env.local index 9183b562..b075d3fc 100644 --- a/src/.env.local +++ b/src/.env.local @@ -2,7 +2,7 @@ DB_NAME=filing DB_USER=filing_user DB_PWD=filing_user DB_HOST=localhost:5432 -DB_SCHEMA=filing +DB_SCHEMA=public KC_URL=http://localhost:8880 KC_REALM=regtech KC_ADMIN_CLIENT_ID=admin-cli diff --git a/src/sbl_filing_api/config.py b/src/sbl_filing_api/config.py index bf5b4d5c..83c90a60 100644 --- a/src/sbl_filing_api/config.py +++ b/src/sbl_filing_api/config.py @@ -12,7 +12,8 @@ env_files_to_load = [".env"] if os.getenv("ENV", "LOCAL") == "LOCAL": - env_files_to_load.append(".env.local") + file_dir = os.path.dirname(os.path.realpath(__file__)) + env_files_to_load.append(f"{file_dir}/../.env.local") class FsProtocol(StrEnum): From c5032dde6aaeb3f8ec880510378c3cb36c648202 Mon Sep 17 00:00:00 2001 From: Nargis Sultani Date: Thu, 2 May 2024 10:51:59 -0400 Subject: [PATCH 2/4] changed DB_SCHEMA back to filing from public --- src/.env.local | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/.env.local b/src/.env.local index b075d3fc..9183b562 100644 --- a/src/.env.local +++ b/src/.env.local @@ -2,7 +2,7 @@ DB_NAME=filing DB_USER=filing_user DB_PWD=filing_user DB_HOST=localhost:5432 -DB_SCHEMA=public +DB_SCHEMA=filing KC_URL=http://localhost:8880 KC_REALM=regtech KC_ADMIN_CLIENT_ID=admin-cli From 201ab0266548bccbb45d270164170665e39e6da3 Mon Sep 17 00:00:00 2001 From: Nargis Sultani Date: Thu, 2 May 2024 14:13:36 -0400 Subject: [PATCH 3/4] Ticket 192 - fixed alembic upgrade and downgrade issues caused by enums --- ...e5_update_filing_table_for_filing_tasks.py | 23 ++++++++------- ...rop_signature_submitter_accepter_tables.py | 19 ++++++++---- .../4659352bd865_create_filing_table.py | 23 ++++++++++----- ...5a775dd75356_create_filing_period_table.py | 11 ++++++- .../f30c5c3c7a42_create_submission_table.py | 29 +++++++++++-------- 5 files changed, 69 insertions(+), 36 deletions(-) diff --git a/db_revisions/versions/078cbbc69fe5_update_filing_table_for_filing_tasks.py b/db_revisions/versions/078cbbc69fe5_update_filing_table_for_filing_tasks.py index fd6df75c..9fe3fdd6 100644 --- a/db_revisions/versions/078cbbc69fe5_update_filing_table_for_filing_tasks.py +++ b/db_revisions/versions/078cbbc69fe5_update_filing_table_for_filing_tasks.py @@ -5,10 +5,12 @@ Create Date: 2024-01-30 13:15:44.323900 """ + from typing import Sequence, Union from alembic import op, context import sqlalchemy as sa +from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. @@ -25,16 +27,17 @@ def upgrade() -> None: def downgrade() -> None: + state = postgresql.ENUM( + "FILING_STARTED", + "FILING_INSTITUTION_APPROVED", + "FILING_IN_PROGRESS", + "FILING_COMPLETE", + name="filingstate", + create_type=False, + ) + state.create(op.get_bind(), checkfirst=True) + op.add_column( "filing", - sa.Column( - "state", - sa.Enum( - "FILING_STARTED", - "FILING_INSTITUTION_APPROVED", - "FILING_IN_PROGRESS", - "FILING_COMPLETE", - name="filingstate", - ), - ), + sa.Column("state", state), ) diff --git a/db_revisions/versions/102fb94a24cc_create_user_action_and_drop_signature_submitter_accepter_tables.py b/db_revisions/versions/102fb94a24cc_create_user_action_and_drop_signature_submitter_accepter_tables.py index acdf79ee..91f1664a 100644 --- a/db_revisions/versions/102fb94a24cc_create_user_action_and_drop_signature_submitter_accepter_tables.py +++ b/db_revisions/versions/102fb94a24cc_create_user_action_and_drop_signature_submitter_accepter_tables.py @@ -10,6 +10,7 @@ from alembic import op import sqlalchemy as sa +from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. @@ -18,8 +19,18 @@ branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None +action_type = postgresql.ENUM( + "SUBMIT", + "ACCEPT", + "SIGN", + name="useractiontype", + create_type=False, +) + def upgrade() -> None: + action_type.create(op.get_bind(), checkfirst=True) + op.create_table( "user_action", sa.Column("id", sa.INTEGER, autoincrement=True), @@ -28,12 +39,7 @@ def upgrade() -> None: sa.Column("user_email", sa.String, nullable=False), sa.Column( "action_type", - sa.Enum( - "SUBMIT", - "ACCEPT", - "SIGN", - name="useractiontype", - ), + action_type, ), sa.Column("timestamp", sa.DateTime(), server_default=sa.func.now(), nullable=False), sa.PrimaryKeyConstraint("id", name="user_action_pkey"), @@ -102,3 +108,4 @@ def downgrade() -> None: op.drop_table("filing_signature") op.drop_table("user_action") + action_type.drop(op.get_bind(), checkfirst=False) diff --git a/db_revisions/versions/4659352bd865_create_filing_table.py b/db_revisions/versions/4659352bd865_create_filing_table.py index 2def6057..d5252953 100644 --- a/db_revisions/versions/4659352bd865_create_filing_table.py +++ b/db_revisions/versions/4659352bd865_create_filing_table.py @@ -5,10 +5,12 @@ Create Date: 2024-01-08 14:42:44.052389 """ + from typing import Sequence, Union from alembic import op import sqlalchemy as sa +from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision: str = "4659352bd865" @@ -16,8 +18,19 @@ branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None +state = postgresql.ENUM( + "FILING_STARTED", + "FILING_INSTITUTION_APPROVED", + "FILING_IN_PROGRESS", + "FILING_COMPLETE", + name="filingstate", + create_type=False, +) + def upgrade() -> None: + state.create(op.get_bind(), checkfirst=True) + op.create_table( "filing", sa.Column("id", sa.INTEGER, autoincrement=True), @@ -25,13 +38,7 @@ def upgrade() -> None: sa.Column("lei", sa.String, nullable=False), sa.Column( "state", - sa.Enum( - "FILING_STARTED", - "FILING_INSTITUTION_APPROVED", - "FILING_IN_PROGRESS", - "FILING_COMPLETE", - name="filingstate", - ), + state, ), sa.Column("institution_snapshot_id", sa.String, nullable=False), sa.Column("contact_info", sa.String), @@ -43,3 +50,5 @@ def upgrade() -> None: def downgrade() -> None: op.drop_table("filing") + + state.drop(op.get_bind(), checkfirst=False) diff --git a/db_revisions/versions/5a775dd75356_create_filing_period_table.py b/db_revisions/versions/5a775dd75356_create_filing_period_table.py index cdbd996a..f7205297 100644 --- a/db_revisions/versions/5a775dd75356_create_filing_period_table.py +++ b/db_revisions/versions/5a775dd75356_create_filing_period_table.py @@ -5,10 +5,12 @@ Create Date: 2024-01-08 13:49:42.475381 """ + from typing import Sequence, Union from alembic import op import sqlalchemy as sa +from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision: str = "5a775dd75356" @@ -16,8 +18,13 @@ branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None +filing_type = postgresql.ENUM("ANNUAL", name="filingtype", create_type=False) + def upgrade() -> None: + + filing_type.create(op.get_bind(), checkfirst=True) + op.create_table( "filing_period", sa.Column("code", sa.String, nullable=False), @@ -25,10 +32,12 @@ def upgrade() -> None: sa.Column("start_period", sa.DateTime, nullable=False), sa.Column("end_period", sa.DateTime, nullable=False), sa.Column("due", sa.DateTime, nullable=False), - sa.Column("filing_type", sa.Enum("ANNUAL", name="filingtype"), server_default="ANNUAL"), + sa.Column("filing_type", filing_type, server_default="ANNUAL"), sa.PrimaryKeyConstraint("code", name="filing_period_pkey"), ) def downgrade() -> None: op.drop_table("filing_period") + + filing_type.drop(op.get_bind(), checkfirst=False) diff --git a/db_revisions/versions/f30c5c3c7a42_create_submission_table.py b/db_revisions/versions/f30c5c3c7a42_create_submission_table.py index f0f40031..f9eb8fb6 100644 --- a/db_revisions/versions/f30c5c3c7a42_create_submission_table.py +++ b/db_revisions/versions/f30c5c3c7a42_create_submission_table.py @@ -5,10 +5,12 @@ Create Date: 2023-12-12 12:40:14.501180 """ + from typing import Sequence, Union from alembic import op import sqlalchemy as sa +from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. @@ -17,24 +19,26 @@ branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None +state = postgresql.ENUM( + "SUBMISSION_UPLOADED", + "VALIDATION_IN_PROGRESS", + "VALIDATION_WITH_ERRORS", + "VALIDATION_WITH_WARNINGS", + "VALIDATION_SUCCESSFUL", + "SUBMISSION_SIGNED", + name="submissionstate", + create_type=False, +) + def upgrade() -> None: + state.create(op.get_bind(), checkfirst=True) + op.create_table( "submission", sa.Column("id", sa.INTEGER, autoincrement=True), sa.Column("submitter", sa.String, nullable=False), - sa.Column( - "state", - sa.Enum( - "SUBMISSION_UPLOADED", - "VALIDATION_IN_PROGRESS", - "VALIDATION_WITH_ERRORS", - "VALIDATION_WITH_WARNINGS", - "VALIDATION_SUCCESSFUL", - "SUBMISSION_SIGNED", - name="submissionstate", - ), - ), + sa.Column("state", state), sa.Column("validation_ruleset_version", sa.String), sa.Column("validation_json", sa.JSON), sa.Column("filing", sa.Integer), @@ -46,3 +50,4 @@ def upgrade() -> None: def downgrade() -> None: op.drop_table("submission") + state.drop(op.get_bind(), checkfirst=False) From ed2567cd085d9ad982d5babe0595024ecefd37a6 Mon Sep 17 00:00:00 2001 From: Nargis Sultani Date: Thu, 2 May 2024 14:19:30 -0400 Subject: [PATCH 4/4] black reformat --- db_revisions/versions/5a775dd75356_create_filing_period_table.py | 1 - 1 file changed, 1 deletion(-) diff --git a/db_revisions/versions/5a775dd75356_create_filing_period_table.py b/db_revisions/versions/5a775dd75356_create_filing_period_table.py index f7205297..5f421991 100644 --- a/db_revisions/versions/5a775dd75356_create_filing_period_table.py +++ b/db_revisions/versions/5a775dd75356_create_filing_period_table.py @@ -22,7 +22,6 @@ def upgrade() -> None: - filing_type.create(op.get_bind(), checkfirst=True) op.create_table(