Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -0,0 +1,108 @@
"""improve foreign key dependencies

Revision ID: 3a3eef5d1886
Revises: 9f381dcb9b95
Create Date: 2024-09-24 07:04:20.424705+00:00

"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "3a3eef5d1886"
down_revision = "9f381dcb9b95"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_foreign_key(
None,
"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(
None, "resource_tracker_pricing_plan_to_service", type_="foreignkey"
)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@
doc="Option to mark default pricing plan for the service (ex. when there are more pricing plans for the same service)",
),
# ---------------------------
sa.ForeignKeyConstraint(
["service_key", "service_version"],
["services_meta_data.key", "services_meta_data.version"],
onupdate="CASCADE",
ondelete="CASCADE",
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ class PricingPlanClassification(str, enum.Enum):
sa.Column(
"product_name",
sa.String,
sa.ForeignKey(
"products.name",
onupdate="CASCADE",
ondelete="CASCADE",
name="fk_rut_pricing_plans_product_name",
),
nullable=False,
doc="Product name",
index=True,
doc="Products unique name",
),
sa.Column(
"display_name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@
sa.Column(
"pricing_plan_id",
sa.BigInteger,
sa.ForeignKey(
"resource_tracker_pricing_plans.pricing_plan_id",
name="fk_resource_tracker_pricing_units_costs_pricing_plan_id",
onupdate="CASCADE",
ondelete="CASCADE",
),
nullable=False,
doc="Parent pricing plan",
doc="Foreign key to pricing plan",
index=True,
),
sa.Column(
Expand All @@ -35,8 +41,14 @@
sa.Column(
"pricing_unit_id",
sa.BigInteger,
sa.ForeignKey(
"resource_tracker_pricing_units.pricing_unit_id",
name="fk_resource_tracker_pricing_units_costs_pricing_unit_id",
onupdate="CASCADE",
ondelete="CASCADE",
),
nullable=False,
doc="Parent pricing unit",
doc="Foreign key to pricing unit",
index=True,
),
sa.Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ class WalletStatus(str, enum.Enum):
),
column_created_datetime(timezone=True),
column_modified_datetime(timezone=True),
sa.Column("product_name", sa.String, nullable=False, doc="Product name"),
sa.Column(
"product_name",
sa.String,
sa.ForeignKey(
"products.name",
onupdate="CASCADE",
ondelete="CASCADE",
name="fk_wallets_product_name",
),
nullable=False,
doc="Products unique name",
),
)

# ------------------------ TRIGGERS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@
nullable=False,
doc="Identifier of the group that owns this workspace (Should be just PRIMARY GROUP)",
),
sa.Column("product_name", sa.String, nullable=False, doc="Product name"),
sa.Column(
"product_name",
sa.String,
sa.ForeignKey(
"products.name",
onupdate="CASCADE",
ondelete="CASCADE",
name="fk_workspaces_product_name",
),
nullable=False,
doc="Products unique name",
),
column_created_datetime(timezone=True),
column_modified_datetime(timezone=True),
)
Expand Down
Loading