"""Create tables Revision ID: 0d3f7039ba77 Revises: 7ad624ae1699 Create Date: 2026-01-12 15:51:43.453822 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision: str = '0d3f7039ba77' down_revision: Union[str, Sequence[str], None] = '7ad624ae1699' branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: """Upgrade schema.""" # ### commands auto generated by Alembic - please adjust! ### op.create_table('chat', sa.Column('id', sa.UUID(), nullable=False), sa.Column('is_group', sa.Boolean(), nullable=False), sa.Column('last_message', sa.String(), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.PrimaryKeyConstraint('id', name=op.f('chat_pkey')) ) op.create_index(op.f('chat_id_idx'), 'chat', ['id'], unique=False) op.create_table('user', sa.Column('id', sa.Integer(), nullable=False), sa.Column('display_name', sa.String(), nullable=False), sa.Column('username', sa.String(), nullable=False), sa.Column('email', sa.String(), nullable=False), sa.Column('birth_day', sa.DATE(), nullable=True), sa.Column('description', sa.String(), nullable=True), sa.Column('avatar_url', sa.String(), nullable=True), sa.Column('is_active', sa.Boolean(), nullable=False), sa.Column('is_verified', sa.Boolean(), nullable=False), sa.Column('is_superuser', sa.Boolean(), nullable=False), sa.Column('hashed_password', sa.String(), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.PrimaryKeyConstraint('id', name=op.f('user_pkey')) ) op.create_index(op.f('user_email_idx'), 'user', ['email'], unique=True) op.create_index(op.f('user_id_idx'), 'user', ['id'], unique=False) op.create_index(op.f('user_username_idx'), 'user', ['username'], unique=True) op.create_table('Participant', sa.Column('id', sa.UUID(), nullable=False), sa.Column('chat_id', sa.UUID(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.ForeignKeyConstraint(['chat_id'], ['chat.id'], name=op.f('Participant_chat_id_fkey'), ondelete='CASCADE'), sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('Participant_user_id_fkey'), ondelete='CASCADE'), sa.PrimaryKeyConstraint('id', name=op.f('Participant_pkey')), sa.UniqueConstraint('chat_id', 'user_id', name='uq_chat_user') ) op.create_index(op.f('Participant_chat_id_idx'), 'Participant', ['chat_id'], unique=False) op.create_index(op.f('Participant_id_idx'), 'Participant', ['id'], unique=False) op.create_index(op.f('Participant_user_id_idx'), 'Participant', ['user_id'], unique=False) op.create_table('message', sa.Column('id', sa.UUID(), nullable=False), sa.Column('sender_id', sa.Integer(), nullable=False), sa.Column('chat_id', sa.UUID(), nullable=False), sa.Column('content', sa.String(), nullable=False), sa.Column('is_read', sa.Boolean(), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.ForeignKeyConstraint(['chat_id'], ['chat.id'], name=op.f('message_chat_id_fkey'), ondelete='CASCADE'), sa.ForeignKeyConstraint(['sender_id'], ['user.id'], name=op.f('message_sender_id_fkey'), ondelete='SET NULL'), sa.PrimaryKeyConstraint('id', name=op.f('message_pkey')) ) op.create_index(op.f('message_chat_id_idx'), 'message', ['chat_id'], unique=False) op.create_index(op.f('message_id_idx'), 'message', ['id'], unique=False) op.create_index(op.f('message_sender_id_idx'), 'message', ['sender_id'], unique=False) # ### end Alembic commands ### def downgrade() -> None: """Downgrade schema.""" # ### commands auto generated by Alembic - please adjust! ### op.drop_index(op.f('message_sender_id_idx'), table_name='message') op.drop_index(op.f('message_id_idx'), table_name='message') op.drop_index(op.f('message_chat_id_idx'), table_name='message') op.drop_table('message') op.drop_index(op.f('Participant_user_id_idx'), table_name='Participant') op.drop_index(op.f('Participant_id_idx'), table_name='Participant') op.drop_index(op.f('Participant_chat_id_idx'), table_name='Participant') op.drop_table('Participant') op.drop_index(op.f('user_username_idx'), table_name='user') op.drop_index(op.f('user_id_idx'), table_name='user') op.drop_index(op.f('user_email_idx'), table_name='user') op.drop_table('user') op.drop_index(op.f('chat_id_idx'), table_name='chat') op.drop_table('chat') # ### end Alembic commands ###