Skip to content

Commit

Permalink
🎨 add constrains in resource_tracker_pricing_plan_to_service and `l…
Browse files Browse the repository at this point in the history
…icensed_item_to_resource` DB tables (🗃️) (#7269)
  • Loading branch information
matusdrobuliak66 authored Feb 25, 2025
1 parent e7e0b79 commit 603a27d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""add restriction ondelete
Revision ID: d84edab53761
Revises: 163b11424cb1
Create Date: 2025-02-25 09:18:14.541874+00:00
"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "d84edab53761"
down_revision = "163b11424cb1"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint(
"uq_licensed_item_to_resource_resource_id",
"licensed_item_to_resource",
["licensed_resource_id"],
)
op.drop_constraint(
"fk_rut_pricing_plan_to_service_key_and_version",
"resource_tracker_pricing_plan_to_service",
type_="foreignkey",
)
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="RESTRICT",
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"fk_rut_pricing_plan_to_service_key_and_version",
"resource_tracker_pricing_plan_to_service",
type_="foreignkey",
)
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_constraint(
"uq_licensed_item_to_resource_resource_id",
"licensed_item_to_resource",
type_="unique",
)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@
),
column_created_datetime(timezone=True),
column_modified_datetime(timezone=True),
#########
# NOTE: Currently, there is a constraint that a resource item ID cannot be in multiple licensed items.
# The reason is that the license key and license version coming from the internal license server are part of the licensed resource domain.
# Sim4Life performs a mapping on their side, where the license key and version are mapped to a licensed item.
# If this constraint is broken, the mapping logic in Sim4Life might break.
sa.UniqueConstraint(
"licensed_resource_id",
name="uq_licensed_item_to_resource_resource_id",
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
["services_meta_data.key", "services_meta_data.version"],
name="fk_rut_pricing_plan_to_service_key_and_version",
onupdate=RefActions.CASCADE,
ondelete=RefActions.CASCADE,
ondelete=RefActions.RESTRICT,
),
)

0 comments on commit 603a27d

Please sign in to comment.