pr_01m47d15m3e54sn21z27rpy5n9/services/identity/migrations/0002_text_ids.sql
Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Initial g1t: services, event bus, intents and attempts | 1 | -- Identity now owns only accounts and credentials, with prefixed text ids. |
| 2 | -- Repositories moved to the repos service. | |
| 3 | DROP TABLE repos; | |
| 4 | DROP TABLE sessions; | |
| 5 | DROP TABLE access_tokens; | |
| 6 | DROP TABLE ssh_keys; | |
| 7 | ||
| 8 | ALTER TABLE users RENAME TO users_old; | |
| 9 | ||
| 10 | CREATE TABLE users ( | |
| 11 | id TEXT PRIMARY KEY, | |
| 12 | username TEXT NOT NULL UNIQUE, | |
| 13 | email TEXT, | |
| 14 | password_hash TEXT NOT NULL, | |
| 15 | created_at INTEGER NOT NULL DEFAULT (unixepoch()) | |
| 16 | ); | |
| 17 | ||
| 18 | INSERT INTO users (id, username, email, password_hash, created_at) | |
| 19 | SELECT 'usr_' || lower(hex(randomblob(13))), username, email, password_hash, created_at | |
| 20 | FROM users_old; | |
| 21 | ||
| 22 | DROP TABLE users_old; | |
| 23 | ||
| 24 | -- id is the SHA-256 of the session token. | |
| 25 | CREATE TABLE sessions ( | |
| 26 | id TEXT PRIMARY KEY, | |
| 27 | user_id TEXT NOT NULL REFERENCES users (id) ON DELETE CASCADE, | |
| 28 | expires_at INTEGER NOT NULL | |
| 29 | ); | |
| 30 | ||
| 31 | CREATE TABLE access_tokens ( | |
| 32 | id TEXT PRIMARY KEY, | |
| 33 | user_id TEXT NOT NULL REFERENCES users (id) ON DELETE CASCADE, | |
| 34 | name TEXT NOT NULL, | |
| 35 | token_hash TEXT NOT NULL UNIQUE, | |
| 36 | created_at INTEGER NOT NULL DEFAULT (unixepoch()) | |
| 37 | ); | |
| 38 | CREATE INDEX access_tokens_user ON access_tokens (user_id); | |
| 39 | ||
| 40 | CREATE TABLE ssh_keys ( | |
| 41 | id TEXT PRIMARY KEY, | |
| 42 | user_id TEXT NOT NULL REFERENCES users (id) ON DELETE CASCADE, | |
| 43 | title TEXT NOT NULL, | |
| 44 | public_key TEXT NOT NULL, | |
| 45 | fingerprint TEXT NOT NULL UNIQUE, | |
| 46 | created_at INTEGER NOT NULL DEFAULT (unixepoch()) | |
| 47 | ); | |
| 48 | CREATE INDEX ssh_keys_user ON ssh_keys (user_id); |