Skip to content

Commit

Permalink
Merge pull request #774 from shangyian/measures-db-migration
Browse files Browse the repository at this point in the history
Separate measures db migration from initial migration
  • Loading branch information
shangyian authored Sep 18, 2023
2 parents c89ed1c + 2710e6d commit 78d6de3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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(
Expand Down Expand Up @@ -473,4 +450,3 @@ def downgrade():
op.drop_table("catalog")
op.drop_table("availabilitystate")
op.drop_table("attributetype")
op.drop_table("measures")
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 78d6de3

Please sign in to comment.