Add Docker, migrations, and initial database setup

Added Dockerfile and docker-compose.yaml for containerization. Introduced Alembic migrations with initial schema and a migration to alter column types. Added requirements.txt for dependencies and removed temp.py cleanup script. Updated .gitignore to allow tracking of migration files.
This commit is contained in:
2025-08-11 00:49:46 +02:00
parent b8bd8d802b
commit 66204e7e4a
11 changed files with 349 additions and 17 deletions

View File

@@ -0,0 +1,73 @@
"""empty message
Revision ID: 46cd3e1a3b67
Revises:
Create Date: 2025-07-07 14:31:50.181885
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '46cd3e1a3b67'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('unit',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('symbol', sa.String(length=10), nullable=False),
sa.Column('name', sa.String(length=50), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name'),
sa.UniqueConstraint('symbol')
)
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(length=150), nullable=False),
sa.Column('password', sa.String(), nullable=False),
sa.Column('is_admin', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('username')
)
op.create_table('food_item',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('barcode', sa.Integer(), nullable=True),
sa.Column('owner_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=150), nullable=False),
sa.Column('energy_100', sa.Integer(), nullable=False),
sa.Column('protein_100', sa.Float(), nullable=False),
sa.Column('carbs_100', sa.Float(), nullable=False),
sa.Column('sugar_100', sa.Float(), nullable=True),
sa.Column('fat_100', sa.Float(), nullable=False),
sa.Column('saturated_fat_100', sa.Float(), nullable=True),
sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('barcode', 'owner_id', name='barcode_owner_key')
)
op.create_table('food_log',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('datetime_created', sa.DateTime(), nullable=False),
sa.Column('date_', sa.Date(), nullable=False),
sa.Column('food_item_id', sa.Integer(), nullable=False),
sa.Column('part_of_day', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('amount', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['food_item_id'], ['food_item.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('food_log')
op.drop_table('food_item')
op.drop_table('user')
op.drop_table('unit')
# ### end Alembic commands ###

View File

@@ -0,0 +1,50 @@
"""empty message
Revision ID: bb1d9bebf8f6
Revises: 46cd3e1a3b67
Create Date: 2025-08-07 16:49:19.511091
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'bb1d9bebf8f6'
down_revision = '46cd3e1a3b67'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('food_item', schema=None) as batch_op:
batch_op.alter_column('barcode',
existing_type=sa.INTEGER(),
type_=sa.String(),
existing_nullable=True)
with op.batch_alter_table('food_log', schema=None) as batch_op:
batch_op.alter_column('amount',
existing_type=sa.INTEGER(),
type_=sa.Float(),
existing_nullable=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('food_log', schema=None) as batch_op:
batch_op.alter_column('amount',
existing_type=sa.Float(),
type_=sa.INTEGER(),
existing_nullable=False)
with op.batch_alter_table('food_item', schema=None) as batch_op:
batch_op.alter_column('barcode',
existing_type=sa.String(),
type_=sa.INTEGER(),
existing_nullable=True)
# ### end Alembic commands ###