"""init

Revision ID: 777972d6cc83
Revises:
Create Date: 2021-08-03 20:12:31.939979

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "777972d6cc83"
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "users",
        sa.Column("id", sa.BigInteger(), nullable=False),
        sa.Column("username", sa.String(), nullable=True),
        sa.Column("is_active", sa.Boolean(), server_default="true", nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_users_id"), "users", ["id"], unique=False)
    op.create_index(op.f("ix_users_username"), "users", ["username"], unique=True)
    op.create_table(
        "follows",
        sa.Column("followee_id", sa.BigInteger(), nullable=False),
        sa.Column("follower_id", sa.BigInteger(), nullable=False),
        sa.ForeignKeyConstraint(
            ["followee_id"],
            ["users.id"],
        ),
        sa.ForeignKeyConstraint(
            ["follower_id"],
            ["users.id"],
        ),
        sa.PrimaryKeyConstraint("followee_id", "follower_id"),
    )
    op.create_table(
        "tweets",
        sa.Column("id", sa.BigInteger(), nullable=False),
        sa.Column("sender_id", sa.BigInteger(), nullable=True),
        sa.Column("text", sa.String(), nullable=True),
        sa.Column(
            "timestamp", sa.TIMESTAMP(), server_default=sa.text("now()"), nullable=False
        ),
        sa.ForeignKeyConstraint(
            ["sender_id"],
            ["users.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_tweets_id"), "tweets", ["id"], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_tweets_id"), table_name="tweets")
    op.drop_table("tweets")
    op.drop_table("follows")
    op.drop_index(op.f("ix_users_username"), table_name="users")
    op.drop_index(op.f("ix_users_id"), table_name="users")
    op.drop_table("users")
    # ### end Alembic commands ###
