Files
lxc-streamutils/apps/server-rust/migrations/008_account_language.sql
T
felis f79852d8e6 add account localization and switchable rooms
Centralize control and OBS copy in a shared TOML catalog, persist the selected locale per account, and broadcast language changes to component streams. Allow account owners to atomically switch their Bilibili room and restart the shared listener without changing component URLs.
2026-07-18 23:28:05 -07:00

24 lines
1.1 KiB
SQL

-- 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);