Files
inventory-plus-plus/database_migrations/000011_link_users_and_accounts.up.sql
T

26 lines
494 B
SQL

-- 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;