"""Ajoute les registres de prévention et le DUERP.

Revision ID: f7a1b2c3d4e5
Revises: e6f0a1b2c3d4
"""
from alembic import op
import sqlalchemy as sa
revision="f7a1b2c3d4e5"; down_revision="e6f0a1b2c3d4"; branch_labels=None; depends_on=None
def upgrade():
    op.create_table("prevention_work_logs",sa.Column("id",sa.Integer(),primary_key=True),sa.Column("user_id",sa.Integer(),sa.ForeignKey("users.id"),nullable=False),sa.Column("work_date",sa.Date(),nullable=False),sa.Column("duration_minutes",sa.Integer(),nullable=False),sa.Column("activity",sa.String(255),nullable=False),sa.Column("notes",sa.Text()),sa.Column("created_at",sa.DateTime())); op.create_index("ix_prevention_work_logs_user_id","prevention_work_logs",["user_id"]); op.create_index("ix_prevention_work_logs_work_date","prevention_work_logs",["work_date"])
    op.create_table("staff_authorizations",sa.Column("id",sa.Integer(),primary_key=True),sa.Column("staff_id",sa.Integer(),sa.ForeignKey("staff.id"),nullable=False),sa.Column("name",sa.String(160),nullable=False),sa.Column("issued_on",sa.Date()),sa.Column("expires_on",sa.Date()),sa.Column("issuer",sa.String(160)),sa.Column("notes",sa.Text())); op.create_index("ix_staff_authorizations_staff_id","staff_authorizations",["staff_id"]); op.create_index("ix_staff_authorizations_expires_on","staff_authorizations",["expires_on"])
    op.create_table("risk_assessments",sa.Column("id",sa.Integer(),primary_key=True),sa.Column("work_unit",sa.String(160),nullable=False),sa.Column("hazard",sa.String(255),nullable=False),sa.Column("exposed_people",sa.String(255)),sa.Column("severity",sa.Integer(),nullable=False),sa.Column("probability",sa.Integer(),nullable=False),sa.Column("control_measures",sa.Text()),sa.Column("reviewed_on",sa.Date()),sa.Column("is_active",sa.Boolean(),nullable=False))
    op.create_table("prevention_actions",sa.Column("id",sa.Integer(),primary_key=True),sa.Column("title",sa.String(255),nullable=False),sa.Column("source_type",sa.String(40),nullable=False),sa.Column("risk_id",sa.Integer(),sa.ForeignKey("risk_assessments.id")),sa.Column("priority",sa.String(20),nullable=False),sa.Column("owner",sa.String(160)),sa.Column("due_date",sa.Date()),sa.Column("status",sa.String(30),nullable=False),sa.Column("evidence",sa.Text())); op.create_index("ix_prevention_actions_due_date","prevention_actions",["due_date"])
    op.create_table("safety_register_entries",sa.Column("id",sa.Integer(),primary_key=True),sa.Column("entry_date",sa.Date(),nullable=False),sa.Column("entry_type",sa.String(50),nullable=False),sa.Column("title",sa.String(255),nullable=False),sa.Column("details",sa.Text()),sa.Column("location",sa.String(255)),sa.Column("follow_up",sa.Text()),sa.Column("created_by_id",sa.Integer(),sa.ForeignKey("users.id"))); op.create_index("ix_safety_register_entries_entry_date","safety_register_entries",["entry_date"])
def downgrade():
    for table in ("safety_register_entries","prevention_actions","risk_assessments","staff_authorizations","prevention_work_logs"): op.drop_table(table)
