generated from pptx704/fastapi-template
66 lines
2.7 KiB
Python
66 lines
2.7 KiB
Python
"""Initial migrations
|
|
|
|
Revision ID: ffce71fc567e
|
|
Revises:
|
|
Create Date: 2025-07-03 08:51:38.752525
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = 'ffce71fc567e'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table('users',
|
|
sa.Column('id', sa.UUID(), nullable=False),
|
|
sa.Column('name', sa.String(), nullable=False),
|
|
sa.Column('email', sa.String(), nullable=False),
|
|
sa.Column('password_hash', sa.String(length=60), nullable=False),
|
|
sa.Column('is_verified', sa.Boolean(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), 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_table('posts',
|
|
sa.Column('id', sa.UUID(), nullable=False),
|
|
sa.Column('user_id', sa.UUID(), nullable=False),
|
|
sa.Column('content', sa.String(length=512), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_posts_created_at'), 'posts', ['created_at'], unique=False)
|
|
op.create_index(op.f('ix_posts_id'), 'posts', ['id'], unique=False)
|
|
op.create_table('post_likes',
|
|
sa.Column('user_id', sa.UUID(), nullable=False),
|
|
sa.Column('post_id', sa.UUID(), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(['post_id'], ['posts.id'], ondelete='CASCADE'),
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('user_id', 'post_id')
|
|
)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.drop_table('post_likes')
|
|
op.drop_index(op.f('ix_posts_id'), table_name='posts')
|
|
op.drop_index(op.f('ix_posts_created_at'), table_name='posts')
|
|
op.drop_table('posts')
|
|
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')
|
|
# ### end Alembic commands ###
|