Fix DB issue 2s
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
# services/recipes/Dockerfile
|
||||
# Recipes Dockerfile
|
||||
# Add this stage at the top of each service Dockerfile
|
||||
FROM python:3.11-slim AS shared
|
||||
WORKDIR /shared
|
||||
COPY shared/ /shared/
|
||||
|
||||
# Then your main service stage
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /app
|
||||
@@ -6,38 +12,34 @@ WORKDIR /app
|
||||
# Install system dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gcc \
|
||||
curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy requirements first for better caching
|
||||
# Copy requirements
|
||||
COPY services/recipes/requirements.txt .
|
||||
|
||||
# Install Python dependencies
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy shared utilities
|
||||
COPY shared/ ./shared/
|
||||
# Copy shared libraries from the shared stage
|
||||
COPY --from=shared /shared /app/shared
|
||||
|
||||
# Copy application code
|
||||
COPY services/recipes/app/ ./app/
|
||||
|
||||
# Copy migrations and alembic config
|
||||
COPY services/recipes/migrations/ /app/migrations/
|
||||
COPY services/recipes/alembic.ini /app/alembic.ini
|
||||
COPY services/recipes/ .
|
||||
|
||||
# Copy scripts directory
|
||||
COPY scripts/ ./scripts/
|
||||
COPY scripts/ /app/scripts/
|
||||
|
||||
# Create logs directory
|
||||
RUN mkdir -p logs
|
||||
# Add shared libraries to Python path
|
||||
ENV PYTHONPATH="/app:/app/shared:${PYTHONPATH:-}"
|
||||
|
||||
# Set environment variables
|
||||
ENV PYTHONPATH=/app
|
||||
ENV ENVIRONMENT=production
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8000
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD curl -f http://localhost:8000/health || exit 1
|
||||
|
||||
# Run the application
|
||||
CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
# Run application
|
||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
|
||||
@@ -20,7 +20,7 @@ from .models import recipes as recipe_models
|
||||
class RecipesService(StandardFastAPIService):
|
||||
"""Recipes Service with standardized setup"""
|
||||
|
||||
expected_migration_version = "001_initial_recipes"
|
||||
expected_migration_version = "00001"
|
||||
|
||||
async def on_startup(self, app):
|
||||
"""Custom startup logic including migration verification"""
|
||||
|
||||
83
services/recipes/migrations/versions/0001_initial_schema.py
Normal file
83
services/recipes/migrations/versions/0001_initial_schema.py
Normal file
@@ -0,0 +1,83 @@
|
||||
"""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')
|
||||
@@ -1 +0,0 @@
|
||||
/Users/urtzialfaro/Documents/bakery-ia/services/sales/shared
|
||||
Reference in New Issue
Block a user