Skip to content

Commit

Permalink
Make scalar.unit non-optional
Browse files Browse the repository at this point in the history
  • Loading branch information
glatterf42 committed Nov 29, 2024
1 parent 2f647c5 commit c18ed42
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ixmp4/data/db/optimization/indexset/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class IndexSet(base.BaseModel):
_data_type: types.OptimizationDataType

_data: types.Mapped[list["IndexSetData"]] = db.relationship(
back_populates="indexset"
back_populates="indexset", order_by="IndexSetData.id"
)

@property
Expand Down
4 changes: 2 additions & 2 deletions ixmp4/data/db/optimization/scalar/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Scalar(base.BaseModel):

value: types.Float = db.Column(db.Float, nullable=True, unique=False)

unit: types.Mapped[Unit | None] = db.relationship()
unit__id: types.Mapped[int | None] = db.Column(
unit: types.Mapped[Unit] = db.relationship()
unit__id: types.Mapped[int] = db.Column(
db.Integer, db.ForeignKey("unit.id"), index=True
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# type: ignore
"""Make Scalar.unit non-optional
Revision ID: d66a8276ba0a
Revises: 914991d09f59
Create Date: 2024-11-29 14:14:42.857695
"""

import sqlalchemy as sa
from alembic import op

# Revision identifiers, used by Alembic.
revision = "d66a8276ba0a"
down_revision = "914991d09f59"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("optimization_scalar", schema=None) as batch_op:
batch_op.alter_column("unit__id", existing_type=sa.INTEGER(), nullable=False)

with op.batch_alter_table("runmetaentry", schema=None) as batch_op:
batch_op.add_column(sa.Column("dtype", sa.String(length=20), nullable=False))
batch_op.drop_column("type")

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("runmetaentry", schema=None) as batch_op:
batch_op.add_column(sa.Column("type", sa.VARCHAR(length=20), nullable=False))
batch_op.drop_column("dtype")

with op.batch_alter_table("optimization_scalar", schema=None) as batch_op:
batch_op.alter_column("unit__id", existing_type=sa.INTEGER(), nullable=True)

# ### end Alembic commands ###

0 comments on commit c18ed42

Please sign in to comment.