mirror of
https://github.com/StefBuwalda/cal_counter.git
synced 2025-10-30 11:19:59 +00:00
Improve FoodItem uniqueness and add name constraint
Refactored add_meal routes to check for existing FoodItems by name or barcode and improved form handling. Made barcode optional in FoodItemForm. Added a unique constraint on (name, owner_id) for FoodItem in both the model and database migrations, while retaining the (barcode, owner_id) constraint. Updated FoodItem relationship to cascade deletes.
This commit is contained in:
32
migrations/versions/f5fbbe915d51_.py
Normal file
32
migrations/versions/f5fbbe915d51_.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: f5fbbe915d51
|
||||
Revises: 99f86450e4af
|
||||
Create Date: 2025-08-11 12:37:02.407643
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'f5fbbe915d51'
|
||||
down_revision = '99f86450e4af'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('food_item', schema=None) as batch_op:
|
||||
batch_op.create_unique_constraint('barcode_owner_key', ['barcode', 'owner_id'])
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('food_item', schema=None) as batch_op:
|
||||
batch_op.drop_constraint('barcode_owner_key', type_='unique')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user