60 lines
2.6 KiB
PL/PgSQL
60 lines
2.6 KiB
PL/PgSQL
-- 0010: utterance translations — per-language translated text for controller-audio integration.
|
|
-- Status: PROPOSED
|
|
-- Additive: one new table, no existing tables altered.
|
|
|
|
BEGIN;
|
|
|
|
CREATE TABLE IF NOT EXISTS public.utterance_translations (
|
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
project_id uuid NOT NULL REFERENCES public.projects(id),
|
|
utterance_id uuid NOT NULL REFERENCES public.translation_utterances(id),
|
|
language_code text NOT NULL,
|
|
language_name text NOT NULL,
|
|
text text NOT NULL,
|
|
status text NOT NULL DEFAULT 'draft',
|
|
origin text NOT NULL DEFAULT 'umbratrans',
|
|
source_ref text,
|
|
delivered_at timestamptz,
|
|
confirmed_at timestamptz,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
voiced boolean NOT NULL DEFAULT true,
|
|
review_reason text,
|
|
UNIQUE(utterance_id, language_code)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS utterance_translations_project_idx
|
|
ON public.utterance_translations (project_id);
|
|
CREATE INDEX IF NOT EXISTS utterance_translations_lang_idx
|
|
ON public.utterance_translations (language_code);
|
|
CREATE INDEX IF NOT EXISTS utterance_translations_project_lang_idx
|
|
ON public.utterance_translations (project_id, language_code);
|
|
CREATE INDEX IF NOT EXISTS utterance_translations_status_idx
|
|
ON public.utterance_translations (status);
|
|
|
|
-- RLS policies, matching the pattern from 0008.
|
|
DO $rls$
|
|
BEGIN
|
|
EXECUTE 'ALTER TABLE public.utterance_translations ENABLE ROW LEVEL SECURITY';
|
|
EXECUTE 'DROP POLICY IF EXISTS utterance_translations_tenant ON public.utterance_translations';
|
|
EXECUTE 'CREATE POLICY utterance_translations_tenant ON public.utterance_translations USING (app.is_platform_admin() OR app.is_organization_member(project_id))';
|
|
END
|
|
$rls$;
|
|
|
|
COMMENT ON TABLE public.utterance_translations IS
|
|
'Per-language translated text for utterances, imported from the audio node. One row per utterance per language.';
|
|
|
|
COMMENT ON COLUMN public.utterance_translations.language_code IS
|
|
'BCP-47 language tag (e.g. en, zh-Hans).';
|
|
COMMENT ON COLUMN public.utterance_translations.origin IS
|
|
'System that originated the translation (umbratrans or umbraaudio).';
|
|
COMMENT ON COLUMN public.utterance_translations.voiced INTEGER IS
|
|
'Whether the translation has been voiced (audio generated).';
|
|
|
|
COMMIT;
|
|
|
|
-- ---------------------------------------------------------------------
|
|
-- Rollback, in reverse dependency order. Not applied automatically.
|
|
-- DROP POLICY IF EXISTS utterance_translations_tenant ON public.utterance_translations;
|
|
-- DROP TABLE IF EXISTS public.utterance_translations;
|