mirror of
https://github.com/hay-kot/mealie.git
synced 2025-07-11 23:57:14 -07:00
feat: Add the ability to flag a food as "on hand", to exclude from shopping list (#3777)
This commit is contained in:
parent
4831adb0f3
commit
a062a4beaa
8 changed files with 112 additions and 9 deletions
|
@ -0,0 +1,48 @@
|
|||
"""Add staple flag to foods
|
||||
|
||||
Revision ID: 32d69327997b
|
||||
Revises: 7788478a0338
|
||||
Create Date: 2024-06-22 10:17:03.323966
|
||||
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "32d69327997b"
|
||||
down_revision = "7788478a0338"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def is_postgres():
|
||||
return op.get_context().dialect.name == "postgresql"
|
||||
|
||||
|
||||
def upgrade():
|
||||
with op.batch_alter_table("ingredient_foods") as batch_op:
|
||||
batch_op.add_column(sa.Column("on_hand", sa.Boolean(), nullable=True, default=False))
|
||||
|
||||
bind = op.get_bind()
|
||||
session = orm.Session(bind=bind)
|
||||
|
||||
with session:
|
||||
if is_postgres():
|
||||
stmt = "UPDATE ingredient_foods SET on_hand = FALSE;"
|
||||
else:
|
||||
stmt = "UPDATE ingredient_foods SET on_hand = 0;"
|
||||
|
||||
session.execute(sa.text(stmt))
|
||||
|
||||
# forbid nulls after migration
|
||||
with op.batch_alter_table("ingredient_foods") as batch_op:
|
||||
batch_op.alter_column("on_hand", nullable=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
with op.batch_alter_table("ingredient_foods") as batch_op:
|
||||
batch_op.drop_column("on_hand")
|
Loading…
Add table
Add a link
Reference in a new issue