-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #774 from shangyian/measures-db-migration
Separate measures db migration from initial migration
- Loading branch information
Showing
2 changed files
with
58 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
datajunction-server/alembic/versions/2023_09_18_1346-f2e9ef937daf_add_measures.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |