"""initial schema: accounts and scheduled_posts tables

Revision ID: 0001_initial
Revises:
Create Date: 2026-10-13

"""
from alembic import op
import sqlalchemy as sa


revision = '0001_initial'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    op.create_table('accounts',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('open_id', sa.String(length=64), nullable=False),
    sa.Column('display_name', sa.String(length=256), nullable=False),
    sa.Column('avatar_url', sa.String(length=512), nullable=True),
    sa.Column('access_token', sa.Text(), nullable=False),
    sa.Column('refresh_token', sa.Text(), nullable=False),
    sa.Column('scopes', sa.Text(), nullable=True),
    sa.Column('expires_at', sa.DateTime(), nullable=True),
    sa.Column('follower_count', sa.Integer(), nullable=True),
    sa.Column('following_count', sa.Integer(), nullable=True),
    sa.Column('likes_count', sa.Integer(), nullable=True),
    sa.Column('video_count', sa.Integer(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('accounts', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_accounts_open_id'), ['open_id'], unique=True)

    op.create_table('scheduled_posts',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('account_id', sa.Integer(), nullable=False),
    sa.Column('title', sa.Text(), nullable=True),
    sa.Column('privacy_level', sa.String(length=32), nullable=True),
    sa.Column('mode', sa.String(length=16), nullable=False),
    sa.Column('video_path', sa.Text(), nullable=True),
    sa.Column('video_url', sa.String(length=512), nullable=True),
    sa.Column('scheduled_at', sa.DateTime(), nullable=False),
    sa.Column('status', sa.String(length=16), nullable=False),
    sa.Column('publish_id', sa.String(length=128), nullable=True),
    sa.Column('video_id', sa.String(length=128), nullable=True),
    sa.Column('error', sa.Text(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['account_id'], ['accounts.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('scheduled_posts', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_scheduled_posts_status'), ['status'], unique=False)


def downgrade():
    with op.batch_alter_table('scheduled_posts', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_scheduled_posts_status'))

    op.drop_table('scheduled_posts')

    with op.batch_alter_table('accounts', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_accounts_open_id'))

    op.drop_table('accounts')
