Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,45 @@
Create Date: 2025-03-11 16:26:52.406726

"""
from alembic import op

from alembic import op
from sqlalchemy.engine.reflection import Inspector

# revision identifiers, used by Alembic.
revision = '37406cca756c'
down_revision = 'da444de005a6'
revision = "37406cca756c"
down_revision = "da444de005a6"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('case_cost_case_cost_type_id_fkey', 'case_cost', type_='foreignkey')
op.create_foreign_key(None, 'case_cost', 'case_cost_type', ['case_cost_type_id'], ['id'], ondelete='CASCADE')
# Get the connection and inspector
conn = op.get_bind()
inspector = Inspector.from_engine(conn)

# Check if the constraint exists
constraints = inspector.get_foreign_keys("case_cost")
constraint_names = [constraint["name"] for constraint in constraints]

# Drop the constraint if it exists
if "case_cost_case_cost_type_id_fkey" in constraint_names:
op.drop_constraint("case_cost_case_cost_type_id_fkey", "case_cost", type_="foreignkey")

# Create the new foreign key constraint
op.create_foreign_key(
None, "case_cost", "case_cost_type", ["case_cost_type_id"], ["id"], ondelete="CASCADE"
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'case_cost', type_='foreignkey')
op.create_foreign_key('case_cost_case_cost_type_id_fkey', 'case_cost', 'case_cost_type', ['case_cost_type_id'], ['id'])
op.drop_constraint(None, "case_cost", type_="foreignkey")
op.create_foreign_key(
"case_cost_case_cost_type_id_fkey",
"case_cost",
"case_cost_type",
["case_cost_type_id"],
["id"],
)
# ### end Alembic commands ###
Loading