main commit
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-16 16:30:25 +09:00
parent 91c7e04474
commit 537e7b363f
1146 changed files with 45926 additions and 77196 deletions

View File

@@ -0,0 +1,151 @@
"""Create nutrition service tables
Revision ID: 3f4e5a1b8c9d
Revises: 2ede6d343f7c
Create Date: 2025-10-16 23:01:02.123456
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '3f4e5a1b8c9d'
down_revision = '49846a45b6b0'
branch_labels = None
depends_on = None
def upgrade():
# Таблица продуктов питания
op.create_table(
'food_items',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('fatsecret_id', sa.String(length=50), nullable=True),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('brand', sa.String(length=255), nullable=True),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('food_type', sa.String(length=50), nullable=True),
sa.Column('serving_size', sa.String(length=100), nullable=True),
sa.Column('serving_weight_grams', sa.Float(), nullable=True),
sa.Column('calories', sa.Float(), nullable=True),
sa.Column('protein_grams', sa.Float(), nullable=True),
sa.Column('fat_grams', sa.Float(), nullable=True),
sa.Column('carbs_grams', sa.Float(), nullable=True),
sa.Column('fiber_grams', sa.Float(), nullable=True),
sa.Column('sugar_grams', sa.Float(), nullable=True),
sa.Column('sodium_mg', sa.Float(), nullable=True),
sa.Column('cholesterol_mg', sa.Float(), nullable=True),
sa.Column('ingredients', sa.Text(), nullable=True),
sa.Column('is_verified', sa.Boolean(), nullable=True),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_food_items_fatsecret_id'), 'food_items', ['fatsecret_id'], unique=True)
op.create_index(op.f('ix_food_items_name'), 'food_items', ['name'], unique=False)
op.create_index(op.f('ix_food_items_uuid'), 'food_items', ['uuid'], unique=True)
# Таблица записей пользователя о потреблении пищи
op.create_table(
'user_nutrition_entries',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('entry_date', sa.Date(), nullable=False),
sa.Column('meal_type', sa.String(length=50), nullable=False),
sa.Column('food_item_id', sa.Integer(), nullable=True),
sa.Column('custom_food_name', sa.String(length=255), nullable=True),
sa.Column('quantity', sa.Float(), nullable=False),
sa.Column('unit', sa.String(length=50), nullable=True),
sa.Column('calories', sa.Float(), nullable=True),
sa.Column('protein_grams', sa.Float(), nullable=True),
sa.Column('fat_grams', sa.Float(), nullable=True),
sa.Column('carbs_grams', sa.Float(), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['food_item_id'], ['food_items.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_user_nutrition_entries_entry_date'), 'user_nutrition_entries', ['entry_date'], unique=False)
op.create_index(op.f('ix_user_nutrition_entries_user_id'), 'user_nutrition_entries', ['user_id'], unique=False)
op.create_index(op.f('ix_user_nutrition_entries_uuid'), 'user_nutrition_entries', ['uuid'], unique=True)
# Таблица для отслеживания потребления воды
op.create_table(
'water_intake',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('entry_date', sa.Date(), nullable=False),
sa.Column('amount_ml', sa.Integer(), nullable=False),
sa.Column('entry_time', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('notes', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_water_intake_entry_date'), 'water_intake', ['entry_date'], unique=False)
op.create_index(op.f('ix_water_intake_user_id'), 'water_intake', ['user_id'], unique=False)
op.create_index(op.f('ix_water_intake_uuid'), 'water_intake', ['uuid'], unique=True)
# Таблица для отслеживания физической активности
op.create_table(
'user_activity_entries',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('entry_date', sa.Date(), nullable=False),
sa.Column('activity_type', sa.String(length=100), nullable=False),
sa.Column('duration_minutes', sa.Integer(), nullable=False),
sa.Column('calories_burned', sa.Float(), nullable=True),
sa.Column('distance_km', sa.Float(), nullable=True),
sa.Column('steps', sa.Integer(), nullable=True),
sa.Column('intensity', sa.String(length=20), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_user_activity_entries_entry_date'), 'user_activity_entries', ['entry_date'], unique=False)
op.create_index(op.f('ix_user_activity_entries_user_id'), 'user_activity_entries', ['user_id'], unique=False)
op.create_index(op.f('ix_user_activity_entries_uuid'), 'user_activity_entries', ['uuid'], unique=True)
# Таблица для хранения целей пользователя по питанию и активности
op.create_table(
'nutrition_goals',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('daily_calorie_goal', sa.Integer(), nullable=True),
sa.Column('protein_goal_grams', sa.Integer(), nullable=True),
sa.Column('fat_goal_grams', sa.Integer(), nullable=True),
sa.Column('carbs_goal_grams', sa.Integer(), nullable=True),
sa.Column('water_goal_ml', sa.Integer(), nullable=True),
sa.Column('activity_goal_minutes', sa.Integer(), nullable=True),
sa.Column('weight_goal_kg', sa.Float(), nullable=True),
sa.Column('goal_type', sa.String(length=50), nullable=True),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_nutrition_goals_user_id'), 'nutrition_goals', ['user_id'], unique=True)
def downgrade():
op.drop_index(op.f('ix_nutrition_goals_user_id'), table_name='nutrition_goals')
op.drop_table('nutrition_goals')
op.drop_index(op.f('ix_user_activity_entries_uuid'), table_name='user_activity_entries')
op.drop_index(op.f('ix_user_activity_entries_user_id'), table_name='user_activity_entries')
op.drop_index(op.f('ix_user_activity_entries_entry_date'), table_name='user_activity_entries')
op.drop_table('user_activity_entries')
op.drop_index(op.f('ix_water_intake_uuid'), table_name='water_intake')
op.drop_index(op.f('ix_water_intake_user_id'), table_name='water_intake')
op.drop_index(op.f('ix_water_intake_entry_date'), table_name='water_intake')
op.drop_table('water_intake')
op.drop_index(op.f('ix_user_nutrition_entries_uuid'), table_name='user_nutrition_entries')
op.drop_index(op.f('ix_user_nutrition_entries_user_id'), table_name='user_nutrition_entries')
op.drop_index(op.f('ix_user_nutrition_entries_entry_date'), table_name='user_nutrition_entries')
op.drop_table('user_nutrition_entries')
op.drop_index(op.f('ix_food_items_uuid'), table_name='food_items')
op.drop_index(op.f('ix_food_items_name'), table_name='food_items')
op.drop_index(op.f('ix_food_items_fatsecret_id'), table_name='food_items')
op.drop_table('food_items')

View File

@@ -0,0 +1,217 @@
"""Add nutrition service tables
Revision ID: a2e71842cf5a
Revises: c78a12db4567
Create Date: 2025-10-16 10:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = "a2e71842cf5a"
down_revision = "c78a12db4567"
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
# Создание таблицы food_items
op.create_table(
"food_items",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("fatsecret_id", sa.String(length=50), nullable=True),
sa.Column("name", sa.String(length=255), nullable=False),
sa.Column("brand", sa.String(length=255), nullable=True),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("food_type", sa.String(length=50), nullable=True),
sa.Column("serving_size", sa.String(length=100), nullable=True),
sa.Column("serving_weight_grams", sa.Float(), nullable=True),
sa.Column("calories", sa.Float(), nullable=True),
sa.Column("protein_grams", sa.Float(), nullable=True),
sa.Column("fat_grams", sa.Float(), nullable=True),
sa.Column("carbs_grams", sa.Float(), nullable=True),
sa.Column("fiber_grams", sa.Float(), nullable=True),
sa.Column("sugar_grams", sa.Float(), nullable=True),
sa.Column("sodium_mg", sa.Float(), nullable=True),
sa.Column("cholesterol_mg", sa.Float(), nullable=True),
sa.Column("ingredients", sa.Text(), nullable=True),
sa.Column("is_verified", sa.Boolean(), nullable=True),
sa.Column(
"created_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column("updated_at", sa.TIMESTAMP(timezone=True), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_food_items_fatsecret_id"), "food_items", ["fatsecret_id"], unique=True
)
op.create_index(op.f("ix_food_items_uuid"), "food_items", ["uuid"], unique=True)
# Создание таблицы user_nutrition_entries
op.create_table(
"user_nutrition_entries",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("user_id", sa.Integer(), nullable=False),
sa.Column("entry_date", sa.Date(), nullable=False),
sa.Column("meal_type", sa.String(length=50), nullable=False),
sa.Column("food_item_id", sa.Integer(), nullable=True),
sa.Column("custom_food_name", sa.String(length=255), nullable=True),
sa.Column("quantity", sa.Float(), nullable=False),
sa.Column("unit", sa.String(length=50), nullable=True),
sa.Column("calories", sa.Float(), nullable=True),
sa.Column("protein_grams", sa.Float(), nullable=True),
sa.Column("fat_grams", sa.Float(), nullable=True),
sa.Column("carbs_grams", sa.Float(), nullable=True),
sa.Column("notes", sa.Text(), nullable=True),
sa.Column(
"created_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column("updated_at", sa.TIMESTAMP(timezone=True), nullable=True),
sa.ForeignKeyConstraint(["food_item_id"], ["food_items.id"],),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_user_nutrition_entries_entry_date"),
"user_nutrition_entries",
["entry_date"],
unique=False,
)
op.create_index(
op.f("ix_user_nutrition_entries_user_id"),
"user_nutrition_entries",
["user_id"],
unique=False,
)
op.create_index(
op.f("ix_user_nutrition_entries_uuid"),
"user_nutrition_entries",
["uuid"],
unique=True
)
# Создание таблицы water_intake
op.create_table(
"water_intake",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("user_id", sa.Integer(), nullable=False),
sa.Column("entry_date", sa.Date(), nullable=False),
sa.Column("amount_ml", sa.Integer(), nullable=False),
sa.Column(
"entry_time",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column("notes", sa.Text(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_water_intake_entry_date"), "water_intake", ["entry_date"], unique=False
)
op.create_index(
op.f("ix_water_intake_user_id"), "water_intake", ["user_id"], unique=False
)
op.create_index(op.f("ix_water_intake_uuid"), "water_intake", ["uuid"], unique=True)
# Создание таблицы user_activity_entries
op.create_table(
"user_activity_entries",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("user_id", sa.Integer(), nullable=False),
sa.Column("entry_date", sa.Date(), nullable=False),
sa.Column("activity_type", sa.String(length=100), nullable=False),
sa.Column("duration_minutes", sa.Integer(), nullable=False),
sa.Column("calories_burned", sa.Float(), nullable=True),
sa.Column("distance_km", sa.Float(), nullable=True),
sa.Column("steps", sa.Integer(), nullable=True),
sa.Column("intensity", sa.String(length=20), nullable=True),
sa.Column("notes", sa.Text(), nullable=True),
sa.Column(
"created_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_user_activity_entries_entry_date"),
"user_activity_entries",
["entry_date"],
unique=False,
)
op.create_index(
op.f("ix_user_activity_entries_user_id"),
"user_activity_entries",
["user_id"],
unique=False,
)
op.create_index(
op.f("ix_user_activity_entries_uuid"),
"user_activity_entries",
["uuid"],
unique=True
)
# Создание таблицы nutrition_goals
op.create_table(
"nutrition_goals",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("user_id", sa.Integer(), nullable=False),
sa.Column("daily_calorie_goal", sa.Integer(), nullable=True),
sa.Column("protein_goal_grams", sa.Integer(), nullable=True),
sa.Column("fat_goal_grams", sa.Integer(), nullable=True),
sa.Column("carbs_goal_grams", sa.Integer(), nullable=True),
sa.Column("water_goal_ml", sa.Integer(), nullable=True),
sa.Column("activity_goal_minutes", sa.Integer(), nullable=True),
sa.Column("weight_goal_kg", sa.Float(), nullable=True),
sa.Column("goal_type", sa.String(length=50), nullable=True),
sa.Column(
"created_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column("updated_at", sa.TIMESTAMP(timezone=True), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_nutrition_goals_user_id"), "nutrition_goals", ["user_id"], unique=True
)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_nutrition_goals_user_id"), table_name="nutrition_goals")
op.drop_table("nutrition_goals")
op.drop_index(op.f("ix_user_activity_entries_uuid"), table_name="user_activity_entries")
op.drop_index(op.f("ix_user_activity_entries_user_id"), table_name="user_activity_entries")
op.drop_index(op.f("ix_user_activity_entries_entry_date"), table_name="user_activity_entries")
op.drop_table("user_activity_entries")
op.drop_index(op.f("ix_water_intake_uuid"), table_name="water_intake")
op.drop_index(op.f("ix_water_intake_user_id"), table_name="water_intake")
op.drop_index(op.f("ix_water_intake_entry_date"), table_name="water_intake")
op.drop_table("water_intake")
op.drop_index(op.f("ix_user_nutrition_entries_uuid"), table_name="user_nutrition_entries")
op.drop_index(op.f("ix_user_nutrition_entries_user_id"), table_name="user_nutrition_entries")
op.drop_index(op.f("ix_user_nutrition_entries_entry_date"), table_name="user_nutrition_entries")
op.drop_table("user_nutrition_entries")
op.drop_index(op.f("ix_food_items_uuid"), table_name="food_items")
op.drop_index(op.f("ix_food_items_fatsecret_id"), table_name="food_items")
op.drop_table("food_items")
# ### end Alembic commands ###