From c296b0da2ebaad1edbe7405c4d32d6db5cc12a67 Mon Sep 17 00:00:00 2001 From: matusdrobuliak66 Date: Tue, 3 Dec 2024 16:32:11 +0100 Subject: [PATCH] upgrade postgres package - shortuuid --- ... => 707fe8c2e7f5_add_license_db_tables.py} | 19 ++++++++++------- .../resource_tracker_license_checkouts.py | 21 ++++++++++++------- 2 files changed, 24 insertions(+), 16 deletions(-) rename packages/postgres-database/src/simcore_postgres_database/migration/versions/{dd0d2a5a993b_add_license_db_tables.py => 707fe8c2e7f5_add_license_db_tables.py} (89%) diff --git a/packages/postgres-database/src/simcore_postgres_database/migration/versions/dd0d2a5a993b_add_license_db_tables.py b/packages/postgres-database/src/simcore_postgres_database/migration/versions/707fe8c2e7f5_add_license_db_tables.py similarity index 89% rename from packages/postgres-database/src/simcore_postgres_database/migration/versions/dd0d2a5a993b_add_license_db_tables.py rename to packages/postgres-database/src/simcore_postgres_database/migration/versions/707fe8c2e7f5_add_license_db_tables.py index 3fd4e33d53e..d2df7d12ab9 100644 --- a/packages/postgres-database/src/simcore_postgres_database/migration/versions/dd0d2a5a993b_add_license_db_tables.py +++ b/packages/postgres-database/src/simcore_postgres_database/migration/versions/707fe8c2e7f5_add_license_db_tables.py @@ -1,15 +1,15 @@ """add license db tables -Revision ID: dd0d2a5a993b +Revision ID: 707fe8c2e7f5 Revises: e05bdc5b3c7b -Create Date: 2024-12-03 14:55:22.308786+00:00 +Create Date: 2024-12-03 15:32:02.797511+00:00 """ import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. -revision = "dd0d2a5a993b" +revision = "707fe8c2e7f5" down_revision = "e05bdc5b3c7b" branch_labels = None depends_on = None @@ -52,8 +52,8 @@ def upgrade(): ) op.create_table( "resource_tracker_license_checkouts", - sa.Column("license_checkout_id", sa.BigInteger(), nullable=False), - sa.Column("license_package_id", sa.BigInteger(), nullable=True), + sa.Column("license_checkout_id", sa.String(), nullable=False), + sa.Column("license_package_id", sa.String(), nullable=True), sa.Column("wallet_id", sa.BigInteger(), nullable=False), sa.Column("user_id", sa.BigInteger(), nullable=False), sa.Column("user_email", sa.String(), nullable=True), @@ -69,9 +69,12 @@ def upgrade(): nullable=False, ), sa.ForeignKeyConstraint( - ["service_run_id"], - ["resource_tracker_service_runs.service_run_id"], - name="fk_resource_tracker_license_checkouts_service_run_id", + ["product_name", "service_run_id"], + [ + "resource_tracker_service_runs.product_name", + "resource_tracker_service_runs.service_run_id", + ], + name="resource_tracker_license_checkouts_service_run_id_fkey", onupdate="CASCADE", ondelete="RESTRICT", ), diff --git a/packages/postgres-database/src/simcore_postgres_database/models/resource_tracker_license_checkouts.py b/packages/postgres-database/src/simcore_postgres_database/models/resource_tracker_license_checkouts.py index 3cac6555f51..a97e31494b1 100644 --- a/packages/postgres-database/src/simcore_postgres_database/models/resource_tracker_license_checkouts.py +++ b/packages/postgres-database/src/simcore_postgres_database/models/resource_tracker_license_checkouts.py @@ -17,14 +17,14 @@ def _custom_id_generator(): metadata, sa.Column( "license_checkout_id", - sa.BigInteger, + sa.String, nullable=False, primary_key=True, default=_custom_id_generator, ), sa.Column( "license_package_id", - sa.BigInteger, + sa.String, nullable=True, ), sa.Column( @@ -47,12 +47,6 @@ def _custom_id_generator(): sa.Column( "service_run_id", sa.String, - sa.ForeignKey( - "resource_tracker_service_runs.service_run_id", - name="fk_resource_tracker_license_checkouts_service_run_id", - onupdate=RefActions.CASCADE, - ondelete=RefActions.RESTRICT, - ), nullable=True, ), sa.Column( @@ -73,6 +67,17 @@ def _custom_id_generator(): nullable=False, ), column_modified_datetime(timezone=True), + # --------------------------- + sa.ForeignKeyConstraint( + ["product_name", "service_run_id"], + [ + "resource_tracker_service_runs.product_name", + "resource_tracker_service_runs.service_run_id", + ], + name="resource_tracker_license_checkouts_service_run_id_fkey", + onupdate=RefActions.CASCADE, + ondelete=RefActions.RESTRICT, + ), ) # We define the partial index