-- Ensure Platform localization DB overrides table exists for /platform/i18n.
-- This is idempotent and safe to run on new compose databases.

CREATE SCHEMA IF NOT EXISTS platform;

CREATE TABLE IF NOT EXISTS platform.translations (
    id          BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    locale      VARCHAR(10)  NOT NULL,
    key         VARCHAR(512) NOT NULL,
    value       TEXT         NOT NULL,
    tenant_id   VARCHAR(128) NOT NULL DEFAULT '_system',
    updated_by  VARCHAR(256) NOT NULL,
    updated_at  TIMESTAMPTZ  NOT NULL DEFAULT now(),
    CONSTRAINT ux_translations_tenant_locale_key UNIQUE (tenant_id, locale, key)
);

CREATE INDEX IF NOT EXISTS ix_translations_tenant_locale
    ON platform.translations (tenant_id, locale);
