mirror of
https://github.com/StefBuwalda/cal_counter.git
synced 2025-10-30 03:10:00 +00:00
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:
73
migrations/versions/46cd3e1a3b67_.py
Normal file
73
migrations/versions/46cd3e1a3b67_.py
Normal 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 ###
|
||||
50
migrations/versions/bb1d9bebf8f6_.py
Normal file
50
migrations/versions/bb1d9bebf8f6_.py
Normal 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 ###
|
||||
Reference in New Issue
Block a user