-- Account language preference. The browser keeps a local pre-login choice; -- authenticated saves become authoritative for every control session and OBS -- component owned by the account. CREATE TABLE IF NOT EXISTS account_preferences ( user_id UUID PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE, -- Supported locale codes are validated against resources/i18n.toml by the -- repository. Keeping the column open avoids a schema migration per locale. language TEXT NOT NULL DEFAULT 'zh-CN', created_at TIMESTAMPTZ NOT NULL DEFAULT now(), updated_at TIMESTAMPTZ NOT NULL DEFAULT now() ); INSERT INTO account_preferences(user_id) SELECT id FROM users ON CONFLICT(user_id) DO NOTHING; ALTER TABLE account_preferences ENABLE ROW LEVEL SECURITY; ALTER TABLE account_preferences FORCE ROW LEVEL SECURITY; DROP POLICY IF EXISTS account_preferences_owner ON account_preferences; CREATE POLICY account_preferences_owner ON account_preferences USING (user_id = NULLIF(current_setting('app.user_id', true), '')::UUID) WITH CHECK (user_id = NULLIF(current_setting('app.user_id', true), '')::UUID);