From 2710e6d07d860e605f90181e598a53c6c3400436 Mon Sep 17 00:00:00 2001 From: Yian Shang Date: Mon, 18 Sep 2023 06:51:26 -0700 Subject: [PATCH] Separate measures db migration from initial migration --- ..._07_2006-4e1ff36c27c6_initial_migration.py | 24 -------- ...23_09_18_1346-f2e9ef937daf_add_measures.py | 58 +++++++++++++++++++ 2 files changed, 58 insertions(+), 24 deletions(-) create mode 100644 datajunction-server/alembic/versions/2023_09_18_1346-f2e9ef937daf_add_measures.py diff --git a/datajunction-server/alembic/versions/2023_07_07_2006-4e1ff36c27c6_initial_migration.py b/datajunction-server/alembic/versions/2023_07_07_2006-4e1ff36c27c6_initial_migration.py index 9a33c8473..adc41b042 100644 --- a/datajunction-server/alembic/versions/2023_07_07_2006-4e1ff36c27c6_initial_migration.py +++ b/datajunction-server/alembic/versions/2023_07_07_2006-4e1ff36c27c6_initial_migration.py @@ -176,23 +176,6 @@ def upgrade(): name=op.f("pk_catalogengines"), ), ) - op.create_table( - "measures", - sa.Column( - "additive", - sa.Enum( - "ADDITIVE", - "NON_ADDITIVE", - "SEMI_ADDITIVE", - name="aggregationrule", - ), - nullable=True, - ), - sa.Column("id", sa.Integer(), nullable=False), - sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), - sa.PrimaryKeyConstraint("id", name=op.f("pk_measures")), - sa.UniqueConstraint("name", name=op.f("uq_measures_name")), - ) op.create_table( "column", sa.Column("type", sa.String(), nullable=False), @@ -209,12 +192,6 @@ def upgrade(): ["node.id"], name=op.f("fk_column_dimension_id_node"), ), - sa.Column("measure_id", sa.Integer(), nullable=True), - sa.ForeignKeyConstraint( - ["measure_id"], - ["measures.id"], - name=op.f("fk_column_measure_id_measures"), - ), sa.PrimaryKeyConstraint("id", name=op.f("pk_column")), ) op.create_table( @@ -473,4 +450,3 @@ def downgrade(): op.drop_table("catalog") op.drop_table("availabilitystate") op.drop_table("attributetype") - op.drop_table("measures") diff --git a/datajunction-server/alembic/versions/2023_09_18_1346-f2e9ef937daf_add_measures.py b/datajunction-server/alembic/versions/2023_09_18_1346-f2e9ef937daf_add_measures.py new file mode 100644 index 000000000..6b9b79b72 --- /dev/null +++ b/datajunction-server/alembic/versions/2023_09_18_1346-f2e9ef937daf_add_measures.py @@ -0,0 +1,58 @@ +"""Add measures + +Revision ID: f2e9ef937daf +Revises: fe8d3dbe512a +Create Date: 2023-09-18 13:46:17.700118+00:00 + +""" +# pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import, no-name-in-module + +import sqlalchemy as sa +import sqlmodel + +from alembic import op + +# revision identifiers, used by Alembic. +revision = "f2e9ef937daf" +down_revision = "fe8d3dbe512a" +branch_labels = None +depends_on = None + + +def upgrade(): + op.create_table( + "measures", + sa.Column( + "additive", + sa.Enum( + "ADDITIVE", + "NON_ADDITIVE", + "SEMI_ADDITIVE", + name="aggregationrule", + ), + nullable=True, + ), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.PrimaryKeyConstraint("id", name=op.f("pk_measures")), + sa.UniqueConstraint("name", name=op.f("uq_measures_name")), + ) + with op.batch_alter_table("column", schema=None) as batch_op: + batch_op.add_column(sa.Column("measure_id", sa.Integer(), nullable=True)) + batch_op.create_foreign_key( + batch_op.f("fk_column_measure_id_measures"), + "measures", + ["measure_id"], + ["id"], + ) + + +def downgrade(): + with op.batch_alter_table("column", schema=None) as batch_op: + batch_op.drop_constraint( + batch_op.f("fk_column_measure_id_measures"), + type_="foreignkey", + ) + batch_op.drop_column("measure_id") + + op.drop_table("measures")