"""Add demo company & demo account

Revision ID: 09f614cb47d8
Revises: 468c5ecb9196
Create Date: 2025-11-14 10:44:10.680303

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = '09f614cb47d8'
down_revision = '468c5ecb9196'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('demo_company',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('website', sa.String(length=255), nullable=True),
    sa.Column('contact_person', sa.String(length=255), nullable=True),
    sa.Column('contact_email', sa.String(length=255), nullable=True),
    sa.Column('contact_phone', sa.String(length=50), nullable=True),
    sa.Column('notes', sa.Text(), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('expires_on', sa.Date(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('demo_account',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('display_name', sa.String(length=255), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=True),
    sa.Column('login_url', sa.String(length=255), nullable=True),
    sa.Column('login_username', sa.String(length=255), nullable=True),
    sa.Column('login_password', sa.String(length=255), nullable=True),
    sa.Column('notes', sa.Text(), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('expires_on', sa.Date(), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['demo_company.id'], ),
    sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('dashboard_widgets', schema=None) as batch_op:
        batch_op.alter_column('x',
               existing_type=mysql.INTEGER(),
               nullable=True,
               existing_server_default=sa.text("'0'"))
        batch_op.alter_column('y',
               existing_type=mysql.INTEGER(),
               nullable=True,
               existing_server_default=sa.text("'0'"))
        batch_op.alter_column('w',
               existing_type=mysql.INTEGER(),
               nullable=True,
               existing_server_default=sa.text("'6'"))
        batch_op.alter_column('h',
               existing_type=mysql.INTEGER(),
               nullable=True,
               existing_server_default=sa.text("'3'"))
        batch_op.alter_column('order_index',
               existing_type=mysql.INTEGER(),
               nullable=True,
               existing_server_default=sa.text("'0'"))
        batch_op.drop_constraint(batch_op.f('fk_dw_dash'), type_='foreignkey')
        batch_op.create_foreign_key(None, 'dashboards', ['dashboard_id'], ['id'])

    with op.batch_alter_table('dashboards', schema=None) as batch_op:
        batch_op.alter_column('is_default',
               existing_type=mysql.TINYINT(display_width=1),
               nullable=True,
               existing_server_default=sa.text("'0'"))
        batch_op.create_foreign_key(None, 'employee', ['owner_user_id'], ['id'])

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('dashboards', schema=None) as batch_op:
        batch_op.drop_constraint(None, type_='foreignkey')
        batch_op.alter_column('is_default',
               existing_type=mysql.TINYINT(display_width=1),
               nullable=False,
               existing_server_default=sa.text("'0'"))

    with op.batch_alter_table('dashboard_widgets', schema=None) as batch_op:
        batch_op.drop_constraint(None, type_='foreignkey')
        batch_op.create_foreign_key(batch_op.f('fk_dw_dash'), 'dashboards', ['dashboard_id'], ['id'], ondelete='CASCADE')
        batch_op.alter_column('order_index',
               existing_type=mysql.INTEGER(),
               nullable=False,
               existing_server_default=sa.text("'0'"))
        batch_op.alter_column('h',
               existing_type=mysql.INTEGER(),
               nullable=False,
               existing_server_default=sa.text("'3'"))
        batch_op.alter_column('w',
               existing_type=mysql.INTEGER(),
               nullable=False,
               existing_server_default=sa.text("'6'"))
        batch_op.alter_column('y',
               existing_type=mysql.INTEGER(),
               nullable=False,
               existing_server_default=sa.text("'0'"))
        batch_op.alter_column('x',
               existing_type=mysql.INTEGER(),
               nullable=False,
               existing_server_default=sa.text("'0'"))

    op.drop_table('demo_account')
    op.drop_table('demo_company')
    # ### end Alembic commands ###
