Fixed formatting
This commit is contained in:
@@ -8,29 +8,46 @@ import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '304a32906234'
|
||||
down_revision = 'aafcd7fb0e84'
|
||||
revision = "304a32906234"
|
||||
down_revision = "aafcd7fb0e84"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
filament = sa.Table('filament',
|
||||
"""Pre-populate the spool weights."""
|
||||
"""This must be done in a separate migration because"""
|
||||
"""of cockroachdb's execution of alembic migrations"""
|
||||
filament = sa.Table(
|
||||
"filament",
|
||||
sa.MetaData(),
|
||||
sa.Column('id', sa.Integer, primary_key=True),
|
||||
sa.Column('weight', sa.Float(), nullable=True),
|
||||
sa.Column('spool_weight', sa.Float(), nullable=True))
|
||||
|
||||
sa.Column("id", sa.Integer, primary_key=True),
|
||||
sa.Column("weight", sa.Float(), nullable=True),
|
||||
sa.Column("spool_weight", sa.Float(), nullable=True),
|
||||
)
|
||||
|
||||
spool = sa.Table(
|
||||
'spool',
|
||||
"spool",
|
||||
sa.MetaData(),
|
||||
sa.Column('id', sa.Integer, primary_key=True),
|
||||
sa.Column('filament_id', sa.Integer),
|
||||
sa.Column('initial_weight', sa.Float(), nullable=False, comment="The initial total weight of the spool (gross weight)."),
|
||||
sa.Column('empty_weight', sa.Float(), nullable=False, comment="The weight of the empty spool (tare weight).")
|
||||
)
|
||||
|
||||
initial_weight = sa.select((filament.c.weight + filament.c.spool_weight).label("initial_weight")).where(filament.c.id == spool.c.filament_id).scalar_subquery()
|
||||
sa.Column("id", sa.Integer, primary_key=True),
|
||||
sa.Column("filament_id", sa.Integer),
|
||||
sa.Column(
|
||||
"initial_weight",
|
||||
sa.Float(),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column(
|
||||
"empty_weight",
|
||||
sa.Float(),
|
||||
nullable=False,
|
||||
),
|
||||
)
|
||||
|
||||
initial_weight = (
|
||||
sa.select((filament.c.weight + filament.c.spool_weight).label("initial_weight"))
|
||||
.where(filament.c.id == spool.c.filament_id)
|
||||
.scalar_subquery()
|
||||
)
|
||||
empty_weight = sa.select(filament.c.spool_weight).where(filament.c.id == spool.c.filament_id).scalar_subquery()
|
||||
|
||||
set_initial_weight = sa.update(spool).values(initial_weight=initial_weight)
|
||||
@@ -43,4 +60,3 @@ def upgrade() -> None:
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Perform the downgrade."""
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user