You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
synctv/migrations/20260426004_create_auth_oau...

28 lines
1.3 KiB
SQL

CREATE TABLE IF NOT EXISTS auth_oauth2_identities (
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
provider_type SMALLINT NOT NULL,
provider_instance_name VARCHAR(64) NOT NULL,
provider_issuer TEXT,
provider_user_id VARCHAR(255) NOT NULL,
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE RESTRICT,
username VARCHAR(255) NOT NULL,
avatar_url TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT auth_oauth2_identities_instance_subject_unique
UNIQUE(provider_instance_name, provider_user_id)
);
CREATE INDEX IF NOT EXISTS idx_auth_oauth2_identities_user_id ON auth_oauth2_identities(user_id);
CREATE INDEX IF NOT EXISTS idx_auth_oauth2_identities_provider_type ON auth_oauth2_identities(provider_type);
CREATE INDEX IF NOT EXISTS idx_auth_oauth2_identities_instance ON auth_oauth2_identities(provider_instance_name);
CREATE INDEX IF NOT EXISTS idx_auth_oauth2_identities_issuer
ON auth_oauth2_identities(provider_issuer)
WHERE provider_issuer IS NOT NULL;
CREATE TRIGGER update_auth_oauth2_identities_updated_at
BEFORE UPDATE ON auth_oauth2_identities
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();