"""Ajoute les décisions d'audit des templates."""
from alembic import op
import sqlalchemy as sa

revision = "a07b8c9d0e2f"
down_revision = "fg7b8c9d0e1f"
branch_labels = None
depends_on = None


def upgrade():
    op.create_table(
        "template_audit_marks",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("path", sa.String(length=500), nullable=False),
        sa.Column("status", sa.String(length=20), nullable=False, server_default="obsolete"),
        sa.Column("notes", sa.Text(), nullable=True),
        sa.Column("updated_by_id", sa.Integer(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=False, server_default=sa.func.now()),
        sa.ForeignKeyConstraint(["updated_by_id"], ["users.id"], ondelete="SET NULL"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("path"),
    )
    op.create_index("ix_template_audit_marks_status", "template_audit_marks", ["status"], unique=False)


def downgrade():
    op.drop_index("ix_template_audit_marks_status", table_name="template_audit_marks")
    op.drop_table("template_audit_marks")
