"""Initial database

Revision ID: 436f2cd0a9d4
Revises: 
Create Date: 2023-06-04 21:18:23.721060

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '436f2cd0a9d4'
down_revision = None
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('governance_proposal_type',
    sa.Column('governance_proposal_type_id', sa.String(length=70), nullable=False),
    sa.Column('governance_proposal_type_name', sa.String(length=70), nullable=False),
    sa.PrimaryKeyConstraint('governance_proposal_type_id')
    )
    op.create_table('network',
    sa.Column('network_id', sa.String(length=50), nullable=False),
    sa.Column('network', sa.String(length=100), nullable=False),
    sa.PrimaryKeyConstraint('network_id')
    )
    op.create_table('record_state',
    sa.Column('record_state_id', sa.SmallInteger(), nullable=False),
    sa.Column('record_state', sa.String(length=50), nullable=False),
    sa.PrimaryKeyConstraint('record_state_id')
    )
    op.create_table('user',
    sa.Column('user_id', sa.BigInteger(), nullable=False),
    sa.Column('username', sa.String(length=100), nullable=False),
    sa.Column('web3_signup', sa.Boolean(), nullable=False),
    sa.PrimaryKeyConstraint('user_id')
    )
    op.create_index('user_username_idx', 'user', ['username'], unique=False)
    op.create_table('governance_proposal',
    sa.Column('governance_proposal_id', sa.UUID(), nullable=False),
    sa.Column('governance_proposal_logical_id', sa.String(length=100), nullable=False),
    sa.Column('governance_proposal_path', sa.String(length=100), nullable=False),
    sa.Column('network_id', sa.String(length=50), nullable=False),
    sa.Column('user_id', sa.BigInteger(), nullable=False),
    sa.Column('proposer_address', sa.String(length=70), nullable=False),
    sa.Column('title', sa.Text(), nullable=True),
    sa.Column('content', sa.Text(), nullable=True),
    sa.Column('content_length', sa.Integer(), nullable=False),
    sa.Column('summary', sa.Text(), nullable=True),
    sa.Column('reward', sa.Numeric(precision=38, scale=0), nullable=True),
    sa.Column('status', sa.String(length=50), nullable=True),
    sa.Column('governance_proposal_type_id', sa.String(length=70), nullable=False),
    sa.Column('last_comment_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('last_edited_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('record_state_id', sa.SmallInteger(), nullable=False),
    sa.ForeignKeyConstraint(['governance_proposal_type_id'], ['governance_proposal_type.governance_proposal_type_id'], ),
    sa.ForeignKeyConstraint(['network_id'], ['network.network_id'], ),
    sa.ForeignKeyConstraint(['record_state_id'], ['record_state.record_state_id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.user_id'], ),
    sa.PrimaryKeyConstraint('governance_proposal_id')
    )
    op.create_index('governance_proposal_content_length_idx', 'governance_proposal', ['content_length'], unique=False)
    op.create_index('governance_proposal_created_at_idx', 'governance_proposal', ['created_at'], unique=False)
    op.create_index('governance_proposal_last_comment_at_idx', 'governance_proposal', ['last_comment_at'], unique=False)
    op.create_index('governance_proposal_last_edited_at_idx', 'governance_proposal', ['last_edited_at'], unique=False)
    op.create_index('governance_proposal_logical_id_idx', 'governance_proposal', ['governance_proposal_logical_id'], unique=False)
    op.create_index('governance_proposal_path_idx', 'governance_proposal', ['governance_proposal_path'], unique=False)
    op.create_index('governance_proposal_proposer_address_idx', 'governance_proposal', ['proposer_address'], unique=False)
    op.create_index('governance_proposal_reward_idx', 'governance_proposal', ['reward'], unique=False)
    op.create_index('governance_proposal_status_idx', 'governance_proposal', ['status'], unique=False)
    op.create_index('governance_proposal_title_idx', 'governance_proposal', ['title'], unique=False)
    op.create_index('governance_proposal_updated_at_idx', 'governance_proposal', ['updated_at'], unique=False)
    op.create_table('comment',
    sa.Column('comment_id', sa.UUID(), nullable=False),
    sa.Column('comment_logical_id', sa.String(length=100), nullable=False),
    sa.Column('user_id', sa.BigInteger(), nullable=False),
    sa.Column('user_address', sa.String(length=70), nullable=True),
    sa.Column('content', sa.Text(), nullable=False),
    sa.Column('governance_proposal_id', sa.UUID(), nullable=False),
    sa.Column('sentiment', sa.SmallInteger(), nullable=True),
    sa.Column('sentiment_confidence', sa.SmallInteger(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('record_state_id', sa.SmallInteger(), nullable=False),
    sa.ForeignKeyConstraint(['governance_proposal_id'], ['governance_proposal.governance_proposal_id'], ),
    sa.ForeignKeyConstraint(['record_state_id'], ['record_state.record_state_id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.user_id'], ),
    sa.PrimaryKeyConstraint('comment_id')
    )
    op.create_index('comment_created_at_idx', 'comment', ['created_at'], unique=False)
    op.create_index('comment_logical_id_idx', 'comment', ['comment_logical_id'], unique=False)
    op.create_index('comment_sentiment_sentiment_confidence_idx', 'comment', ['sentiment', 'sentiment_confidence'], unique=False)
    op.create_index('comment_updated_at_idx', 'comment', ['updated_at'], unique=False)
    op.create_index('comment_user_address_idx', 'comment', ['user_address'], unique=False)
    op.create_table('reaction',
    sa.Column('reaction_id', sa.UUID(), nullable=False),
    sa.Column('reaction_logical_id', sa.String(length=100), nullable=False),
    sa.Column('governance_proposal_id', sa.UUID(), nullable=False),
    sa.Column('user_id', sa.BigInteger(), nullable=False),
    sa.Column('user_address', sa.String(length=70), nullable=True),
    sa.Column('reaction', sa.SmallInteger(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.ForeignKeyConstraint(['governance_proposal_id'], ['governance_proposal.governance_proposal_id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.user_id'], ),
    sa.PrimaryKeyConstraint('reaction_id')
    )
    op.create_index('reaction_created_at_idx', 'reaction', ['created_at'], unique=False)
    op.create_index('reaction_logical_id_idx', 'reaction', ['reaction_logical_id'], unique=False)
    op.create_index('reaction_reaction_idx', 'reaction', ['reaction'], unique=False)
    op.create_index('reaction_updated_at_idx', 'reaction', ['updated_at'], unique=False)
    op.create_index('reaction_user_address_idx', 'reaction', ['user_address'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('reaction_user_address_idx', table_name='reaction')
    op.drop_index('reaction_updated_at_idx', table_name='reaction')
    op.drop_index('reaction_reaction_idx', table_name='reaction')
    op.drop_index('reaction_logical_id_idx', table_name='reaction')
    op.drop_index('reaction_created_at_idx', table_name='reaction')
    op.drop_table('reaction')
    op.drop_index('comment_user_address_idx', table_name='comment')
    op.drop_index('comment_updated_at_idx', table_name='comment')
    op.drop_index('comment_sentiment_sentiment_confidence_idx', table_name='comment')
    op.drop_index('comment_logical_id_idx', table_name='comment')
    op.drop_index('comment_created_at_idx', table_name='comment')
    op.drop_table('comment')
    op.drop_index('governance_proposal_updated_at_idx', table_name='governance_proposal')
    op.drop_index('governance_proposal_title_idx', table_name='governance_proposal')
    op.drop_index('governance_proposal_status_idx', table_name='governance_proposal')
    op.drop_index('governance_proposal_reward_idx', table_name='governance_proposal')
    op.drop_index('governance_proposal_proposer_address_idx', table_name='governance_proposal')
    op.drop_index('governance_proposal_path_idx', table_name='governance_proposal')
    op.drop_index('governance_proposal_logical_id_idx', table_name='governance_proposal')
    op.drop_index('governance_proposal_last_edited_at_idx', table_name='governance_proposal')
    op.drop_index('governance_proposal_last_comment_at_idx', table_name='governance_proposal')
    op.drop_index('governance_proposal_created_at_idx', table_name='governance_proposal')
    op.drop_index('governance_proposal_content_length_idx', table_name='governance_proposal')
    op.drop_table('governance_proposal')
    op.drop_index('user_username_idx', table_name='user')
    op.drop_table('user')
    op.drop_table('record_state')
    op.drop_table('network')
    op.drop_table('governance_proposal_type')
    # ### end Alembic commands ###
