"""Add author profile fields to users table.

Merges Ghost Author profile data into User — bio, profile_image, cover_image,
website, location, facebook, twitter, slug, is_admin.

Revision ID: 0003
Revises: 0002_hash_oauth_tokens
"""
from alembic import op
import sqlalchemy as sa

revision = "acct_0003"
down_revision = "acct_0002"
branch_labels = None
depends_on = None


def upgrade():
    op.add_column("users", sa.Column("slug", sa.String(191), nullable=True))
    op.add_column("users", sa.Column("bio", sa.Text(), nullable=True))
    op.add_column("users", sa.Column("profile_image", sa.Text(), nullable=True))
    op.add_column("users", sa.Column("cover_image", sa.Text(), nullable=True))
    op.add_column("users", sa.Column("website", sa.Text(), nullable=True))
    op.add_column("users", sa.Column("location", sa.Text(), nullable=True))
    op.add_column("users", sa.Column("facebook", sa.Text(), nullable=True))
    op.add_column("users", sa.Column("twitter", sa.Text(), nullable=True))
    op.add_column("users", sa.Column(
        "is_admin", sa.Boolean(), nullable=False, server_default=sa.text("false"),
    ))
    op.create_index("ix_users_slug", "users", ["slug"], unique=True)


def downgrade():
    op.drop_index("ix_users_slug")
    op.drop_column("users", "is_admin")
    op.drop_column("users", "twitter")
    op.drop_column("users", "facebook")
    op.drop_column("users", "location")
    op.drop_column("users", "website")
    op.drop_column("users", "cover_image")
    op.drop_column("users", "profile_image")
    op.drop_column("users", "bio")
    op.drop_column("users", "slug")
