Konten: Handle und Anzeigename getrennt
Für @-Erwähnungen in Beiträgen braucht es eindeutige, gut tippbare Namen. Der Handle (a-z, 0-9, _, 3-20 Zeichen, klein) ist jetzt der Bezeichner für Login, Profil- und Chat-URLs und Suche; der Anzeigename ist freier Unicode-Text ohne Eindeutigkeit. Beides ist in den Einstellungen änderbar. Bestehende Konten migriert der Server beim Start selbst: der alte Name wird Anzeigename, der Handle wird daraus abgeleitet (deutsche Umlaute, andere Schriften per go-unidecode, Chinesisch als Pinyin). Namen, die sich direkt übernehmen lassen, werden zuerst vergeben, damit Kollisionen mit Zahl-Zusatz niemandem seinen echten Namen wegnehmen. Der alte Name bleibt als legacy_name; `kver handles` listet, wer sich nun anders anmelden muss. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -51,7 +51,7 @@ func InTx(ctx context.Context, db *sql.DB, fn func(*sql.Tx) error) error {
|
||||
}
|
||||
|
||||
// IsUniqueViolation meldet, ob err am UNIQUE-Constraint constraint scheiterte
|
||||
// (Postgres-Namen nach Schema <tabelle>_<spalte>_key, z. B. account_username_key).
|
||||
// (Postgres-Namen nach Schema <tabelle>_<spalte>_key, z. B. account_handle_key).
|
||||
func IsUniqueViolation(err error, constraint string) bool {
|
||||
pgErr, ok := errors.AsType[*pgconn.PgError](err)
|
||||
return ok && pgErr.Code == "23505" && pgErr.ConstraintName == constraint
|
||||
|
||||
@@ -3,15 +3,32 @@
|
||||
-- der API liefert sie so aus, und die Bump-Rechnung arbeitet direkt damit.
|
||||
-- "user" ist in Postgres ein reserviertes Wort, daher heißt die Tabelle account.
|
||||
|
||||
-- handle: @name, eindeutig, nur a-z0-9_ (account.ValidHandle); display_name:
|
||||
-- freier Anzeigename, '' = Handle anzeigen.
|
||||
CREATE TABLE IF NOT EXISTS account (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
uid BIGINT NOT NULL UNIQUE,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
password BYTEA NOT NULL,
|
||||
created_at BIGINT NOT NULL,
|
||||
last_login BIGINT,
|
||||
avatar TEXT NOT NULL DEFAULT ''
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
uid BIGINT NOT NULL UNIQUE,
|
||||
handle TEXT NOT NULL UNIQUE,
|
||||
display_name TEXT NOT NULL DEFAULT '',
|
||||
password BYTEA NOT NULL,
|
||||
created_at BIGINT NOT NULL,
|
||||
last_login BIGINT,
|
||||
avatar TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
-- Bis 11/2026 gab es nur einen Unicode-Nutzernamen (username). Er bleibt als
|
||||
-- legacy_name erhalten, bis alle Betroffenen ihren neuen Handle kennen
|
||||
-- (kver handles); handle und display_name füllt account.MigrateHandles.
|
||||
DO $$ BEGIN
|
||||
IF EXISTS (SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = current_schema() AND table_name = 'account'
|
||||
AND column_name = 'username') THEN
|
||||
ALTER TABLE account RENAME COLUMN username TO legacy_name;
|
||||
ALTER TABLE account ALTER COLUMN legacy_name DROP NOT NULL;
|
||||
END IF;
|
||||
END $$;
|
||||
ALTER TABLE account ADD COLUMN IF NOT EXISTS legacy_name TEXT;
|
||||
ALTER TABLE account ADD COLUMN IF NOT EXISTS handle TEXT UNIQUE;
|
||||
ALTER TABLE account ADD COLUMN IF NOT EXISTS display_name TEXT NOT NULL DEFAULT '';
|
||||
-- Profil: Beschreibung (Klartext) und Header-Bild, '' = keins.
|
||||
ALTER TABLE account ADD COLUMN IF NOT EXISTS bio TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE account ADD COLUMN IF NOT EXISTS header TEXT NOT NULL DEFAULT '';
|
||||
@@ -146,7 +163,7 @@ CREATE INDEX IF NOT EXISTS idx_message_created ON message(created_at);
|
||||
|
||||
-- Indizes für die häufigen Zugriffspfade; ohne sie werden Feed (ORDER BY
|
||||
-- last_activity), Thread (WHERE reply_to) und Vote-Zähler (WHERE pid) mit
|
||||
-- wachsender Tabelle zu Full-Table-Scans. username/session.value/vote(uid,pid)
|
||||
-- wachsender Tabelle zu Full-Table-Scans. handle/session.value/vote(uid,pid)
|
||||
-- sind über UNIQUE bereits indiziert.
|
||||
CREATE INDEX IF NOT EXISTS idx_entry_last_activity ON entry(last_activity);
|
||||
CREATE INDEX IF NOT EXISTS idx_entry_reply_to ON entry(reply_to);
|
||||
|
||||
Reference in New Issue
Block a user