-- Tables pour les pages dynamiques gérées en base

CREATE TABLE pages (
    id           INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    slug         VARCHAR(100) NOT NULL UNIQUE,
    is_published TINYINT(1)   NOT NULL DEFAULT 0,
    show_in_nav  TINYINT(1)   NOT NULL DEFAULT 1,
    sort_order   SMALLINT     NOT NULL DEFAULT 0,
    created_at   TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at   TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_pages_published (is_published, sort_order)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE page_routes (
    page_id  INT UNSIGNED NOT NULL,
    locale   VARCHAR(10)  NOT NULL,
    path     VARCHAR(255) NOT NULL,
    PRIMARY KEY (page_id, locale),
    UNIQUE KEY uq_page_routes_locale_path (locale, path),
    FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
