diff --git a/alembic/versions/20250414_010203_5350732a_update_grocery.py b/alembic/versions/20250414_010203_5350732a_update_grocery.py index a546d92..61b8808 100644 --- a/alembic/versions/20250414_010203_5350732a_update_grocery.py +++ b/alembic/versions/20250414_010203_5350732a_update_grocery.py @@ -6,14 +6,23 @@ Create Date: 2024-01-30 10:00:00.000000 from alembic import op import sqlalchemy as sa + # revision identifiers, used by Alembic. revision = '9a4c2e7d' down_revision = '8f2b3d5c' branch_labels = None depends_on = None + def upgrade(): - op.add_column('groceries', sa.Column('color', sa.String(), nullable=True)) + # SQLite doesn't support adding a column with a default value directly + # We need to use batch_alter_table for SQLite compatibility + with op.batch_alter_table('groceries') as batch_op: + batch_op.add_column(sa.Column('color', sa.String(), nullable=True)) + batch_op.create_index('ix_groceries_name', ['name']) + def downgrade(): - op.drop_column('groceries', 'color') \ No newline at end of file + with op.batch_alter_table('groceries') as batch_op: + batch_op.drop_index('ix_groceries_name') + batch_op.drop_column('color') \ No newline at end of file