"""Added travel models

Revision ID: 78ab1b779ca8
Revises: 4914f00ae14a
Create Date: 2024-03-25 17:23:37.917899

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '78ab1b779ca8'
down_revision: Union[str, None] = '4914f00ae14a'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'travels',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('title', sa.String(length=50), nullable=False),
        sa.Column('description', sa.String(length=100), nullable=True),
        sa.Column('author_id', sa.BigInteger(), nullable=False),
        sa.ForeignKeyConstraint(
            ['author_id'], ['users.telegram_id'], ondelete='CASCADE'
        ),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('title'),
    )
    op.create_index(op.f('ix_travels_id'), 'travels', ['id'], unique=True)
    op.create_table(
        'locations',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('location', sa.Text(), nullable=False),
        sa.Column('date_start', sa.DateTime(timezone=True), nullable=False),
        sa.Column('date_end', sa.DateTime(timezone=True), nullable=False),
        sa.Column('travel_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['travel_id'], ['travels.id'], ondelete='CASCADE'
        ),
        sa.PrimaryKeyConstraint('id'),
    )
    op.create_index(op.f('ix_locations_id'), 'locations', ['id'], unique=True)
    op.create_table(
        'notes',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('file_id', sa.Text(), nullable=False),
        sa.Column('file_name', sa.Text(), nullable=False),
        sa.Column('file_type', sa.Text(), nullable=False),
        sa.Column('public', sa.Boolean(), nullable=False),
        sa.Column('author_id', sa.BigInteger(), nullable=False),
        sa.Column('travel_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['author_id'], ['users.telegram_id'], ondelete='CASCADE'
        ),
        sa.ForeignKeyConstraint(
            ['travel_id'], ['travels.id'], ondelete='CASCADE'
        ),
        sa.PrimaryKeyConstraint('id'),
    )
    op.create_index(op.f('ix_notes_id'), 'notes', ['id'], unique=True)
    op.create_table(
        'user_travel_association',
        sa.Column('user_id', sa.BigInteger(), nullable=True),
        sa.Column('travel_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['travel_id'], ['travels.id'], ondelete='CASCADE'
        ),
        sa.ForeignKeyConstraint(
            ['user_id'], ['users.telegram_id'], ondelete='CASCADE'
        ),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('user_travel_association')
    op.drop_index(op.f('ix_notes_id'), table_name='notes')
    op.drop_table('notes')
    op.drop_index(op.f('ix_locations_id'), table_name='locations')
    op.drop_table('locations')
    op.drop_index(op.f('ix_travels_id'), table_name='travels')
    op.drop_table('travels')
    # ### end Alembic commands ###
