Added initial_weight and empty_weight to spool
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""spool weights.
|
||||
|
||||
Revision ID: aafcd7fb0e84
|
||||
Revises: b8881bdb716c
|
||||
Create Date: 2024-03-26 09:48:09.930022
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'aafcd7fb0e84'
|
||||
down_revision = 'b8881bdb716c'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Perform the upgrade."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('spool', sa.Column('initial_weight', sa.Float(), nullable=True, comment="The initial total weight of the spool (gross weight)."))
|
||||
op.add_column('spool', sa.Column('empty_weight', sa.Float(), nullable=True, comment="The weight of the empty spool (tare weight)."))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Perform the downgrade."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('spool', 'empty_weight')
|
||||
op.drop_column('spool', 'initial_weight')
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,46 @@
|
||||
"""spool weight population.
|
||||
|
||||
Revision ID: 304a32906234
|
||||
Revises: aafcd7fb0e84
|
||||
Create Date: 2024-03-26 13:49:26.594399
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '304a32906234'
|
||||
down_revision = 'aafcd7fb0e84'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
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))
|
||||
|
||||
spool = sa.Table(
|
||||
'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()
|
||||
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)
|
||||
op.execute(set_initial_weight)
|
||||
|
||||
set_empty_weight = sa.update(spool).values(empty_weight=empty_weight)
|
||||
op.execute(set_empty_weight)
|
||||
pass
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Perform the downgrade."""
|
||||
pass
|
||||
Reference in New Issue
Block a user