second-project-wahm3i/alembic/versions/20250414_010203_5350732a_update_grocery.py

28 lines
810 B
Python

"""add color field to groceries table
Revision ID: 9a4c2e7d
Revises: 8f2b3d5c
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():
# 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():
with op.batch_alter_table('groceries') as batch_op:
batch_op.drop_index('ix_groceries_name')
batch_op.drop_column('color')