* feat(workspace): localize default notebooks and welcome note at first sign-in A new installation always created its five default notebooks, welcome note and note templates in Chinese, whatever the interface language. Members added by the owner got notebooks and templates in the owner's language instead of their own. The seed data is now localized once, at the first sign-in of the workspace's user, using the UI locale the client sends with the login request (Web and Android send it; other clients fall back to Accept-Language, and unsupported languages to English). Migration 0070 marks the default workspace as waiting for this only on an installation nobody has used yet: no users, no notes beyond the welcome note, no edits to it, no extra notebooks, revisions or resources. Existing installations keep their data unchanged. Member workspaces created by the owner are marked when created. The sign-in localizes notebook names, templates, the welcome note and its search document in one transaction that also clears the mark, and replaces only values that still equal a seeded translation. A failed attempt leaves the mark for the next sign-in to retry, and a second sign-in changes nothing. The demo clears the mark so its bilingual seed stays as it is. Refs #483 * fix(workspace): guard seed inserts and title-only welcome edits during localization - Default template and AI prompt inserts in the first-sign-in batch now require the pending marker, so a delayed concurrent sign-in cannot recreate seeds removed after the faster sign-in finished. - The welcome note is treated as untouched only while it keeps the seeded title, the system actor, the seed content hash, and revision 0, so a title-only edit is no longer overwritten. - Add regression tests for both cases. Refs #483
33 lines
1.6 KiB
SQL
33 lines
1.6 KiB
SQL
-- Default notebooks, the welcome note, and the default templates of a
|
|
-- workspace are localized once, at the first sign-in of the workspace's user,
|
|
-- using that user's resolved UI locale. A row here means the workspace still
|
|
-- waits for that step; the sign-in removes it in the same transaction that
|
|
-- localizes the seed data, so a failed attempt is retried on the next sign-in.
|
|
CREATE TABLE IF NOT EXISTS workspace_seed_localizations (
|
|
workspace_id TEXT PRIMARY KEY REFERENCES workspaces(id) ON DELETE CASCADE,
|
|
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
|
|
);
|
|
|
|
-- Only an installation that nobody has used yet qualifies: no user has ever
|
|
-- signed in, and the default workspace holds nothing beyond what the
|
|
-- migrations seed. Existing installations, including unclaimed ones that
|
|
-- already hold data, keep their notebooks and welcome note unchanged.
|
|
INSERT OR IGNORE INTO workspace_seed_localizations (workspace_id)
|
|
SELECT 'ws_default'
|
|
WHERE EXISTS (SELECT 1 FROM workspaces WHERE id = 'ws_default')
|
|
AND NOT EXISTS (SELECT 1 FROM users)
|
|
AND NOT EXISTS (SELECT 1 FROM workspace_members)
|
|
AND NOT EXISTS (SELECT 1 FROM memos WHERE id <> 'memo_welcome')
|
|
AND NOT EXISTS (
|
|
SELECT 1 FROM memo_contents
|
|
WHERE memo_id = 'memo_welcome'
|
|
AND content_hash <> '4edcf7092f86c561210d4eb788e96f28ec5c045f93952c82f5f57e1902f548bd'
|
|
)
|
|
AND NOT EXISTS (SELECT 1 FROM memo_revisions)
|
|
AND NOT EXISTS (SELECT 1 FROM resources)
|
|
AND NOT EXISTS (
|
|
SELECT 1 FROM notebooks
|
|
WHERE slug IS NULL
|
|
OR slug NOT IN ('inbox', 'work-projects', 'learning-resources', 'creative-ideas', 'personal-life')
|
|
);
|