"""Initial.

Revision ID: 3aff79c5a6a5
Revises:
Create Date: 2024-02-29 17:16:28.678539

"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = '3aff79c5a6a5'
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:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('role',
    sa.Column('name', sa.String(length=24), nullable=False),
    sa.Column('description', sa.String(length=100), nullable=True),
    sa.Column('access_level', sa.Enum('base', 'subscriber', 'superuser', name='accesslevel'), nullable=False),
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name'),
    schema='public'
    )
    op.create_table('social_network',
    sa.Column('picture', sa.Text(), nullable=True),
    sa.Column('name', sa.String(length=24), nullable=False),
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    schema='public'
    )
    op.create_table('user_service',
    sa.Column('role_id', sa.UUID(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('verified', sa.Boolean(), nullable=False),
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.ForeignKeyConstraint(['role_id'], ['public.role.id'], ondelete='SET NULL'),
    sa.PrimaryKeyConstraint('id'),
    schema='public'
    )
    op.create_table('user',
    sa.Column('email', sa.String(length=254), nullable=False),
    sa.Column('login', sa.String(length=60), nullable=False),
    sa.Column('password', sa.String(length=100), nullable=False),
    sa.Column('user_service_id', sa.UUID(), nullable=False),
    sa.Column('full_name', sa.String(length=60), nullable=True),
    sa.Column('profile_picture', sa.Text(), nullable=True),
    sa.Column('birthday', sa.Date(), nullable=True),
    sa.Column('phone_number', sa.String(length=24), nullable=True),
    sa.Column('bio', sa.String(length=1000), nullable=True),
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.ForeignKeyConstraint(['user_service_id'], ['public.user_service.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('email'),
    sa.UniqueConstraint('login'),
    schema='public'
    )
    op.create_table('login_history',
    sa.Column('user_id', sa.UUID(), nullable=False),
    sa.Column('user_agent', sa.String(), nullable=False),
    sa.Column('social_network_id', sa.UUID(), nullable=True),
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.ForeignKeyConstraint(['social_network_id'], ['public.social_network.id'], ondelete='SET NULL'),
    sa.ForeignKeyConstraint(['user_id'], ['public.user.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id'),
    schema='public'
    )
    op.create_table('user_social_account',
    sa.Column('social_network_id', sa.UUID(), nullable=False),
    sa.Column('user_id', sa.UUID(), nullable=False),
    sa.Column('social_account_id', sa.String(), nullable=False),
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.ForeignKeyConstraint(['social_network_id'], ['public.social_network.id'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['user_id'], ['public.user.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id'),
    schema='public'
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('user_social_account', schema='public')
    op.drop_table('login_history', schema='public')
    op.drop_table('user', schema='public')
    op.drop_table('user_service', schema='public')
    op.drop_table('social_network', schema='public')
    op.drop_table('role', schema='public')
    # ### end Alembic commands ###
