|
"""Initiate Database Migration |
|
|
|
Revision ID: 5dceb6aede3b |
|
Revises: |
|
Create Date: 2024-08-20 17:33:42.696641 |
|
|
|
""" |
|
from typing import Sequence, Union |
|
|
|
from alembic import op |
|
import sqlalchemy as sa |
|
|
|
|
|
|
|
revision: str = '5dceb6aede3b' |
|
down_revision: Union[str, None] = None |
|
branch_labels: Union[str, Sequence[str], None] = None |
|
depends_on: Union[str, Sequence[str], None] = None |
|
|
|
|
|
def upgrade() -> None: |
|
|
|
op.create_table('meals', |
|
sa.Column('id', sa.Integer(), nullable=False), |
|
sa.Column('name', sa.String(), nullable=False), |
|
sa.Column('description', sa.String(), nullable=False), |
|
sa.Column('price', sa.Float(), nullable=False), |
|
sa.Column('category', sa.String(), nullable=True), |
|
sa.PrimaryKeyConstraint('id') |
|
) |
|
op.create_index(op.f('ix_meals_id'), 'meals', ['id'], unique=False) |
|
op.create_index(op.f('ix_meals_name'), 'meals', ['name'], unique=True) |
|
op.create_table('users', |
|
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('age', sa.Integer(), nullable=True), |
|
sa.Column('preferences', sa.ARRAY(sa.String()), nullable=True), |
|
sa.Column('is_active', sa.Boolean(), nullable=True), |
|
sa.Column('is_admin', sa.Boolean(), nullable=True), |
|
sa.Column('updated_at', sa.DateTime(), nullable=True), |
|
sa.Column('created_at', sa.DateTime(), nullable=True), |
|
sa.PrimaryKeyConstraint('id') |
|
) |
|
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True) |
|
op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False) |
|
op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True) |
|
op.create_table('orders', |
|
sa.Column('id', sa.Integer(), nullable=False), |
|
sa.Column('user_id', sa.Integer(), nullable=False), |
|
sa.Column('meal_id', sa.Integer(), nullable=False), |
|
sa.Column('quantity', sa.Integer(), nullable=False), |
|
sa.Column('timestamp', sa.DateTime(), nullable=True), |
|
sa.ForeignKeyConstraint(['meal_id'], ['meals.id'], ), |
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), |
|
sa.PrimaryKeyConstraint('id') |
|
) |
|
op.create_index(op.f('ix_orders_id'), 'orders', ['id'], unique=False) |
|
op.create_index(op.f('ix_orders_meal_id'), 'orders', ['meal_id'], unique=False) |
|
op.create_index(op.f('ix_orders_user_id'), 'orders', ['user_id'], unique=False) |
|
op.create_table('user_embeddings', |
|
sa.Column('id', sa.Integer(), nullable=False), |
|
sa.Column('user_id', sa.Integer(), nullable=False), |
|
sa.Column('embeddings', sa.ARRAY(sa.Float()), nullable=False), |
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), |
|
sa.PrimaryKeyConstraint('id'), |
|
sa.UniqueConstraint('user_id') |
|
) |
|
op.create_index(op.f('ix_user_embeddings_id'), 'user_embeddings', ['id'], unique=False) |
|
|
|
|
|
|
|
def downgrade() -> None: |
|
|
|
op.drop_index(op.f('ix_user_embeddings_id'), table_name='user_embeddings') |
|
op.drop_table('user_embeddings') |
|
op.drop_index(op.f('ix_orders_user_id'), table_name='orders') |
|
op.drop_index(op.f('ix_orders_meal_id'), table_name='orders') |
|
op.drop_index(op.f('ix_orders_id'), table_name='orders') |
|
op.drop_table('orders') |
|
op.drop_index(op.f('ix_users_username'), table_name='users') |
|
op.drop_index(op.f('ix_users_id'), table_name='users') |
|
op.drop_index(op.f('ix_users_email'), table_name='users') |
|
op.drop_table('users') |
|
op.drop_index(op.f('ix_meals_name'), table_name='meals') |
|
op.drop_index(op.f('ix_meals_id'), table_name='meals') |
|
op.drop_table('meals') |
|
|
|
|