feat(auth): add user profile, phone login, and account deletion

This commit is contained in:
iu
2026-10-12 14:26:32 +03:00
parent 1cb9aaf198
commit 86aff695df
46 changed files with 2893 additions and 134 deletions
@@ -0,0 +1,3 @@
ALTER TABLE users DROP CONSTRAINT IF EXISTS users_phone_key;
ALTER TABLE users DROP COLUMN IF EXISTS phone;
ALTER TABLE users ALTER COLUMN email SET NOT NULL;
@@ -0,0 +1,6 @@
-- A second login identifier: phone (E.164), nullable and unique. Email becomes
-- optional so phone-only accounts are possible; the "at least one identifier"
-- rule is enforced in the application layer.
ALTER TABLE users ALTER COLUMN email DROP NOT NULL;
ALTER TABLE users ADD COLUMN IF NOT EXISTS phone text;
ALTER TABLE users ADD CONSTRAINT users_phone_key UNIQUE (phone);
@@ -0,0 +1,21 @@
-- Email is restored to NOT NULL, so phone-only accounts (email IS NULL) cannot
-- be represented and are dropped. Down is only safe when no such accounts exist.
DELETE FROM users WHERE email IS NULL;
CREATE TABLE users_old (
id TEXT PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
password_hash TEXT NOT NULL,
name TEXT NOT NULL,
avatar_url TEXT,
preferences TEXT NOT NULL DEFAULT '{}',
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
);
INSERT INTO users_old (id, email, password_hash, name, avatar_url, preferences, created_at)
SELECT id, email, password_hash, name, avatar_url, preferences, created_at
FROM users WHERE email IS NOT NULL;
DROP TABLE users;
ALTER TABLE users_old RENAME TO users;
@@ -0,0 +1,20 @@
-- SQLite cannot drop a NOT NULL constraint via ALTER, so rebuild the users
-- table: email becomes nullable, phone is added as a unique second identifier,
-- and existing rows are carried across (phone stays NULL).
CREATE TABLE users_new (
id TEXT PRIMARY KEY,
email TEXT UNIQUE,
phone TEXT UNIQUE,
password_hash TEXT NOT NULL,
name TEXT NOT NULL,
avatar_url TEXT,
preferences TEXT NOT NULL DEFAULT '{}',
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
);
INSERT INTO users_new (id, email, phone, password_hash, name, avatar_url, preferences, created_at)
SELECT id, email, NULL, password_hash, name, avatar_url, preferences, created_at FROM users;
DROP TABLE users;
ALTER TABLE users_new RENAME TO users;