Files
bakery-ia/services/recipes/migrations/versions/0001_initial_schema.py
2025-09-30 21:58:10 +02:00

84 lines
4.0 KiB
Python

"""Initial schema for recipes service
Revision ID: 0001
Revises:
Create Date: 2025-09-30 18:00:00.0000
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '00001'
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
op.create_table('recipes',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('tenant_id', sa.UUID(), nullable=False),
sa.Column('name', sa.String(255), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('category', sa.String(100), nullable=True),
sa.Column('cuisine', sa.String(100), nullable=True),
sa.Column('difficulty_level', sa.String(50), nullable=True),
sa.Column('preparation_time', sa.Integer(), nullable=True),
sa.Column('cooking_time', sa.Integer(), nullable=True),
sa.Column('total_time', sa.Integer(), nullable=True),
sa.Column('servings', sa.Integer(), nullable=True),
sa.Column('calories_per_serving', sa.Integer(), nullable=True),
sa.Column('status', sa.String(50), nullable=True),
sa.Column('created_by', sa.UUID(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_recipes_tenant_id'), 'recipes', ['tenant_id'], unique=False)
op.create_index(op.f('ix_recipes_name'), 'recipes', ['name'], unique=False)
op.create_index(op.f('ix_recipes_category'), 'recipes', ['category'], unique=False)
op.create_index(op.f('ix_recipes_status'), 'recipes', ['status'], unique=False)
op.create_table('recipe_ingredients',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('recipe_id', sa.UUID(), nullable=False),
sa.Column('ingredient_name', sa.String(255), nullable=False),
sa.Column('quantity', sa.Float(), nullable=False),
sa.Column('unit', sa.String(50), nullable=False),
sa.Column('optional', sa.Boolean(), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.ForeignKeyConstraint(['recipe_id'], ['recipes.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_recipe_ingredients_recipe_id'), 'recipe_ingredients', ['recipe_id'], unique=False)
op.create_index(op.f('ix_recipe_ingredients_ingredient_name'), 'recipe_ingredients', ['ingredient_name'], unique=False)
op.create_table('recipe_steps',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('recipe_id', sa.UUID(), nullable=False),
sa.Column('step_number', sa.Integer(), nullable=False),
sa.Column('description', sa.Text(), nullable=False),
sa.Column('duration', sa.Integer(), nullable=True),
sa.Column('temperature', sa.Float(), nullable=True),
sa.ForeignKeyConstraint(['recipe_id'], ['recipes.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_recipe_steps_recipe_id'), 'recipe_steps', ['recipe_id'], unique=False)
op.create_index(op.f('ix_recipe_steps_step_number'), 'recipe_steps', ['step_number'], unique=False)
def downgrade() -> None:
op.drop_index(op.f('ix_recipe_steps_step_number'), table_name='recipe_steps')
op.drop_index(op.f('ix_recipe_steps_recipe_id'), table_name='recipe_steps')
op.drop_table('recipe_steps')
op.drop_index(op.f('ix_recipe_ingredients_ingredient_name'), table_name='recipe_ingredients')
op.drop_index(op.f('ix_recipe_ingredients_recipe_id'), table_name='recipe_ingredients')
op.drop_table('recipe_ingredients')
op.drop_index(op.f('ix_recipes_status'), table_name='recipes')
op.drop_index(op.f('ix_recipes_category'), table_name='recipes')
op.drop_index(op.f('ix_recipes_name'), table_name='recipes')
op.drop_index(op.f('ix_recipes_tenant_id'), table_name='recipes')
op.drop_table('recipes')