-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 improve DB foreign key dependencies (🗃️) (#6428)
- Loading branch information
1 parent
65ffdd9
commit 1a4dcea
Showing
11 changed files
with
274 additions
and
33 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
...ore_postgres_database/migration/versions/10729e07000d_improve_foreign_key_dependencies.py
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,110 @@ | ||
"""improve foreign key dependencies | ||
Revision ID: 10729e07000d | ||
Revises: 47ca7335e146 | ||
Create Date: 2024-09-24 07:52:20.253076+00:00 | ||
""" | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "10729e07000d" | ||
down_revision = "47ca7335e146" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_foreign_key( | ||
"fk_rut_pricing_plan_to_service_key_and_version", | ||
"resource_tracker_pricing_plan_to_service", | ||
"services_meta_data", | ||
["service_key", "service_version"], | ||
["key", "version"], | ||
onupdate="CASCADE", | ||
ondelete="CASCADE", | ||
) | ||
op.drop_index( | ||
"ix_resource_tracker_pricing_plans_product_name", | ||
table_name="resource_tracker_pricing_plans", | ||
) | ||
op.create_foreign_key( | ||
"fk_rut_pricing_plans_product_name", | ||
"resource_tracker_pricing_plans", | ||
"products", | ||
["product_name"], | ||
["name"], | ||
onupdate="CASCADE", | ||
ondelete="CASCADE", | ||
) | ||
op.create_foreign_key( | ||
"fk_resource_tracker_pricing_units_costs_pricing_plan_id", | ||
"resource_tracker_pricing_unit_costs", | ||
"resource_tracker_pricing_plans", | ||
["pricing_plan_id"], | ||
["pricing_plan_id"], | ||
onupdate="CASCADE", | ||
ondelete="CASCADE", | ||
) | ||
op.create_foreign_key( | ||
"fk_resource_tracker_pricing_units_costs_pricing_unit_id", | ||
"resource_tracker_pricing_unit_costs", | ||
"resource_tracker_pricing_units", | ||
["pricing_unit_id"], | ||
["pricing_unit_id"], | ||
onupdate="CASCADE", | ||
ondelete="CASCADE", | ||
) | ||
op.create_foreign_key( | ||
"fk_wallets_product_name", | ||
"wallets", | ||
"products", | ||
["product_name"], | ||
["name"], | ||
onupdate="CASCADE", | ||
ondelete="CASCADE", | ||
) | ||
op.create_foreign_key( | ||
"fk_workspaces_product_name", | ||
"workspaces", | ||
"products", | ||
["product_name"], | ||
["name"], | ||
onupdate="CASCADE", | ||
ondelete="CASCADE", | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_constraint("fk_workspaces_product_name", "workspaces", type_="foreignkey") | ||
op.drop_constraint("fk_wallets_product_name", "wallets", type_="foreignkey") | ||
op.drop_constraint( | ||
"fk_resource_tracker_pricing_units_costs_pricing_unit_id", | ||
"resource_tracker_pricing_unit_costs", | ||
type_="foreignkey", | ||
) | ||
op.drop_constraint( | ||
"fk_resource_tracker_pricing_units_costs_pricing_plan_id", | ||
"resource_tracker_pricing_unit_costs", | ||
type_="foreignkey", | ||
) | ||
op.drop_constraint( | ||
"fk_rut_pricing_plans_product_name", | ||
"resource_tracker_pricing_plans", | ||
type_="foreignkey", | ||
) | ||
op.create_index( | ||
"ix_resource_tracker_pricing_plans_product_name", | ||
"resource_tracker_pricing_plans", | ||
["product_name"], | ||
unique=False, | ||
) | ||
op.drop_constraint( | ||
"fk_rut_pricing_plan_to_service_key_and_version", | ||
"resource_tracker_pricing_plan_to_service", | ||
type_="foreignkey", | ||
) | ||
# ### end Alembic commands ### |
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
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
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
Oops, something went wrong.