Add migration for Food
This commit is contained in:
parent
15e8315b0a
commit
9e907a1c79
40
alembic/versions/20250328_144526_a76a4078_create_food.py
Normal file
40
alembic/versions/20250328_144526_a76a4078_create_food.py
Normal file
@ -0,0 +1,40 @@
|
||||
"""create foods table
|
||||
|
||||
Revision ID: a2b3c4d5e6f7
|
||||
Revises: 0001
|
||||
Create Date: 2024-03-26 12:00:00.000000
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
# revision identifiers
|
||||
revision = 'a2b3c4d5e6f7'
|
||||
down_revision = '0001'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def upgrade():
|
||||
op.create_table(
|
||||
'foods',
|
||||
sa.Column('id', UUID(as_uuid=True), primary_key=True, default=sa.text('gen_random_uuid()')),
|
||||
sa.Column('name', sa.String(), nullable=False),
|
||||
sa.Column('description', sa.Text(), nullable=True),
|
||||
sa.Column('price', sa.Float(), nullable=False),
|
||||
sa.Column('category', sa.String(), nullable=False),
|
||||
sa.Column('is_available', sa.Boolean(), server_default='true'),
|
||||
sa.Column('calories', sa.Integer(), nullable=True),
|
||||
sa.Column('ingredients', sa.Text(), nullable=True),
|
||||
sa.Column('image_url', sa.String(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), server_default=sa.func.now()),
|
||||
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.now(), onupdate=sa.func.now())
|
||||
)
|
||||
|
||||
op.create_index('ix_foods_name', 'foods', ['name'])
|
||||
op.create_index('ix_foods_category', 'foods', ['category'])
|
||||
|
||||
def downgrade():
|
||||
op.drop_index('ix_foods_category')
|
||||
op.drop_index('ix_foods_name')
|
||||
op.drop_table('foods')
|
Loading…
x
Reference in New Issue
Block a user