-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0adc62d
commit 55d8fd1
Showing
1 changed file
with
151 additions
and
0 deletions.
There are no files selected for viewing
151 changes: 151 additions & 0 deletions
151
ixmp4/db/migrations/versions/bd37acfe8566_normalize_optimization_table_storage.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,151 @@ | ||
# type: ignore | ||
"""Normalize optimization.table storage | ||
Revision ID: bd37acfe8566 | ||
Revises: d66a8276ba0a | ||
Create Date: 2024-12-17 14:19:27.618301 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import sqlite | ||
|
||
# Revision identifiers, used by Alembic. | ||
revision = "bd37acfe8566" | ||
down_revision = "d66a8276ba0a" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"optimization_tabledata", | ||
sa.Column("table__id", sa.Integer(), nullable=False), | ||
sa.Column("value_0", sa.String(), nullable=False), | ||
sa.Column("value_1", sa.String(), nullable=True), | ||
sa.Column("value_2", sa.String(), nullable=True), | ||
sa.Column("value_3", sa.String(), nullable=True), | ||
sa.Column("value_4", sa.String(), nullable=True), | ||
sa.Column("value_5", sa.String(), nullable=True), | ||
sa.Column("value_6", sa.String(), nullable=True), | ||
sa.Column("value_7", sa.String(), nullable=True), | ||
sa.Column("value_8", sa.String(), nullable=True), | ||
sa.Column("value_9", sa.String(), nullable=True), | ||
sa.Column("value_10", sa.String(), nullable=True), | ||
sa.Column("value_11", sa.String(), nullable=True), | ||
sa.Column("value_12", sa.String(), nullable=True), | ||
sa.Column("value_13", sa.String(), nullable=True), | ||
sa.Column("value_14", sa.String(), nullable=True), | ||
sa.Column( | ||
"id", | ||
sa.Integer(), | ||
sa.Identity(always=False, on_null=True, start=1, increment=1), | ||
nullable=False, | ||
), | ||
sa.ForeignKeyConstraint( | ||
["table__id"], | ||
["optimization_table.id"], | ||
name=op.f("fk_optimization_tabledata_table__id_optimization_table"), | ||
), | ||
sa.PrimaryKeyConstraint("id", name=op.f("pk_optimization_tabledata")), | ||
sa.UniqueConstraint( | ||
"table__id", | ||
"value_0", | ||
"value_1", | ||
"value_2", | ||
"value_3", | ||
"value_4", | ||
"value_5", | ||
"value_6", | ||
"value_7", | ||
"value_8", | ||
"value_9", | ||
"value_10", | ||
"value_11", | ||
"value_12", | ||
"value_13", | ||
"value_14", | ||
name=op.f( | ||
"uq_optimization_tabledata_table__id_value_0_value_1_value_2_value_3_value_4_value_5_value_6_value_7_value_8_value_9_value_10_value_11_value_12_value_13_value_14" | ||
), | ||
), | ||
) | ||
with op.batch_alter_table("optimization_tabledata", schema=None) as batch_op: | ||
batch_op.create_index( | ||
batch_op.f("ix_optimization_tabledata_table__id"), | ||
["table__id"], | ||
unique=False, | ||
) | ||
|
||
op.create_table( | ||
"optimization_tableindexsetassociation", | ||
sa.Column("table_id", sa.Integer(), nullable=False), | ||
sa.Column("indexset_id", sa.Integer(), nullable=False), | ||
sa.Column("column_name", sa.String(length=255), nullable=True), | ||
sa.Column( | ||
"id", | ||
sa.Integer(), | ||
sa.Identity(always=False, on_null=True, start=1, increment=1), | ||
nullable=False, | ||
), | ||
sa.ForeignKeyConstraint( | ||
["indexset_id"], | ||
["optimization_indexset.id"], | ||
name=op.f( | ||
"fk_optimization_tableindexsetassociation_indexset_id_optimization_indexset" | ||
), | ||
), | ||
sa.ForeignKeyConstraint( | ||
["table_id"], | ||
["optimization_table.id"], | ||
name=op.f( | ||
"fk_optimization_tableindexsetassociation_table_id_optimization_table" | ||
), | ||
), | ||
sa.PrimaryKeyConstraint( | ||
"id", name=op.f("pk_optimization_tableindexsetassociation") | ||
), | ||
) | ||
with op.batch_alter_table( | ||
"optimization_tableindexsetassociation", schema=None | ||
) as batch_op: | ||
batch_op.create_index( | ||
batch_op.f("ix_optimization_tableindexsetassociation_indexset_id"), | ||
["indexset_id"], | ||
unique=False, | ||
) | ||
batch_op.create_index( | ||
batch_op.f("ix_optimization_tableindexsetassociation_table_id"), | ||
["table_id"], | ||
unique=False, | ||
) | ||
|
||
with op.batch_alter_table("optimization_table", schema=None) as batch_op: | ||
batch_op.drop_column("data") | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("optimization_table", schema=None) as batch_op: | ||
batch_op.add_column(sa.Column("data", sqlite.JSON(), nullable=False)) | ||
|
||
with op.batch_alter_table( | ||
"optimization_tableindexsetassociation", schema=None | ||
) as batch_op: | ||
batch_op.drop_index( | ||
batch_op.f("ix_optimization_tableindexsetassociation_table_id") | ||
) | ||
batch_op.drop_index( | ||
batch_op.f("ix_optimization_tableindexsetassociation_indexset_id") | ||
) | ||
|
||
op.drop_table("optimization_tableindexsetassociation") | ||
with op.batch_alter_table("optimization_tabledata", schema=None) as batch_op: | ||
batch_op.drop_index(batch_op.f("ix_optimization_tabledata_table__id")) | ||
|
||
op.drop_table("optimization_tabledata") | ||
# ### end Alembic commands ### |