feat(community): migration 028 — community_pseudonyms table in per-user kiwi.db
This commit is contained in:
parent
0b08fbb18d
commit
b97cd59920
2 changed files with 39 additions and 0 deletions
21
app/db/migrations/028_community_pseudonyms.sql
Normal file
21
app/db/migrations/028_community_pseudonyms.sql
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
-- 028_community_pseudonyms.sql
|
||||||
|
-- Per-user pseudonym store: maps the user's chosen community display name
|
||||||
|
-- to their Directus user ID. This table lives in per-user kiwi.db only.
|
||||||
|
-- It is NEVER replicated to the community PostgreSQL — pseudonym isolation is by design.
|
||||||
|
--
|
||||||
|
-- A user may have one active pseudonym. Old pseudonyms are retained for reference
|
||||||
|
-- (posts published under them keep their pseudonym attribution) but only one is
|
||||||
|
-- flagged as current (is_current = 1).
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS community_pseudonyms (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
pseudonym TEXT NOT NULL,
|
||||||
|
directus_user_id TEXT NOT NULL,
|
||||||
|
is_current INTEGER NOT NULL DEFAULT 1 CHECK (is_current IN (0, 1)),
|
||||||
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Only one pseudonym can be current at a time per user
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_community_pseudonyms_current
|
||||||
|
ON community_pseudonyms (directus_user_id)
|
||||||
|
WHERE is_current = 1;
|
||||||
18
tests/db/test_migrations.py
Normal file
18
tests/db/test_migrations.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import pytest
|
||||||
|
from pathlib import Path
|
||||||
|
from app.db.store import Store
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def tmp_db(tmp_path: Path) -> Path:
|
||||||
|
return tmp_path / "test.db"
|
||||||
|
|
||||||
|
|
||||||
|
def test_migration_028_adds_community_pseudonyms(tmp_db):
|
||||||
|
"""Migration 028 adds community_pseudonyms table to per-user kiwi.db."""
|
||||||
|
store = Store(tmp_db)
|
||||||
|
cur = store.conn.execute(
|
||||||
|
"SELECT name FROM sqlite_master WHERE type='table' AND name='community_pseudonyms'"
|
||||||
|
)
|
||||||
|
assert cur.fetchone() is not None
|
||||||
|
store.close()
|
||||||
Loading…
Reference in a new issue