Skip to content
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

Features/192 fix alembic filingtype already exists #194

Merged
merged 4 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion db_revisions/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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),
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql


# revision identifiers, used by Alembic.
Expand All @@ -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),
Expand All @@ -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"),
Expand Down Expand Up @@ -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)
23 changes: 16 additions & 7 deletions db_revisions/versions/4659352bd865_create_filing_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,40 @@
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"
down_revision: Union[str, None] = "5a775dd75356"
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),
sa.Column("filing_period", sa.String, nullable=False),
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),
Expand All @@ -43,3 +50,5 @@ def upgrade() -> None:

def downgrade() -> None:
op.drop_table("filing")

state.drop(op.get_bind(), checkfirst=False)
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,38 @@
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"
down_revision: Union[str, None] = None
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),
sa.Column("description", sa.String, nullable=False),
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)
29 changes: 17 additions & 12 deletions db_revisions/versions/f30c5c3c7a42_create_submission_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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),
Expand All @@ -46,3 +50,4 @@ def upgrade() -> None:

def downgrade() -> None:
op.drop_table("submission")
state.drop(op.get_bind(), checkfirst=False)
3 changes: 2 additions & 1 deletion src/sbl_filing_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading