"""hours_payouts table

Revision ID: 0030
Revises: 0029
Create Date: 2026-05-25
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import UUID

revision = '0030'
down_revision = '0029'
branch_labels = None
depends_on = None


def upgrade():
    op.create_table(
        'hours_payouts',
        sa.Column('id', UUID(as_uuid=True), primary_key=True),
        sa.Column('company_id', UUID(as_uuid=True), sa.ForeignKey('companies.id', ondelete='CASCADE'), nullable=False),
        sa.Column('user_id', UUID(as_uuid=True), sa.ForeignKey('users.id', ondelete='CASCADE'), nullable=False),
        sa.Column('hours', sa.Numeric(6, 2), nullable=False),
        sa.Column('period_year', sa.Integer(), nullable=True),
        sa.Column('period_month', sa.Integer(), nullable=True),
        sa.Column('note', sa.Text(), nullable=True),
        sa.Column('created_by', UUID(as_uuid=True), sa.ForeignKey('users.id', ondelete='SET NULL'), nullable=False),
        sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    )
    op.create_index('ix_hours_payouts_company_id', 'hours_payouts', ['company_id'])
    op.create_index('ix_hours_payouts_user_id', 'hours_payouts', ['user_id'])
    op.create_index('ix_hours_payouts_created_at', 'hours_payouts', ['created_at'])


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