"""Initial tables Revision ID: 001 Revises: Create Date: 2023-09-26 10:00:00.000000 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = '001' down_revision = None branch_labels = None depends_on = None def upgrade(): # Create user table op.create_table( 'user', sa.Column('id', sa.Integer(), nullable=False), sa.Column('email', sa.String(), nullable=False), sa.Column('username', sa.String(), nullable=False), sa.Column('hashed_password', sa.String(), nullable=False), sa.Column('first_name', sa.String(), nullable=True), sa.Column('last_name', sa.String(), nullable=True), sa.Column('is_active', sa.Boolean(), nullable=True, default=True), sa.Column('is_superuser', sa.Boolean(), nullable=True, default=False), sa.Column('target_calories', sa.Float(), nullable=True, default=2000.0), sa.Column('height_cm', sa.Float(), nullable=True), sa.Column('weight_kg', sa.Float(), nullable=True), sa.Column('date_of_birth', sa.DateTime(), nullable=True), sa.Column('gender', sa.String(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id'), ) op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True) op.create_index(op.f('ix_user_id'), 'user', ['id'], unique=False) op.create_index(op.f('ix_user_username'), 'user', ['username'], unique=True) # Create food table op.create_table( 'food', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(), nullable=False), sa.Column('description', sa.String(), nullable=True), sa.Column('calories_per_100g', sa.Float(), nullable=False), sa.Column('protein_g', sa.Float(), nullable=True), sa.Column('carbs_g', sa.Float(), nullable=True), sa.Column('fat_g', sa.Float(), nullable=True), sa.Column('fiber_g', sa.Float(), nullable=True), sa.Column('is_verified', sa.Boolean(), nullable=True, default=False), sa.Column('created_by_id', sa.Integer(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id'), ) op.create_index(op.f('ix_food_id'), 'food', ['id'], unique=False) op.create_index(op.f('ix_food_name'), 'food', ['name'], unique=False) # Create calorie_entry table op.create_table( 'calorieentry', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('food_id', sa.Integer(), nullable=False), sa.Column('quantity_g', sa.Float(), nullable=False), sa.Column('meal_type', sa.String(), nullable=True), sa.Column('notes', sa.String(), nullable=True), sa.Column('consumed_at', sa.DateTime(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.ForeignKeyConstraint(['food_id'], ['food.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id'), ) op.create_index(op.f('ix_calorieentry_id'), 'calorieentry', ['id'], unique=False) def downgrade(): op.drop_index(op.f('ix_calorieentry_id'), table_name='calorieentry') op.drop_table('calorieentry') op.drop_index(op.f('ix_food_name'), table_name='food') op.drop_index(op.f('ix_food_id'), table_name='food') op.drop_table('food') op.drop_index(op.f('ix_user_username'), table_name='user') op.drop_index(op.f('ix_user_id'), table_name='user') op.drop_index(op.f('ix_user_email'), table_name='user') op.drop_table('user')