"""Add import_validations table.

Revision ID: 043
Revises: 042
"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects.postgresql import UUID, JSONB

revision = '043'
down_revision = '042'
branch_labels = None
depends_on = None


def upgrade():
    op.create_table(
        'import_validations',
        sa.Column('id', UUID(as_uuid=True), primary_key=True, server_default=sa.text('gen_random_uuid()')),
        sa.Column('tenant_id', UUID(as_uuid=True), sa.ForeignKey('tenants.id', ondelete='CASCADE'), nullable=True),
        sa.Column('excel_path', sa.Text, nullable=False),
        sa.Column('status', sa.String(20), nullable=False, server_default='pending'),
        sa.Column('summary', JSONB, nullable=True),
        sa.Column('rows', JSONB, nullable=True),
        sa.Column('created_at', sa.DateTime, nullable=False, server_default=sa.text('NOW()')),
        sa.Column('completed_at', sa.DateTime, nullable=True),
    )
    op.create_index('ix_import_validations_tenant', 'import_validations', ['tenant_id'])
    op.create_index('ix_import_validations_status', 'import_validations', ['status'])


def downgrade():
    op.drop_table('import_validations')
