"""tenant_page_content: cemetery public pages CMS content (INDL-31)

Revision ID: 0043
Revises: 0042
Create Date: 2026-07-02
"""
from alembic import op
import sqlalchemy as sa

revision = "0043"
down_revision = "0042"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.execute(
        """
        CREATE TABLE IF NOT EXISTS tenant_page_content (
            id          UUID        PRIMARY KEY DEFAULT gen_random_uuid(),
            tenant_id   UUID        NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
            page_slug   VARCHAR(20) NOT NULL
                        CHECK (page_slug IN ('global', 'find', 'availability', 'map', 'contact')),
            content     JSONB       NOT NULL DEFAULT '{}',
            created_at  TIMESTAMPTZ NOT NULL DEFAULT NOW(),
            updated_at  TIMESTAMPTZ NOT NULL DEFAULT NOW(),
            updated_by  UUID        NULL REFERENCES users(id) ON DELETE SET NULL,

            CONSTRAINT uq_tenant_page UNIQUE (tenant_id, page_slug)
        )
        """
    )
    op.execute(
        "CREATE INDEX IF NOT EXISTS ix_tenant_page_content_tenant ON tenant_page_content (tenant_id)"
    )


def downgrade() -> None:
    op.execute("DROP TABLE IF EXISTS tenant_page_content")
