mirror of
				https://github.com/StefBuwalda/cal_counter.git
				synced 2025-10-31 03:39:59 +00:00 
			
		
		
		
	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.
		
			
				
	
	
		
			35 lines
		
	
	
		
			1006 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			1006 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| """empty message
 | |
| 
 | |
| Revision ID: 99f86450e4af
 | |
| Revises: bb1d9bebf8f6
 | |
| Create Date: 2025-08-11 12:36:26.924696
 | |
| 
 | |
| """
 | |
| from alembic import op
 | |
| import sqlalchemy as sa
 | |
| 
 | |
| 
 | |
| # revision identifiers, used by Alembic.
 | |
| revision = '99f86450e4af'
 | |
| down_revision = 'bb1d9bebf8f6'
 | |
| 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.drop_constraint(batch_op.f('barcode_owner_key'), type_='unique')
 | |
|         batch_op.create_unique_constraint('name_owner_key', ['name', '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('name_owner_key', type_='unique')
 | |
|         batch_op.create_unique_constraint(batch_op.f('barcode_owner_key'), ['barcode', 'owner_id'])
 | |
| 
 | |
|     # ### end Alembic commands ###
 |