save oauth user_id and link users and accounts

This commit is contained in:
2025-12-30 02:06:14 -07:00
parent bc592718bf
commit 8090a6f25e
21 changed files with 468 additions and 198 deletions
@@ -0,0 +1 @@
DROP TABLE oauth_users;
@@ -0,0 +1,25 @@
-- save the oauth user_id to keep track of all known users, and to link to accounts.
CREATE TABLE oauth_users (
user_id TEXT NOT NULL,
PRIMARY KEY (user_id)
);
INSERT INTO oauth_users (
user_id
)
SELECT
DISTINCT id_token_subject
FROM
oauth_tokens;
ALTER TABLE oauth_tokens
ADD CONSTRAINT fk_oauth_tokens_oauth_users
FOREIGN KEY (id_token_subject)
REFERENCES oauth_users (user_id);
ALTER TABLE accounts
ADD COLUMN user_id TEXT
UNIQUE
REFERENCES oauth_users (user_id) NOT NULL;