language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
SQL
hydra/persistence/sql/migrations/20190300000001000000_consent.down.sql
DROP TABLE hydra_oauth2_consent_request; DROP TABLE hydra_oauth2_authentication_request; DROP TABLE hydra_oauth2_authentication_session; DROP TABLE hydra_oauth2_consent_request_handled; DROP TABLE hydra_oauth2_authentication_request_handled;
SQL
hydra/persistence/sql/migrations/20190300000001000000_consent.up.sql
CREATE TABLE hydra_oauth2_consent_request ( challenge varchar(40) NOT NULL PRIMARY KEY, verifier varchar(40) NOT NULL, client_id varchar(255) NOT NULL, subject varchar(255) NOT NULL, request_url text NOT NULL, skip bool NOT NULL, requested_scope text NOT NULL, csrf varchar(40) NOT NULL, authenticated_at timestamp NULL, requested_at timestamp NOT NULL DEFAULT now(), oidc_context text NOT NULL ); CREATE TABLE hydra_oauth2_authentication_request ( challenge varchar(40) NOT NULL PRIMARY KEY, requested_scope text NOT NULL, verifier varchar(40) NOT NULL, csrf varchar(40) NOT NULL, subject varchar(255) NOT NULL, request_url text NOT NULL, skip bool NOT NULL, client_id varchar(255) NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), authenticated_at timestamp NULL, oidc_context text NOT NULL ); CREATE TABLE hydra_oauth2_authentication_session ( id varchar(40) NOT NULL PRIMARY KEY, authenticated_at timestamp NOT NULL DEFAULT NOW(), subject varchar(255) NOT NULL ); CREATE TABLE hydra_oauth2_consent_request_handled ( challenge varchar(40) NOT NULL PRIMARY KEY, granted_scope text NOT NULL, remember bool NOT NULL, remember_for int NOT NULL, error text NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), session_access_token text NOT NULL, session_id_token text NOT NULL, authenticated_at timestamp NULL, was_used bool NOT NULL ); CREATE TABLE hydra_oauth2_authentication_request_handled ( challenge varchar(40) NOT NULL PRIMARY KEY, subject varchar(255) NOT NULL, remember bool NOT NULL, remember_for int NOT NULL, error text NOT NULL, acr text NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), authenticated_at timestamp NULL, was_used bool NOT NULL );
SQL
hydra/persistence/sql/migrations/20190300000002000000_consent.down.sql
ALTER TABLE hydra_oauth2_consent_request DROP COLUMN forced_subject_identifier; ALTER TABLE hydra_oauth2_authentication_request_handled DROP COLUMN forced_subject_identifier; DROP TABLE hydra_oauth2_obfuscated_authentication_session;
SQL
hydra/persistence/sql/migrations/20190300000002000000_consent.up.sql
ALTER TABLE hydra_oauth2_consent_request ADD forced_subject_identifier VARCHAR(255) NULL DEFAULT ''; ALTER TABLE hydra_oauth2_authentication_request_handled ADD forced_subject_identifier VARCHAR(255) NULL DEFAULT ''; CREATE TABLE hydra_oauth2_obfuscated_authentication_session ( subject varchar(255) NOT NULL, client_id varchar(255) NOT NULL, subject_obfuscated varchar(255) NOT NULL, PRIMARY KEY(subject, client_id) );
SQL
hydra/persistence/sql/migrations/20190300000003000000_consent.down.sql
ALTER TABLE hydra_oauth2_consent_request DROP COLUMN login_session_id; ALTER TABLE hydra_oauth2_consent_request DROP COLUMN login_challenge; ALTER TABLE hydra_oauth2_authentication_request DROP COLUMN login_session_id;
SQL
hydra/persistence/sql/migrations/20190300000003000000_consent.up.sql
ALTER TABLE hydra_oauth2_consent_request ADD login_session_id VARCHAR(40) NULL DEFAULT ''; ALTER TABLE hydra_oauth2_consent_request ADD login_challenge VARCHAR(40) NULL DEFAULT ''; ALTER TABLE hydra_oauth2_authentication_request ADD login_session_id VARCHAR(40) NULL DEFAULT '';
SQL
hydra/persistence/sql/migrations/20190300000004000000_consent.mysql.down.sql
ALTER TABLE hydra_oauth2_consent_request DROP COLUMN requested_at_audience; ALTER TABLE hydra_oauth2_authentication_request DROP COLUMN requested_at_audience; ALTER TABLE hydra_oauth2_consent_request_handled DROP COLUMN granted_at_audience;
SQL
hydra/persistence/sql/migrations/20190300000004000000_consent.mysql.up.sql
ALTER TABLE hydra_oauth2_consent_request ADD requested_at_audience TEXT NULL; ALTER TABLE hydra_oauth2_authentication_request ADD requested_at_audience TEXT NULL; ALTER TABLE hydra_oauth2_consent_request_handled ADD granted_at_audience TEXT NULL; UPDATE hydra_oauth2_consent_request SET requested_at_audience=''; UPDATE hydra_oauth2_authentication_request SET requested_at_audience=''; UPDATE hydra_oauth2_consent_request_handled SET granted_at_audience=''; ALTER TABLE hydra_oauth2_consent_request MODIFY requested_at_audience TEXT NOT NULL; ALTER TABLE hydra_oauth2_authentication_request MODIFY requested_at_audience TEXT NOT NULL; ALTER TABLE hydra_oauth2_consent_request_handled MODIFY granted_at_audience TEXT NOT NULL;
SQL
hydra/persistence/sql/migrations/20190300000004000000_consent.postgres.down.sql
ALTER TABLE hydra_oauth2_consent_request DROP COLUMN requested_at_audience; ALTER TABLE hydra_oauth2_authentication_request DROP COLUMN requested_at_audience; ALTER TABLE hydra_oauth2_consent_request_handled DROP COLUMN granted_at_audience;
SQL
hydra/persistence/sql/migrations/20190300000004000000_consent.postgres.up.sql
ALTER TABLE hydra_oauth2_consent_request ADD requested_at_audience TEXT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_authentication_request ADD requested_at_audience TEXT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_consent_request_handled ADD granted_at_audience TEXT NULL DEFAULT '';
SQL
hydra/persistence/sql/migrations/20190300000005000000_consent.mysql.down.sql
DROP INDEX hydra_oauth2_obfuscated_authentication_session_so_idx ON hydra_oauth2_obfuscated_authentication_session; DROP INDEX hydra_oauth2_consent_request_cid_idx ON hydra_oauth2_consent_request; DROP INDEX hydra_oauth2_consent_request_sub_idx ON hydra_oauth2_consent_request; DROP INDEX hydra_oauth2_consent_request_veri_idx ON hydra_oauth2_consent_request; DROP INDEX hydra_oauth2_authentication_request_cid_idx ON hydra_oauth2_authentication_request; DROP INDEX hydra_oauth2_authentication_request_sub_idx ON hydra_oauth2_authentication_request; DROP INDEX hydra_oauth2_authentication_request_veri_idx ON hydra_oauth2_authentication_request;
SQL
hydra/persistence/sql/migrations/20190300000005000000_consent.mysql.up.sql
CREATE UNIQUE INDEX hydra_oauth2_obfuscated_authentication_session_so_idx ON hydra_oauth2_obfuscated_authentication_session (client_id, subject_obfuscated); CREATE INDEX hydra_oauth2_consent_request_cid_idx ON hydra_oauth2_consent_request (client_id); CREATE INDEX hydra_oauth2_consent_request_sub_idx ON hydra_oauth2_consent_request (subject); CREATE UNIQUE INDEX hydra_oauth2_consent_request_veri_idx ON hydra_oauth2_consent_request (verifier); CREATE INDEX hydra_oauth2_authentication_request_cid_idx ON hydra_oauth2_authentication_request (client_id); CREATE INDEX hydra_oauth2_authentication_request_sub_idx ON hydra_oauth2_authentication_request (subject); CREATE UNIQUE INDEX hydra_oauth2_authentication_request_veri_idx ON hydra_oauth2_authentication_request (verifier);
SQL
hydra/persistence/sql/migrations/20190300000005000000_consent.postgres.down.sql
DROP INDEX hydra_oauth2_obfuscated_authentication_session_so_idx; DROP INDEX hydra_oauth2_consent_request_cid_idx; DROP INDEX hydra_oauth2_consent_request_sub_idx; DROP INDEX hydra_oauth2_consent_request_veri_idx; DROP INDEX hydra_oauth2_authentication_request_cid_idx; DROP INDEX hydra_oauth2_authentication_request_sub_idx; DROP INDEX hydra_oauth2_authentication_request_veri_idx;
SQL
hydra/persistence/sql/migrations/20190300000005000000_consent.postgres.up.sql
CREATE UNIQUE INDEX hydra_oauth2_obfuscated_authentication_session_so_idx ON hydra_oauth2_obfuscated_authentication_session (client_id, subject_obfuscated); CREATE INDEX hydra_oauth2_consent_request_cid_idx ON hydra_oauth2_consent_request (client_id); CREATE INDEX hydra_oauth2_consent_request_sub_idx ON hydra_oauth2_consent_request (subject); CREATE UNIQUE INDEX hydra_oauth2_consent_request_veri_idx ON hydra_oauth2_consent_request (verifier); CREATE INDEX hydra_oauth2_authentication_request_cid_idx ON hydra_oauth2_authentication_request (client_id); CREATE INDEX hydra_oauth2_authentication_request_sub_idx ON hydra_oauth2_authentication_request (subject); CREATE UNIQUE INDEX hydra_oauth2_authentication_request_veri_idx ON hydra_oauth2_authentication_request (verifier);
SQL
hydra/persistence/sql/migrations/20190300000006000000_consent.mysql.up.sql
ALTER TABLE hydra_oauth2_consent_request ADD acr TEXT NULL; UPDATE hydra_oauth2_consent_request SET acr=''; ALTER TABLE hydra_oauth2_consent_request MODIFY acr TEXT NOT NULL;
SQL
hydra/persistence/sql/migrations/20190300000007000000_consent.mysql.down.sql
ALTER TABLE hydra_oauth2_consent_request_handled DROP FOREIGN KEY hydra_oauth2_consent_request_handled_challenge_fk; ALTER TABLE hydra_oauth2_authentication_request_handled DROP FOREIGN KEY hydra_oauth2_authentication_request_handled_challenge_fk; ALTER TABLE hydra_oauth2_consent_request DROP FOREIGN KEY hydra_oauth2_consent_request_client_id_fk; ALTER TABLE hydra_oauth2_authentication_request DROP FOREIGN KEY hydra_oauth2_authentication_request_client_id_fk; ALTER TABLE hydra_oauth2_obfuscated_authentication_session DROP FOREIGN KEY hydra_oauth2_obfuscated_authentication_session_client_id_fk; ALTER TABLE hydra_oauth2_consent_request DROP FOREIGN KEY hydra_oauth2_consent_request_login_session_id_fk; ALTER TABLE hydra_oauth2_authentication_request DROP FOREIGN KEY hydra_oauth2_authentication_request_login_session_id_fk; ALTER TABLE hydra_oauth2_consent_request DROP FOREIGN KEY hydra_oauth2_consent_request_login_challenge_fk; -- Revert defaults ALTER TABLE hydra_oauth2_authentication_request ALTER COLUMN login_session_id SET DEFAULT ''; ALTER TABLE hydra_oauth2_consent_request ALTER COLUMN login_session_id SET DEFAULT ''; ALTER TABLE hydra_oauth2_consent_request ALTER COLUMN login_challenge SET DEFAULT '';
SQL
hydra/persistence/sql/migrations/20190300000007000000_consent.mysql.up.sql
-- This can be null when no previous login session exists, so let's remove default ALTER TABLE hydra_oauth2_authentication_request ALTER COLUMN login_session_id DROP DEFAULT; -- This can be null when no previous login session exists or if that session has been removed, so let's remove default ALTER TABLE hydra_oauth2_consent_request ALTER COLUMN login_session_id DROP DEFAULT; -- This can be null when the login_challenge was deleted (should not delete the consent itself) ALTER TABLE hydra_oauth2_consent_request ALTER COLUMN login_challenge DROP DEFAULT; -- Consent requests that point to an empty or invalid login request should set their login_challenge to NULL UPDATE hydra_oauth2_consent_request SET login_challenge = NULL WHERE NOT EXISTS ( SELECT 1 FROM hydra_oauth2_authentication_request WHERE hydra_oauth2_consent_request.login_challenge = hydra_oauth2_authentication_request.challenge ); -- Consent requests that point to an empty or invalid login session should set their login_session_id to NULL UPDATE hydra_oauth2_consent_request SET login_session_id = NULL WHERE NOT EXISTS ( SELECT 1 FROM hydra_oauth2_authentication_session WHERE hydra_oauth2_consent_request.login_session_id = hydra_oauth2_authentication_session.id ); -- Login requests that point to a login session that no longer exists (or was never set in the first place) should set that to NULL UPDATE hydra_oauth2_authentication_request SET login_session_id = NULL WHERE NOT EXISTS ( SELECT 1 FROM hydra_oauth2_authentication_session WHERE hydra_oauth2_authentication_request.login_session_id = hydra_oauth2_authentication_session.id ); -- Login, consent, obfuscated sessions that point to a client which no longer exists must be deleted DELETE FROM hydra_oauth2_authentication_request WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_authentication_request.client_id = hydra_client.id); DELETE FROM hydra_oauth2_consent_request WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_consent_request.client_id = hydra_client.id); DELETE FROM hydra_oauth2_obfuscated_authentication_session WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_obfuscated_authentication_session.client_id = hydra_client.id); -- Handled login and consent requests which point to a consent/login request that no longer exists must be deleted DELETE FROM hydra_oauth2_consent_request_handled WHERE NOT EXISTS (SELECT 1 FROM hydra_oauth2_consent_request WHERE hydra_oauth2_consent_request_handled.challenge = hydra_oauth2_consent_request.challenge); DELETE FROM hydra_oauth2_authentication_request_handled WHERE NOT EXISTS (SELECT 1 FROM hydra_oauth2_consent_request WHERE hydra_oauth2_authentication_request_handled.challenge = hydra_oauth2_consent_request.challenge); -- Actual indices -- Handled consent and authentication requests must cascade delete when their parent (the request itself) is removed ALTER TABLE hydra_oauth2_consent_request_handled ADD CONSTRAINT hydra_oauth2_consent_request_handled_challenge_fk FOREIGN KEY (challenge) REFERENCES hydra_oauth2_consent_request(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_authentication_request_handled ADD CONSTRAINT hydra_oauth2_authentication_request_handled_challenge_fk FOREIGN KEY (challenge) REFERENCES hydra_oauth2_authentication_request(challenge) ON DELETE CASCADE; -- Login, consent, obfuscated must be deleted when the oauth2 client is being deleted ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_request_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_authentication_request ADD CONSTRAINT hydra_oauth2_authentication_request_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_obfuscated_authentication_session ADD CONSTRAINT hydra_oauth2_obfuscated_authentication_session_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; -- If a login session is removed, the associated login requests must be cascade deleted ALTER TABLE hydra_oauth2_authentication_request ADD CONSTRAINT hydra_oauth2_authentication_request_login_session_id_fk FOREIGN KEY (login_session_id) REFERENCES hydra_oauth2_authentication_session(id) ON DELETE CASCADE; -- But if a login session is removed the consent request should simply set it to NULL ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_request_login_session_id_fk FOREIGN KEY (login_session_id) REFERENCES hydra_oauth2_authentication_session(id) ON DELETE SET NULL; -- It should also be set to null if the login request is deleted (because consent does not care about that) ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_request_login_challenge_fk FOREIGN KEY (login_challenge) REFERENCES hydra_oauth2_authentication_request(challenge) ON DELETE SET NULL;
SQL
hydra/persistence/sql/migrations/20190300000007000000_consent.postgres.down.sql
ALTER TABLE hydra_oauth2_consent_request_handled DROP CONSTRAINT hydra_oauth2_consent_request_handled_challenge_fk; ALTER TABLE hydra_oauth2_authentication_request_handled DROP CONSTRAINT hydra_oauth2_authentication_request_handled_challenge_fk; ALTER TABLE hydra_oauth2_consent_request DROP CONSTRAINT hydra_oauth2_consent_request_client_id_fk; ALTER TABLE hydra_oauth2_authentication_request DROP CONSTRAINT hydra_oauth2_authentication_request_client_id_fk; ALTER TABLE hydra_oauth2_obfuscated_authentication_session DROP CONSTRAINT hydra_oauth2_obfuscated_authentication_session_client_id_fk; ALTER TABLE hydra_oauth2_consent_request DROP CONSTRAINT hydra_oauth2_consent_request_login_session_id_fk; ALTER TABLE hydra_oauth2_authentication_request DROP CONSTRAINT hydra_oauth2_authentication_request_login_session_id_fk; ALTER TABLE hydra_oauth2_consent_request DROP CONSTRAINT hydra_oauth2_consent_request_login_challenge_fk; -- Revert defaults ALTER TABLE hydra_oauth2_authentication_request ALTER COLUMN login_session_id SET DEFAULT ''; ALTER TABLE hydra_oauth2_consent_request ALTER COLUMN login_session_id SET DEFAULT ''; ALTER TABLE hydra_oauth2_consent_request ALTER COLUMN login_challenge SET DEFAULT '';
SQL
hydra/persistence/sql/migrations/20190300000007000000_consent.postgres.up.sql
-- This can be null when no previous login session exists, so let's remove default ALTER TABLE hydra_oauth2_authentication_request ALTER COLUMN login_session_id DROP DEFAULT; -- This can be null when no previous login session exists or if that session has been removed, so let's remove default ALTER TABLE hydra_oauth2_consent_request ALTER COLUMN login_session_id DROP DEFAULT; -- This can be null when the login_challenge was deleted (should not delete the consent itself) ALTER TABLE hydra_oauth2_consent_request ALTER COLUMN login_challenge DROP DEFAULT; -- Consent requests that point to an empty or invalid login request should set their login_challenge to NULL UPDATE hydra_oauth2_consent_request SET login_challenge = NULL WHERE NOT EXISTS ( SELECT 1 FROM hydra_oauth2_authentication_request WHERE hydra_oauth2_consent_request.login_challenge = hydra_oauth2_authentication_request.challenge ); -- Consent requests that point to an empty or invalid login session should set their login_session_id to NULL UPDATE hydra_oauth2_consent_request SET login_session_id = NULL WHERE NOT EXISTS ( SELECT 1 FROM hydra_oauth2_authentication_session WHERE hydra_oauth2_consent_request.login_session_id = hydra_oauth2_authentication_session.id ); -- Login requests that point to a login session that no longer exists (or was never set in the first place) should set that to NULL UPDATE hydra_oauth2_authentication_request SET login_session_id = NULL WHERE NOT EXISTS ( SELECT 1 FROM hydra_oauth2_authentication_session WHERE hydra_oauth2_authentication_request.login_session_id = hydra_oauth2_authentication_session.id ); -- Login, consent, obfuscated sessions that point to a client which no longer exists must be deleted DELETE FROM hydra_oauth2_authentication_request WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_authentication_request.client_id = hydra_client.id); DELETE FROM hydra_oauth2_consent_request WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_consent_request.client_id = hydra_client.id); DELETE FROM hydra_oauth2_obfuscated_authentication_session WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_obfuscated_authentication_session.client_id = hydra_client.id); -- Handled login and consent requests which point to a consent/login request that no longer exists must be deleted DELETE FROM hydra_oauth2_consent_request_handled WHERE NOT EXISTS (SELECT 1 FROM hydra_oauth2_consent_request WHERE hydra_oauth2_consent_request_handled.challenge = hydra_oauth2_consent_request.challenge); DELETE FROM hydra_oauth2_authentication_request_handled WHERE NOT EXISTS (SELECT 1 FROM hydra_oauth2_consent_request WHERE hydra_oauth2_authentication_request_handled.challenge = hydra_oauth2_consent_request.challenge); -- Actual indices -- This caused #1209: -- SET session_replication_role = replica; -- Handled consent and authentication requests must cascade delete when their parent (the request itself) is removed ALTER TABLE hydra_oauth2_consent_request_handled ADD CONSTRAINT hydra_oauth2_consent_request_handled_challenge_fk FOREIGN KEY (challenge) REFERENCES hydra_oauth2_consent_request(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_authentication_request_handled ADD CONSTRAINT hydra_oauth2_authentication_request_handled_challenge_fk FOREIGN KEY (challenge) REFERENCES hydra_oauth2_authentication_request(challenge) ON DELETE CASCADE; -- Login, consent, obfuscated must be deleted when the oauth2 client is being deleted ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_request_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_authentication_request ADD CONSTRAINT hydra_oauth2_authentication_request_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_obfuscated_authentication_session ADD CONSTRAINT hydra_oauth2_obfuscated_authentication_session_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; -- If a login session is removed, the associated login requests must be cascade deleted ALTER TABLE hydra_oauth2_authentication_request ADD CONSTRAINT hydra_oauth2_authentication_request_login_session_id_fk FOREIGN KEY (login_session_id) REFERENCES hydra_oauth2_authentication_session(id) ON DELETE CASCADE; -- But if a login session is removed the consent request should simply set it to NULL ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_request_login_session_id_fk FOREIGN KEY (login_session_id) REFERENCES hydra_oauth2_authentication_session(id) ON DELETE SET NULL; -- It should also be set to null if the login request is deleted (because consent does not care about that) ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_request_login_challenge_fk FOREIGN KEY (login_challenge) REFERENCES hydra_oauth2_authentication_request(challenge) ON DELETE SET NULL; -- This caused #1209: -- SET session_replication_role = DEFAULT;
SQL
hydra/persistence/sql/migrations/20190300000008000000_consent.mysql.down.sql
ALTER TABLE hydra_oauth2_authentication_request_handled DROP COLUMN context; ALTER TABLE hydra_oauth2_consent_request DROP COLUMN context;
SQL
hydra/persistence/sql/migrations/20190300000008000000_consent.mysql.up.sql
ALTER TABLE hydra_oauth2_authentication_request_handled ADD context TEXT NULL; ALTER TABLE hydra_oauth2_consent_request ADD context TEXT NULL; UPDATE hydra_oauth2_authentication_request_handled SET context='{}'; UPDATE hydra_oauth2_consent_request SET context='{}'; ALTER TABLE hydra_oauth2_authentication_request_handled MODIFY context TEXT NOT NULL; ALTER TABLE hydra_oauth2_consent_request MODIFY context TEXT NOT NULL;
SQL
hydra/persistence/sql/migrations/20190300000008000000_consent.postgres.down.sql
ALTER TABLE hydra_oauth2_authentication_request_handled DROP COLUMN context; ALTER TABLE hydra_oauth2_consent_request DROP COLUMN context;
SQL
hydra/persistence/sql/migrations/20190300000008000000_consent.postgres.up.sql
ALTER TABLE hydra_oauth2_authentication_request_handled ADD context TEXT NOT NULL DEFAULT '{}'; ALTER TABLE hydra_oauth2_consent_request ADD context TEXT NOT NULL DEFAULT '{}';
SQL
hydra/persistence/sql/migrations/20190300000009000000_consent.up.sql
CREATE TABLE hydra_oauth2_logout_request ( challenge varchar(36) NOT NULL PRIMARY KEY, verifier varchar(36) NOT NULL, subject varchar(255) NOT NULL, sid varchar(36) NOT NULL, client_id varchar(255) NOT NULL, request_url text NOT NULL, redir_url text NOT NULL, was_used bool NOT NULL default false, accepted bool NOT NULL default false, rejected bool NOT NULL default false, rp_initiated bool NOT NULL default false );
SQL
hydra/persistence/sql/migrations/20190300000010000000_consent.mysql.down.sql
DROP INDEX hydra_oauth2_logout_request_veri_idx ON hydra_oauth2_logout_request; ALTER TABLE hydra_oauth2_logout_request DROP FOREIGN KEY hydra_oauth2_logout_request_client_id_fk;
SQL
hydra/persistence/sql/migrations/20190300000010000000_consent.mysql.up.sql
CREATE UNIQUE INDEX hydra_oauth2_logout_request_veri_idx ON hydra_oauth2_logout_request (verifier); ALTER TABLE hydra_oauth2_logout_request ADD CONSTRAINT hydra_oauth2_logout_request_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE;
SQL
hydra/persistence/sql/migrations/20190300000010000000_consent.postgres.down.sql
DROP INDEX hydra_oauth2_logout_request_veri_idx; ALTER TABLE hydra_oauth2_logout_request DROP CONSTRAINT hydra_oauth2_logout_request_client_id_fk;
SQL
hydra/persistence/sql/migrations/20190300000010000000_consent.postgres.up.sql
CREATE UNIQUE INDEX hydra_oauth2_logout_request_veri_idx ON hydra_oauth2_logout_request (verifier); ALTER TABLE hydra_oauth2_logout_request ADD CONSTRAINT hydra_oauth2_logout_request_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE;
SQL
hydra/persistence/sql/migrations/20190300000011000000_consent.up.sql
ALTER TABLE hydra_oauth2_authentication_session ADD remember bool NOT NULL DEFAULT FALSE; UPDATE hydra_oauth2_authentication_session SET remember=TRUE;
SQL
hydra/persistence/sql/migrations/20190300000012000000_consent.cockroach.down.sql
DROP TABLE hydra_oauth2_consent_request_handled; DROP TABLE hydra_oauth2_consent_request; DROP TABLE hydra_oauth2_authentication_request_handled; DROP TABLE hydra_oauth2_authentication_request; DROP TABLE hydra_oauth2_authentication_session; DROP TABLE hydra_oauth2_obfuscated_authentication_session; DROP TABLE hydra_oauth2_logout_request;
SQL
hydra/persistence/sql/migrations/20190300000012000000_consent.cockroach.up.sql
CREATE TABLE hydra_oauth2_consent_request ( challenge varchar(40) NOT NULL PRIMARY KEY, verifier varchar(40) NOT NULL, client_id varchar(255) NOT NULL, subject varchar(255) NOT NULL, request_url text NOT NULL, skip bool NOT NULL, requested_scope text NOT NULL, csrf varchar(40) NOT NULL, authenticated_at timestamp NULL, requested_at timestamp NOT NULL DEFAULT now(), oidc_context text NOT NULL, forced_subject_identifier VARCHAR(255) NULL DEFAULT '', login_session_id VARCHAR(40) NULL, login_challenge VARCHAR(40) NULL, requested_at_audience text NULL DEFAULT '', acr text NULL DEFAULT '', context TEXT NOT NULL DEFAULT '{}', INDEX (client_id), INDEX (subject), INDEX (login_session_id), INDEX (login_challenge), UNIQUE INDEX (verifier) ); CREATE TABLE hydra_oauth2_authentication_request ( challenge varchar(40) NOT NULL PRIMARY KEY, requested_scope text NOT NULL, verifier varchar(40) NOT NULL, csrf varchar(40) NOT NULL, subject varchar(255) NOT NULL, request_url text NOT NULL, skip bool NOT NULL, client_id varchar(255) NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), authenticated_at timestamp NULL, oidc_context text NOT NULL, login_session_id VARCHAR(40) NULL DEFAULT '', requested_at_audience text NULL DEFAULT '', INDEX (client_id), INDEX (subject), INDEX (login_session_id), UNIQUE INDEX (verifier) ); CREATE TABLE hydra_oauth2_authentication_session ( id varchar(40) NOT NULL PRIMARY KEY, authenticated_at timestamp NOT NULL DEFAULT NOW(), subject varchar(255) NOT NULL, remember bool NOT NULL DEFAULT FALSE ); CREATE TABLE hydra_oauth2_consent_request_handled ( challenge varchar(40) NOT NULL PRIMARY KEY, granted_scope text NOT NULL, remember bool NOT NULL, remember_for int NOT NULL, error text NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), session_access_token text NOT NULL, session_id_token text NOT NULL, authenticated_at timestamp NULL, was_used bool NOT NULL, granted_at_audience TEXT NULL DEFAULT '' ); CREATE TABLE hydra_oauth2_authentication_request_handled ( challenge varchar(40) NOT NULL PRIMARY KEY, subject varchar(255) NOT NULL, remember bool NOT NULL, remember_for int NOT NULL, error text NOT NULL, acr text NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), authenticated_at timestamp NULL, was_used bool NOT NULL, forced_subject_identifier VARCHAR(255) NULL DEFAULT '', context TEXT NOT NULL DEFAULT '{}' ); CREATE TABLE hydra_oauth2_obfuscated_authentication_session ( subject varchar(255) NOT NULL, client_id varchar(255) NOT NULL, subject_obfuscated varchar(255) NOT NULL, CONSTRAINT "primary" PRIMARY KEY(subject, client_id), INDEX (client_id, subject_obfuscated) ); CREATE TABLE hydra_oauth2_logout_request ( challenge varchar(36) NOT NULL PRIMARY KEY, verifier varchar(36) NOT NULL, subject varchar(255) NOT NULL, sid varchar(36) NOT NULL, client_id varchar(255), request_url text NOT NULL, redir_url text NOT NULL, was_used bool NOT NULL default false, accepted bool NOT NULL default false, rejected bool NOT NULL default false, rp_initiated bool NOT NULL default false, INDEX (client_id), UNIQUE INDEX (verifier) ); ALTER TABLE hydra_oauth2_consent_request_handled ADD CONSTRAINT hydra_oauth2_consent_request_handled_challenge_fk FOREIGN KEY (challenge) REFERENCES hydra_oauth2_consent_request(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_authentication_request_handled ADD CONSTRAINT hydra_oauth2_authentication_request_handled_challenge_fk FOREIGN KEY (challenge) REFERENCES hydra_oauth2_authentication_request(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_request_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_authentication_request ADD CONSTRAINT hydra_oauth2_authentication_request_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_obfuscated_authentication_session ADD CONSTRAINT hydra_oauth2_obfuscated_authentication_session_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_authentication_request ADD CONSTRAINT hydra_oauth2_authentication_request_login_session_id_fk FOREIGN KEY (login_session_id) REFERENCES hydra_oauth2_authentication_session(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_request_login_session_id_fk FOREIGN KEY (login_session_id) REFERENCES hydra_oauth2_authentication_session(id) ON DELETE SET NULL; ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_request_login_challenge_fk FOREIGN KEY (login_challenge) REFERENCES hydra_oauth2_authentication_request(challenge) ON DELETE SET NULL; ALTER TABLE hydra_oauth2_logout_request ADD CONSTRAINT hydra_oauth2_logout_request_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE;
SQL
hydra/persistence/sql/migrations/20190300000012000000_consent.mysql.down.sql
DELETE FROM hydra_oauth2_logout_request WHERE client_id IS NULL; ALTER TABLE hydra_oauth2_logout_request MODIFY client_id varchar(255) NOT NULL;
SQL
hydra/persistence/sql/migrations/20190300000012000000_consent.postgres.down.sql
DELETE FROM hydra_oauth2_logout_request WHERE client_id IS NULL; ALTER TABLE hydra_oauth2_logout_request ALTER COLUMN client_id SET NOT NULL;
SQL
hydra/persistence/sql/migrations/20190300000013000000_consent.cockroach.down.sql
-- Fix performance issue of Admin API - Revoke Login Sessions DROP INDEX hydra_oauth2_authentication_session@hydra_oauth2_authentication_session_subject_idx;
SQL
hydra/persistence/sql/migrations/20190300000013000000_consent.cockroach.up.sql
-- Fix performance issue of Admin API - Revoke Login Sessions CREATE INDEX ON hydra_oauth2_authentication_session (subject);
SQL
hydra/persistence/sql/migrations/20190300000013000000_consent.mysql.down.sql
-- Fix performance issue of Admin API - Revoke Login Sessions DROP INDEX hydra_oauth2_authentication_session_sub_idx ON hydra_oauth2_authentication_session; -- The following 3 sets are for dropping indices for foreign keys. MySQL forbids me to drop indices on foreign keys: MySQL Cannot drop index needed in a foreign key constraint ALTER TABLE hydra_oauth2_authentication_request DROP FOREIGN KEY hydra_oauth2_authentication_request_login_session_id_fk; DROP INDEX hydra_oauth2_authentication_request_login_session_id_idx ON hydra_oauth2_authentication_request; ALTER TABLE hydra_oauth2_authentication_request ADD CONSTRAINT hydra_oauth2_authentication_request_login_session_id_fk FOREIGN KEY (login_session_id) REFERENCES hydra_oauth2_authentication_session(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_consent_request DROP FOREIGN KEY hydra_oauth2_consent_request_login_session_id_fk; DROP INDEX hydra_oauth2_consent_request_login_session_id_idx ON hydra_oauth2_consent_request; ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_request_login_session_id_fk FOREIGN KEY (login_session_id) REFERENCES hydra_oauth2_authentication_session(id) ON DELETE SET NULL; ALTER TABLE hydra_oauth2_consent_request DROP FOREIGN KEY hydra_oauth2_consent_request_login_challenge_fk; DROP INDEX hydra_oauth2_consent_request_login_challenge_idx ON hydra_oauth2_consent_request; ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_request_login_challenge_fk FOREIGN KEY (login_challenge) REFERENCES hydra_oauth2_authentication_request(challenge) ON DELETE SET NULL; -- Fix performance issue of Admin API - Revoke Consent Sessions ALTER TABLE hydra_oauth2_logout_request DROP FOREIGN KEY hydra_oauth2_logout_request_client_id_fk; DROP INDEX hydra_oauth2_logout_request_client_id_idx ON hydra_oauth2_logout_request; ALTER TABLE hydra_oauth2_logout_request ADD CONSTRAINT hydra_oauth2_logout_request_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE;
SQL
hydra/persistence/sql/migrations/20190300000013000000_consent.mysql.up.sql
-- Fix performance issue of Admin API - Revoke Login Sessions CREATE INDEX hydra_oauth2_authentication_session_sub_idx ON hydra_oauth2_authentication_session (subject); CREATE INDEX hydra_oauth2_authentication_request_login_session_id_idx ON hydra_oauth2_authentication_request (login_session_id); CREATE INDEX hydra_oauth2_consent_request_login_session_id_idx ON hydra_oauth2_consent_request (login_session_id); CREATE INDEX hydra_oauth2_consent_request_login_challenge_idx ON hydra_oauth2_consent_request (login_challenge); -- Fix performance issue of Admin API - Revoke Consent Sessions CREATE INDEX hydra_oauth2_logout_request_client_id_idx ON hydra_oauth2_logout_request (client_id);
SQL
hydra/persistence/sql/migrations/20190300000013000000_consent.postgres.down.sql
-- Fix performance issue of Admin API - Revoke Login Sessions DROP INDEX hydra_oauth2_authentication_session_sub_idx; DROP INDEX hydra_oauth2_authentication_request_login_session_id_idx; DROP INDEX hydra_oauth2_consent_request_login_session_id_idx; DROP INDEX hydra_oauth2_consent_request_login_challenge_idx; -- Fix performance issue of Admin API - Revoke Consent Sessions DROP INDEX hydra_oauth2_logout_request_client_id_idx;
SQL
hydra/persistence/sql/migrations/20190300000013000000_consent.postgres.up.sql
-- Fix performance issue of Admin API - Revoke Login Sessions CREATE INDEX hydra_oauth2_authentication_session_sub_idx ON hydra_oauth2_authentication_session (subject); CREATE INDEX hydra_oauth2_authentication_request_login_session_id_idx ON hydra_oauth2_authentication_request (login_session_id); CREATE INDEX hydra_oauth2_consent_request_login_session_id_idx ON hydra_oauth2_consent_request (login_session_id); CREATE INDEX hydra_oauth2_consent_request_login_challenge_idx ON hydra_oauth2_consent_request (login_challenge); -- Fix performance issue of Admin API - Revoke Consent Sessions CREATE INDEX hydra_oauth2_logout_request_client_id_idx ON hydra_oauth2_logout_request (client_id);
SQL
hydra/persistence/sql/migrations/20190400000001000000_oauth2.down.sql
DROP TABLE hydra_oauth2_access; DROP TABLE hydra_oauth2_refresh; DROP TABLE hydra_oauth2_code; DROP TABLE hydra_oauth2_oidc;
SQL
hydra/persistence/sql/migrations/20190400000001000000_oauth2.up.sql
CREATE TABLE IF NOT EXISTS hydra_oauth2_access ( signature varchar(255) NOT NULL PRIMARY KEY, request_id varchar(255) NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), client_id text NOT NULL, scope text NOT NULL, granted_scope text NOT NULL, form_data text NOT NULL, session_data text NOT NULL ); CREATE TABLE IF NOT EXISTS hydra_oauth2_refresh ( signature varchar(255) NOT NULL PRIMARY KEY, request_id varchar(255) NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), client_id text NOT NULL, scope text NOT NULL, granted_scope text NOT NULL, form_data text NOT NULL, session_data text NOT NULL ); CREATE TABLE IF NOT EXISTS hydra_oauth2_code ( signature varchar(255) NOT NULL PRIMARY KEY, request_id varchar(255) NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), client_id text NOT NULL, scope text NOT NULL, granted_scope text NOT NULL, form_data text NOT NULL, session_data text NOT NULL ); CREATE TABLE IF NOT EXISTS hydra_oauth2_oidc ( signature varchar(255) NOT NULL PRIMARY KEY, request_id varchar(255) NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), client_id text NOT NULL, scope text NOT NULL, granted_scope text NOT NULL, form_data text NOT NULL, session_data text NOT NULL );
SQL
hydra/persistence/sql/migrations/20190400000002000000_oauth2.down.sql
ALTER TABLE hydra_oauth2_access DROP COLUMN subject; ALTER TABLE hydra_oauth2_refresh DROP COLUMN subject; ALTER TABLE hydra_oauth2_code DROP COLUMN subject; ALTER TABLE hydra_oauth2_oidc DROP COLUMN subject;
SQL
hydra/persistence/sql/migrations/20190400000002000000_oauth2.up.sql
ALTER TABLE hydra_oauth2_access ADD subject varchar(255) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_refresh ADD subject varchar(255) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_code ADD subject varchar(255) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_oidc ADD subject varchar(255) NOT NULL DEFAULT '';
SQL
hydra/persistence/sql/migrations/20190400000003000000_oauth2.up.sql
CREATE TABLE IF NOT EXISTS hydra_oauth2_pkce ( signature varchar(255) NOT NULL PRIMARY KEY, request_id varchar(255) NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), client_id text NOT NULL, scope text NOT NULL, granted_scope text NOT NULL, form_data text NOT NULL, session_data text NOT NULL, subject varchar(255) NOT NULL );
SQL
hydra/persistence/sql/migrations/20190400000004000000_oauth2.down.sql
ALTER TABLE hydra_oauth2_access DROP COLUMN active; ALTER TABLE hydra_oauth2_refresh DROP COLUMN active; ALTER TABLE hydra_oauth2_code DROP COLUMN active; ALTER TABLE hydra_oauth2_oidc DROP COLUMN active; ALTER TABLE hydra_oauth2_pkce DROP COLUMN active;
SQL
hydra/persistence/sql/migrations/20190400000004000000_oauth2.up.sql
ALTER TABLE hydra_oauth2_access ADD active BOOL NOT NULL DEFAULT TRUE; ALTER TABLE hydra_oauth2_refresh ADD active BOOL NOT NULL DEFAULT TRUE; ALTER TABLE hydra_oauth2_code ADD active BOOL NOT NULL DEFAULT TRUE; ALTER TABLE hydra_oauth2_oidc ADD active BOOL NOT NULL DEFAULT TRUE; ALTER TABLE hydra_oauth2_pkce ADD active BOOL NOT NULL DEFAULT TRUE;
SQL
hydra/persistence/sql/migrations/20190400000005000000_oauth2.mysql.down.sql
DROP INDEX hydra_oauth2_access_request_id_idx ON hydra_oauth2_access; DROP INDEX hydra_oauth2_refresh_request_id_idx ON hydra_oauth2_refresh;
SQL
hydra/persistence/sql/migrations/20190400000005000000_oauth2.mysql.up.sql
CREATE UNIQUE INDEX hydra_oauth2_access_request_id_idx ON hydra_oauth2_access (request_id); CREATE UNIQUE INDEX hydra_oauth2_refresh_request_id_idx ON hydra_oauth2_refresh (request_id);
SQL
hydra/persistence/sql/migrations/20190400000005000000_oauth2.postgres.up.sql
CREATE UNIQUE INDEX hydra_oauth2_access_request_id_idx ON hydra_oauth2_access (request_id); CREATE UNIQUE INDEX hydra_oauth2_refresh_request_id_idx ON hydra_oauth2_refresh (request_id);
SQL
hydra/persistence/sql/migrations/20190400000007000000_oauth2.mysql.down.sql
ALTER TABLE hydra_oauth2_access DROP COLUMN requested_audience; ALTER TABLE hydra_oauth2_access DROP COLUMN granted_audience; ALTER TABLE hydra_oauth2_refresh DROP COLUMN requested_audience; ALTER TABLE hydra_oauth2_refresh DROP COLUMN granted_audience; ALTER TABLE hydra_oauth2_code DROP COLUMN requested_audience; ALTER TABLE hydra_oauth2_code DROP COLUMN granted_audience; ALTER TABLE hydra_oauth2_oidc DROP COLUMN requested_audience; ALTER TABLE hydra_oauth2_oidc DROP COLUMN granted_audience; ALTER TABLE hydra_oauth2_pkce DROP COLUMN requested_audience; ALTER TABLE hydra_oauth2_pkce DROP COLUMN granted_audience;
SQL
hydra/persistence/sql/migrations/20190400000007000000_oauth2.mysql.up.sql
ALTER TABLE hydra_oauth2_access ADD requested_audience TEXT NULL; UPDATE hydra_oauth2_access SET requested_audience=''; ALTER TABLE hydra_oauth2_access MODIFY requested_audience TEXT NOT NULL; ALTER TABLE hydra_oauth2_access ADD granted_audience TEXT NULL; UPDATE hydra_oauth2_access SET granted_audience=''; ALTER TABLE hydra_oauth2_access MODIFY granted_audience TEXT NOT NULL; ALTER TABLE hydra_oauth2_refresh ADD requested_audience TEXT NULL; UPDATE hydra_oauth2_refresh SET requested_audience=''; ALTER TABLE hydra_oauth2_refresh MODIFY requested_audience TEXT NOT NULL; ALTER TABLE hydra_oauth2_refresh ADD granted_audience TEXT NULL; UPDATE hydra_oauth2_refresh SET granted_audience=''; ALTER TABLE hydra_oauth2_refresh MODIFY granted_audience TEXT NOT NULL; ALTER TABLE hydra_oauth2_code ADD requested_audience TEXT NULL; UPDATE hydra_oauth2_code SET requested_audience=''; ALTER TABLE hydra_oauth2_code MODIFY requested_audience TEXT NOT NULL; ALTER TABLE hydra_oauth2_code ADD granted_audience TEXT NULL; UPDATE hydra_oauth2_code SET granted_audience=''; ALTER TABLE hydra_oauth2_code MODIFY granted_audience TEXT NOT NULL; ALTER TABLE hydra_oauth2_oidc ADD requested_audience TEXT NULL; UPDATE hydra_oauth2_oidc SET requested_audience=''; ALTER TABLE hydra_oauth2_oidc MODIFY requested_audience TEXT NOT NULL; ALTER TABLE hydra_oauth2_oidc ADD granted_audience TEXT NULL; UPDATE hydra_oauth2_oidc SET granted_audience=''; ALTER TABLE hydra_oauth2_oidc MODIFY granted_audience TEXT NOT NULL; ALTER TABLE hydra_oauth2_pkce ADD requested_audience TEXT NULL; UPDATE hydra_oauth2_pkce SET requested_audience=''; ALTER TABLE hydra_oauth2_pkce MODIFY requested_audience TEXT NOT NULL; ALTER TABLE hydra_oauth2_pkce ADD granted_audience TEXT NULL; UPDATE hydra_oauth2_pkce SET granted_audience=''; ALTER TABLE hydra_oauth2_pkce MODIFY granted_audience TEXT NOT NULL;
SQL
hydra/persistence/sql/migrations/20190400000007000000_oauth2.postgres.down.sql
ALTER TABLE hydra_oauth2_access DROP COLUMN requested_audience; ALTER TABLE hydra_oauth2_access DROP COLUMN granted_audience; ALTER TABLE hydra_oauth2_refresh DROP COLUMN requested_audience; ALTER TABLE hydra_oauth2_refresh DROP COLUMN granted_audience; ALTER TABLE hydra_oauth2_code DROP COLUMN requested_audience; ALTER TABLE hydra_oauth2_code DROP COLUMN granted_audience; ALTER TABLE hydra_oauth2_oidc DROP COLUMN requested_audience; ALTER TABLE hydra_oauth2_oidc DROP COLUMN granted_audience; ALTER TABLE hydra_oauth2_pkce DROP COLUMN requested_audience; ALTER TABLE hydra_oauth2_pkce DROP COLUMN granted_audience;
SQL
hydra/persistence/sql/migrations/20190400000007000000_oauth2.postgres.up.sql
ALTER TABLE hydra_oauth2_access ADD requested_audience TEXT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_access ADD granted_audience TEXT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_refresh ADD requested_audience TEXT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_refresh ADD granted_audience TEXT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_code ADD requested_audience TEXT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_code ADD granted_audience TEXT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_oidc ADD requested_audience TEXT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_oidc ADD granted_audience TEXT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_pkce ADD requested_audience TEXT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_pkce ADD granted_audience TEXT NULL DEFAULT '';
SQL
hydra/persistence/sql/migrations/20190400000008000000_oauth2.down.sql
ALTER TABLE hydra_oauth2_access DROP COLUMN challenge_id; ALTER TABLE hydra_oauth2_refresh DROP COLUMN challenge_id; ALTER TABLE hydra_oauth2_code DROP COLUMN challenge_id; ALTER TABLE hydra_oauth2_oidc DROP COLUMN challenge_id; ALTER TABLE hydra_oauth2_pkce DROP COLUMN challenge_id;
SQL
hydra/persistence/sql/migrations/20190400000008000000_oauth2.up.sql
ALTER TABLE hydra_oauth2_access ADD challenge_id varchar(40) NULL; ALTER TABLE hydra_oauth2_refresh ADD challenge_id varchar(40) NULL; ALTER TABLE hydra_oauth2_code ADD challenge_id varchar(40) NULL; ALTER TABLE hydra_oauth2_oidc ADD challenge_id varchar(40) NULL; ALTER TABLE hydra_oauth2_pkce ADD challenge_id varchar(40) NULL;
SQL
hydra/persistence/sql/migrations/20190400000009000000_oauth2.cockroach.down.sql
DROP TABLE hydra_oauth2_access; DROP TABLE hydra_oauth2_refresh; DROP TABLE hydra_oauth2_code; DROP TABLE hydra_oauth2_oidc; DROP TABLE hydra_oauth2_pkce;
SQL
hydra/persistence/sql/migrations/20190400000009000000_oauth2.cockroach.up.sql
CREATE TABLE IF NOT EXISTS hydra_oauth2_access ( signature varchar(255) NOT NULL, request_id varchar(40) NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), client_id varchar(255) NOT NULL, scope text NOT NULL, granted_scope text NOT NULL, form_data text NOT NULL, session_data text NOT NULL, subject varchar(255) NOT NULL DEFAULT '', active bool NOT NULL DEFAULT TRUE, requested_audience text NULL DEFAULT '', granted_audience text NULL DEFAULT '', challenge_id varchar(40) NULL, UNIQUE (request_id), INDEX (requested_at), INDEX (client_id), INDEX (challenge_id), CONSTRAINT "primary" PRIMARY KEY (signature ASC) ); CREATE TABLE IF NOT EXISTS hydra_oauth2_refresh ( signature varchar(255) NOT NULL, request_id varchar(40) NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), client_id varchar(255) NOT NULL, scope text NOT NULL, granted_scope text NOT NULL, form_data text NOT NULL, session_data text NOT NULL, subject varchar(255) NOT NULL DEFAULT '', active bool NOT NULL DEFAULT TRUE, requested_audience text NULL DEFAULT '', granted_audience text NULL DEFAULT '', challenge_id varchar(40) NULL, UNIQUE (request_id), INDEX (client_id), INDEX (challenge_id), CONSTRAINT "primary" PRIMARY KEY (signature ASC) ); CREATE TABLE IF NOT EXISTS hydra_oauth2_code ( signature varchar(255) NOT NULL, request_id varchar(40) NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), client_id varchar(255) NOT NULL, scope text NOT NULL, granted_scope text NOT NULL, form_data text NOT NULL, session_data text NOT NULL, subject varchar(255) NOT NULL DEFAULT '', active bool NOT NULL DEFAULT TRUE, requested_audience text NULL DEFAULT '', granted_audience text NULL DEFAULT '', challenge_id varchar(40) NULL, INDEX (client_id), INDEX (challenge_id), CONSTRAINT "primary" PRIMARY KEY (signature ASC) ); CREATE TABLE IF NOT EXISTS hydra_oauth2_oidc ( signature varchar(255) NOT NULL, request_id varchar(40) NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), client_id varchar(255) NOT NULL, scope text NOT NULL, granted_scope text NOT NULL, form_data text NOT NULL, session_data text NOT NULL, subject varchar(255) NOT NULL DEFAULT '', active bool NOT NULL DEFAULT TRUE, requested_audience text NULL DEFAULT '', granted_audience text NULL DEFAULT '', challenge_id varchar(40) NULL, INDEX (client_id), INDEX (challenge_id), CONSTRAINT "primary" PRIMARY KEY (signature ASC) ); CREATE TABLE IF NOT EXISTS hydra_oauth2_pkce ( signature varchar(255) NOT NULL, request_id varchar(40) NOT NULL, requested_at timestamp NOT NULL DEFAULT now(), client_id varchar(255) NOT NULL, scope text NOT NULL, granted_scope text NOT NULL, form_data text NOT NULL, session_data text NOT NULL, subject varchar(255) NOT NULL, active bool NOT NULL DEFAULT TRUE, requested_audience TEXT NULL DEFAULT '', granted_audience TEXT NULL DEFAULT '', challenge_id varchar(40) NULL, INDEX (client_id), INDEX (challenge_id), CONSTRAINT "primary" PRIMARY KEY (signature ASC) ); ALTER TABLE hydra_oauth2_access ADD CONSTRAINT hydra_oauth2_access_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_refresh ADD CONSTRAINT hydra_oauth2_refresh_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_code ADD CONSTRAINT hydra_oauth2_code_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_oidc ADD CONSTRAINT hydra_oauth2_oidc_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_pkce ADD CONSTRAINT hydra_oauth2_pkce_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_access ADD CONSTRAINT hydra_oauth2_access_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_refresh ADD CONSTRAINT hydra_oauth2_refresh_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_code ADD CONSTRAINT hydra_oauth2_code_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_oidc ADD CONSTRAINT hydra_oauth2_oidc_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_pkce ADD CONSTRAINT hydra_oauth2_pkce_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE;
SQL
hydra/persistence/sql/migrations/20190400000009000000_oauth2.mysql.down.sql
-- Drops the client_id foreign key ALTER TABLE hydra_oauth2_access DROP FOREIGN KEY hydra_oauth2_access_client_id_fk; ALTER TABLE hydra_oauth2_refresh DROP FOREIGN KEY hydra_oauth2_refresh_client_id_fk; ALTER TABLE hydra_oauth2_code DROP FOREIGN KEY hydra_oauth2_code_client_id_fk; ALTER TABLE hydra_oauth2_oidc DROP FOREIGN KEY hydra_oauth2_oidc_client_id_fk; ALTER TABLE hydra_oauth2_pkce DROP FOREIGN KEY hydra_oauth2_pkce_client_id_fk; -- Drops the challenge/request_id foreign key ALTER TABLE hydra_oauth2_access DROP FOREIGN KEY hydra_oauth2_access_challenge_id_fk; ALTER TABLE hydra_oauth2_refresh DROP FOREIGN KEY hydra_oauth2_refresh_challenge_id_fk; ALTER TABLE hydra_oauth2_code DROP FOREIGN KEY hydra_oauth2_code_challenge_id_fk; ALTER TABLE hydra_oauth2_oidc DROP FOREIGN KEY hydra_oauth2_oidc_challenge_id_fk; ALTER TABLE hydra_oauth2_pkce DROP FOREIGN KEY hydra_oauth2_pkce_challenge_id_fk; -- Drops the index for client_id DROP INDEX hydra_oauth2_access_client_id_idx ON hydra_oauth2_access; DROP INDEX hydra_oauth2_refresh_client_id_idx ON hydra_oauth2_refresh; DROP INDEX hydra_oauth2_code_client_id_idx ON hydra_oauth2_code; DROP INDEX hydra_oauth2_oidc_client_id_idx ON hydra_oauth2_oidc; DROP INDEX hydra_oauth2_pkce_client_id_idx ON hydra_oauth2_pkce; -- request_id was set to varchar(40) NULL (without default) - let's revert that ALTER TABLE hydra_oauth2_access MODIFY request_id varchar(255) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_refresh MODIFY request_id varchar(255) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_code MODIFY request_id varchar(255) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_oidc MODIFY request_id varchar(255) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_pkce MODIFY request_id varchar(255) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_access MODIFY client_id TEXT NOT NULL; ALTER TABLE hydra_oauth2_refresh MODIFY client_id TEXT NOT NULL; ALTER TABLE hydra_oauth2_code MODIFY client_id TEXT NOT NULL; ALTER TABLE hydra_oauth2_oidc MODIFY client_id TEXT NOT NULL; ALTER TABLE hydra_oauth2_pkce MODIFY client_id TEXT NOT NULL;
SQL
hydra/persistence/sql/migrations/20190400000009000000_oauth2.mysql.up.sql
-- First we need to delete all rows that point to a non-existing oauth2 client. DELETE FROM hydra_oauth2_access WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_access.client_id = hydra_client.id); DELETE FROM hydra_oauth2_refresh WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_refresh.client_id = hydra_client.id); DELETE FROM hydra_oauth2_code WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_code.client_id = hydra_client.id); DELETE FROM hydra_oauth2_oidc WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_oidc.client_id = hydra_client.id); DELETE FROM hydra_oauth2_pkce WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_pkce.client_id = hydra_client.id); -- request_id is a 40 varchar in the referenced table which is why we are resizing -- 1. We must remove request_ids longer than 40 chars. This should never happen as we've never issued them longer than this DELETE FROM hydra_oauth2_access WHERE LENGTH(request_id) > 40; DELETE FROM hydra_oauth2_refresh WHERE LENGTH(request_id) > 40; DELETE FROM hydra_oauth2_code WHERE LENGTH(request_id) > 40; DELETE FROM hydra_oauth2_oidc WHERE LENGTH(request_id) > 40; DELETE FROM hydra_oauth2_pkce WHERE LENGTH(request_id) > 40; -- 2. Next we're actually resizing ALTER TABLE hydra_oauth2_access MODIFY request_id varchar(40) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_refresh MODIFY request_id varchar(40) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_code MODIFY request_id varchar(40) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_oidc MODIFY request_id varchar(40) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_pkce MODIFY request_id varchar(40) NOT NULL DEFAULT ''; -- In preparation for creating the client_id index and foreign key, we must set it to varchar(255) which is also -- the length of hydra_client.id DELETE FROM hydra_oauth2_access WHERE LENGTH(client_id) > 255; DELETE FROM hydra_oauth2_refresh WHERE LENGTH(client_id) > 255; DELETE FROM hydra_oauth2_code WHERE LENGTH(client_id) > 255; DELETE FROM hydra_oauth2_oidc WHERE LENGTH(client_id) > 255; DELETE FROM hydra_oauth2_pkce WHERE LENGTH(client_id) > 255; ALTER TABLE hydra_oauth2_access MODIFY client_id varchar(255) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_refresh MODIFY client_id varchar(255) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_code MODIFY client_id varchar(255) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_oidc MODIFY client_id varchar(255) NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_pkce MODIFY client_id varchar(255) NOT NULL DEFAULT ''; -- Now it's time to create the index for client_id CREATE INDEX hydra_oauth2_access_client_id_idx ON hydra_oauth2_access (client_id); CREATE INDEX hydra_oauth2_refresh_client_id_idx ON hydra_oauth2_refresh (client_id); CREATE INDEX hydra_oauth2_code_client_id_idx ON hydra_oauth2_code (client_id); CREATE INDEX hydra_oauth2_oidc_client_id_idx ON hydra_oauth2_oidc (client_id); CREATE INDEX hydra_oauth2_pkce_client_id_idx ON hydra_oauth2_pkce (client_id); -- Foreign keys start here -- This creates a foreign key that cascade delete's if the client_id is removed. ALTER TABLE hydra_oauth2_access ADD CONSTRAINT hydra_oauth2_access_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_refresh ADD CONSTRAINT hydra_oauth2_refresh_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_code ADD CONSTRAINT hydra_oauth2_code_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_oidc ADD CONSTRAINT hydra_oauth2_oidc_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_pkce ADD CONSTRAINT hydra_oauth2_pkce_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; -- This creates a foreign key that cascade delete's if the consent associated with this is removed. ALTER TABLE hydra_oauth2_access ADD CONSTRAINT hydra_oauth2_access_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_refresh ADD CONSTRAINT hydra_oauth2_refresh_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_code ADD CONSTRAINT hydra_oauth2_code_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_oidc ADD CONSTRAINT hydra_oauth2_oidc_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_pkce ADD CONSTRAINT hydra_oauth2_pkce_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE;
SQL
hydra/persistence/sql/migrations/20190400000009000000_oauth2.postgres.down.sql
-- Drops the client_id foreign key ALTER TABLE hydra_oauth2_access DROP CONSTRAINT hydra_oauth2_access_client_id_fk; ALTER TABLE hydra_oauth2_refresh DROP CONSTRAINT hydra_oauth2_refresh_client_id_fk; ALTER TABLE hydra_oauth2_code DROP CONSTRAINT hydra_oauth2_code_client_id_fk; ALTER TABLE hydra_oauth2_oidc DROP CONSTRAINT hydra_oauth2_oidc_client_id_fk; ALTER TABLE hydra_oauth2_pkce DROP CONSTRAINT hydra_oauth2_pkce_client_id_fk; -- Drops the challenge/request_id foreign key ALTER TABLE hydra_oauth2_access DROP CONSTRAINT hydra_oauth2_access_challenge_id_fk; ALTER TABLE hydra_oauth2_refresh DROP CONSTRAINT hydra_oauth2_refresh_challenge_id_fk; ALTER TABLE hydra_oauth2_code DROP CONSTRAINT hydra_oauth2_code_challenge_id_fk; ALTER TABLE hydra_oauth2_oidc DROP CONSTRAINT hydra_oauth2_oidc_challenge_id_fk; ALTER TABLE hydra_oauth2_pkce DROP CONSTRAINT hydra_oauth2_pkce_challenge_id_fk; -- Drops the index for client_id DROP INDEX hydra_oauth2_access_client_id_idx; DROP INDEX hydra_oauth2_refresh_client_id_idx; DROP INDEX hydra_oauth2_code_client_id_idx; DROP INDEX hydra_oauth2_oidc_client_id_idx; DROP INDEX hydra_oauth2_pkce_client_id_idx; -- request_id was set to varchar(40) NULL (without default) - let's revert that ALTER TABLE hydra_oauth2_access ALTER COLUMN request_id TYPE varchar(255); ALTER TABLE hydra_oauth2_refresh ALTER COLUMN request_id TYPE varchar(255); ALTER TABLE hydra_oauth2_code ALTER COLUMN request_id TYPE varchar(255); ALTER TABLE hydra_oauth2_oidc ALTER COLUMN request_id TYPE varchar(255); ALTER TABLE hydra_oauth2_pkce ALTER COLUMN request_id TYPE varchar(255); -- client_id was set to varchar(255), let's revert that. ALTER TABLE hydra_oauth2_access ALTER COLUMN client_id TYPE TEXT; ALTER TABLE hydra_oauth2_refresh ALTER COLUMN client_id TYPE TEXT; ALTER TABLE hydra_oauth2_code ALTER COLUMN client_id TYPE TEXT; ALTER TABLE hydra_oauth2_oidc ALTER COLUMN client_id TYPE TEXT; ALTER TABLE hydra_oauth2_pkce ALTER COLUMN client_id TYPE TEXT;
SQL
hydra/persistence/sql/migrations/20190400000009000000_oauth2.postgres.up.sql
-- First we need to delete all rows that point to a non-existing oauth2 client. DELETE FROM hydra_oauth2_access WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_access.client_id = hydra_client.id); DELETE FROM hydra_oauth2_refresh WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_refresh.client_id = hydra_client.id); DELETE FROM hydra_oauth2_code WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_code.client_id = hydra_client.id); DELETE FROM hydra_oauth2_oidc WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_oidc.client_id = hydra_client.id); DELETE FROM hydra_oauth2_pkce WHERE NOT EXISTS (SELECT 1 FROM hydra_client WHERE hydra_oauth2_pkce.client_id = hydra_client.id); -- request_id is a 40 varchar in the referenced table which is why we are resizing -- 1. We must remove request_ids longer than 40 chars. This should never happen as we've never issued them longer than this DELETE FROM hydra_oauth2_access WHERE LENGTH(request_id) > 40; DELETE FROM hydra_oauth2_refresh WHERE LENGTH(request_id) > 40; DELETE FROM hydra_oauth2_code WHERE LENGTH(request_id) > 40; DELETE FROM hydra_oauth2_oidc WHERE LENGTH(request_id) > 40; DELETE FROM hydra_oauth2_pkce WHERE LENGTH(request_id) > 40; -- 2. Next we're actually resizing ALTER TABLE hydra_oauth2_access ALTER COLUMN request_id TYPE varchar(40); ALTER TABLE hydra_oauth2_refresh ALTER COLUMN request_id TYPE varchar(40); ALTER TABLE hydra_oauth2_code ALTER COLUMN request_id TYPE varchar(40); ALTER TABLE hydra_oauth2_oidc ALTER COLUMN request_id TYPE varchar(40); ALTER TABLE hydra_oauth2_pkce ALTER COLUMN request_id TYPE varchar(40); -- In preparation for creating the client_id index and foreign key, we must set it to varchar(255) which is also -- the length of hydra_client.id DELETE FROM hydra_oauth2_access WHERE LENGTH(client_id) > 255; DELETE FROM hydra_oauth2_refresh WHERE LENGTH(client_id) > 255; DELETE FROM hydra_oauth2_code WHERE LENGTH(client_id) > 255; DELETE FROM hydra_oauth2_oidc WHERE LENGTH(client_id) > 255; DELETE FROM hydra_oauth2_pkce WHERE LENGTH(client_id) > 255; ALTER TABLE hydra_oauth2_access ALTER COLUMN client_id TYPE varchar(255); ALTER TABLE hydra_oauth2_refresh ALTER COLUMN client_id TYPE varchar(255); ALTER TABLE hydra_oauth2_code ALTER COLUMN client_id TYPE varchar(255); ALTER TABLE hydra_oauth2_oidc ALTER COLUMN client_id TYPE varchar(255); ALTER TABLE hydra_oauth2_pkce ALTER COLUMN client_id TYPE varchar(255); -- Now it's time to create the index for client_id CREATE INDEX hydra_oauth2_access_client_id_idx ON hydra_oauth2_access (client_id); CREATE INDEX hydra_oauth2_refresh_client_id_idx ON hydra_oauth2_refresh (client_id); CREATE INDEX hydra_oauth2_code_client_id_idx ON hydra_oauth2_code (client_id); CREATE INDEX hydra_oauth2_oidc_client_id_idx ON hydra_oauth2_oidc (client_id); CREATE INDEX hydra_oauth2_pkce_client_id_idx ON hydra_oauth2_pkce (client_id); -- Foreign keys start here -- This caused #1209: -- SET session_replication_role = replica; -- This creates a foreign key that cascade delete's if the client_id is removed. ALTER TABLE hydra_oauth2_access ADD CONSTRAINT hydra_oauth2_access_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_refresh ADD CONSTRAINT hydra_oauth2_refresh_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_code ADD CONSTRAINT hydra_oauth2_code_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_oidc ADD CONSTRAINT hydra_oauth2_oidc_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_pkce ADD CONSTRAINT hydra_oauth2_pkce_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; -- This creates a foreign key that cascade delete's if the consent associated with this is removed. ALTER TABLE hydra_oauth2_access ADD CONSTRAINT hydra_oauth2_access_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_refresh ADD CONSTRAINT hydra_oauth2_refresh_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_code ADD CONSTRAINT hydra_oauth2_code_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_oidc ADD CONSTRAINT hydra_oauth2_oidc_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_pkce ADD CONSTRAINT hydra_oauth2_pkce_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; -- This caused #1209: -- SET session_replication_role = DEFAULT;
SQL
hydra/persistence/sql/migrations/20190400000010000000_oauth2.cockroach.up.sql
-- Empty because CockroachDB creates indices for foreign keys automatically: -- https://www.cockroachlabs.com/docs/stable/foreign-key.html -- +migrate Up
SQL
hydra/persistence/sql/migrations/20190400000010000000_oauth2.mysql.down.sql
ALTER TABLE hydra_oauth2_access DROP FOREIGN KEY hydra_oauth2_access_challenge_id_fk; DROP INDEX hydra_oauth2_access_challenge_id_idx ON hydra_oauth2_access; ALTER TABLE hydra_oauth2_access ADD CONSTRAINT hydra_oauth2_access_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_refresh DROP FOREIGN KEY hydra_oauth2_refresh_challenge_id_fk; DROP INDEX hydra_oauth2_refresh_challenge_id_idx ON hydra_oauth2_refresh; ALTER TABLE hydra_oauth2_refresh ADD CONSTRAINT hydra_oauth2_refresh_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_code DROP FOREIGN KEY hydra_oauth2_code_challenge_id_fk; DROP INDEX hydra_oauth2_code_challenge_id_idx ON hydra_oauth2_code; ALTER TABLE hydra_oauth2_code ADD CONSTRAINT hydra_oauth2_code_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_oidc DROP FOREIGN KEY hydra_oauth2_oidc_challenge_id_fk; DROP INDEX hydra_oauth2_oidc_challenge_id_idx ON hydra_oauth2_oidc; ALTER TABLE hydra_oauth2_oidc ADD CONSTRAINT hydra_oauth2_oidc_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; ALTER TABLE hydra_oauth2_pkce DROP FOREIGN KEY hydra_oauth2_pkce_challenge_id_fk; DROP INDEX hydra_oauth2_pkce_challenge_id_idx ON hydra_oauth2_pkce; ALTER TABLE hydra_oauth2_pkce ADD CONSTRAINT hydra_oauth2_pkce_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE;
SQL
hydra/persistence/sql/migrations/20190400000010000000_oauth2.mysql.up.sql
CREATE INDEX hydra_oauth2_access_challenge_id_idx ON hydra_oauth2_access (challenge_id); CREATE INDEX hydra_oauth2_refresh_challenge_id_idx ON hydra_oauth2_refresh (challenge_id); CREATE INDEX hydra_oauth2_code_challenge_id_idx ON hydra_oauth2_code (challenge_id); CREATE INDEX hydra_oauth2_oidc_challenge_id_idx ON hydra_oauth2_oidc (challenge_id); CREATE INDEX hydra_oauth2_pkce_challenge_id_idx ON hydra_oauth2_pkce (challenge_id);
SQL
hydra/persistence/sql/migrations/20190400000010000000_oauth2.postgres.down.sql
DROP INDEX hydra_oauth2_access_challenge_id_idx; DROP INDEX hydra_oauth2_refresh_challenge_id_idx; DROP INDEX hydra_oauth2_code_challenge_id_idx; DROP INDEX hydra_oauth2_oidc_challenge_id_idx; DROP INDEX hydra_oauth2_pkce_challenge_id_idx;
SQL
hydra/persistence/sql/migrations/20190400000010000000_oauth2.postgres.up.sql
CREATE INDEX hydra_oauth2_access_challenge_id_idx ON hydra_oauth2_access (challenge_id); CREATE INDEX hydra_oauth2_refresh_challenge_id_idx ON hydra_oauth2_refresh (challenge_id); CREATE INDEX hydra_oauth2_code_challenge_id_idx ON hydra_oauth2_code (challenge_id); CREATE INDEX hydra_oauth2_oidc_challenge_id_idx ON hydra_oauth2_oidc (challenge_id); CREATE INDEX hydra_oauth2_pkce_challenge_id_idx ON hydra_oauth2_pkce (challenge_id);
SQL
hydra/persistence/sql/migrations/20190400000011000000_oauth2.cockroach.up.sql
CREATE TABLE IF NOT EXISTS hydra_oauth2_jti_blacklist ( signature varchar(64) NOT NULL, expires_at timestamp NOT NULL DEFAULT now(), CONSTRAINT "primary" PRIMARY KEY (signature ASC) ); CREATE INDEX ON hydra_oauth2_jti_blacklist ( expires_at );
SQL
hydra/persistence/sql/migrations/20190400000011000000_oauth2.up.sql
CREATE TABLE IF NOT EXISTS hydra_oauth2_jti_blacklist ( signature varchar(64) NOT NULL PRIMARY KEY, expires_at timestamp NOT NULL DEFAULT now() ); -- mysql requires the index to be named CREATE INDEX hydra_oauth2_jti_blacklist_expiry ON hydra_oauth2_jti_blacklist ( expires_at );
SQL
hydra/persistence/sql/migrations/20200521071434000000_consent.cockroach.up.sql
CREATE INDEX hydra_oauth2_consent_request_client_id_subject_idx ON hydra_oauth2_consent_request (client_id, subject);
SQL
hydra/persistence/sql/migrations/20200521071434000000_consent.mysql.up.sql
CREATE INDEX hydra_oauth2_consent_request_client_id_subject_idx ON hydra_oauth2_consent_request (client_id, subject);
SQL
hydra/persistence/sql/migrations/20200521071434000000_consent.postgres.up.sql
CREATE INDEX hydra_oauth2_consent_request_client_id_subject_idx ON hydra_oauth2_consent_request (client_id, subject);
SQL
hydra/persistence/sql/migrations/20200527215732000000_client.up.sql
-- complement for migration 20200527215731_client.up -- due to cockroach being unable to handle a scheme modification and update statement in a single migration transaction UPDATE hydra_client SET token_endpoint_auth_signing_alg = 'RS256' WHERE token_endpoint_auth_method = 'private_key_jwt';
SQL
hydra/persistence/sql/migrations/20200819163013000000_add_client_id_subject_idx_to_access_and_refresh.cockroach.down.sql
DROP INDEX hydra_oauth2_refresh@hydra_oauth2_refresh_client_id_subject_idx; DROP INDEX hydra_oauth2_access@hydra_oauth2_access_client_id_subject_idx;
SQL
hydra/persistence/sql/migrations/20200819163013000000_add_client_id_subject_idx_to_access_and_refresh.cockroach.up.sql
CREATE INDEX hydra_oauth2_access_client_id_subject_idx ON hydra_oauth2_access (client_id, subject); CREATE INDEX hydra_oauth2_refresh_client_id_subject_idx ON hydra_oauth2_refresh (client_id, subject);
SQL
hydra/persistence/sql/migrations/20200819163013000000_add_client_id_subject_idx_to_access_and_refresh.mysql.down.sql
DROP INDEX hydra_oauth2_refresh_client_id_subject_idx ON hydra_oauth2_refresh; DROP INDEX hydra_oauth2_access_client_id_subject_idx ON hydra_oauth2_access;
SQL
hydra/persistence/sql/migrations/20200819163013000000_add_client_id_subject_idx_to_access_and_refresh.mysql.up.sql
CREATE INDEX hydra_oauth2_access_client_id_subject_idx ON hydra_oauth2_access (client_id, subject); CREATE INDEX hydra_oauth2_refresh_client_id_subject_idx ON hydra_oauth2_refresh (client_id, subject);
SQL
hydra/persistence/sql/migrations/20200819163013000000_add_client_id_subject_idx_to_access_and_refresh.postgres.down.sql
DROP INDEX hydra_oauth2_refresh_client_id_subject_idx; DROP INDEX hydra_oauth2_access_client_id_subject_idx;
SQL
hydra/persistence/sql/migrations/20200819163013000000_add_client_id_subject_idx_to_access_and_refresh.postgres.up.sql
CREATE INDEX hydra_oauth2_access_client_id_subject_idx ON hydra_oauth2_access (client_id, subject); CREATE INDEX hydra_oauth2_refresh_client_id_subject_idx ON hydra_oauth2_refresh (client_id, subject);
SQL
hydra/persistence/sql/migrations/20200913192340000000_initial_sqlite.sqlite.down.sql
DROP TABLE hydra_client; DROP TABLE hydra_jwk; DROP TABLE hydra_oauth2_authentication_session; DROP TABLE hydra_oauth2_authentication_request; DROP TABLE hydra_oauth2_consent_request; DROP TABLE hydra_oauth2_consent_request_handled; DROP TABLE hydra_oauth2_access; DROP TABLE hydra_oauth2_authentication_request_handled; DROP TABLE hydra_oauth2_code; DROP TABLE hydra_oauth2_jti_blacklist; DROP TABLE hydra_oauth2_logout_request; DROP TABLE hydra_oauth2_obfuscated_authentication_session; DROP TABLE hydra_oauth2_oidc; DROP TABLE hydra_oauth2_pkce; DROP TABLE hydra_oauth2_refresh;
SQL
hydra/persistence/sql/migrations/20200913192340000000_initial_sqlite.sqlite.up.sql
CREATE TABLE IF NOT EXISTS hydra_client ( id VARCHAR(255) NOT NULL, client_name TEXT NOT NULL, client_secret TEXT NOT NULL, redirect_uris TEXT NOT NULL, grant_types TEXT NOT NULL, response_types TEXT NOT NULL, scope TEXT NOT NULL, owner TEXT NOT NULL, policy_uri TEXT NOT NULL, tos_uri TEXT NOT NULL, client_uri TEXT NOT NULL, logo_uri TEXT NOT NULL, contacts TEXT NOT NULL, client_secret_expires_at INTEGER NOT NULL DEFAULT 0, sector_identifier_uri TEXT NOT NULL, jwks TEXT NOT NULL, jwks_uri TEXT NOT NULL, request_uris TEXT NOT NULL, token_endpoint_auth_method VARCHAR(25) NOT NULL DEFAULT '', request_object_signing_alg VARCHAR(10) NOT NULL DEFAULT '', userinfo_signed_response_alg VARCHAR(10) NOT NULL DEFAULT '', subject_type VARCHAR(15) NOT NULL DEFAULT '', allowed_cors_origins TEXT NOT NULL, pk INTEGER PRIMARY KEY, audience TEXT NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, frontchannel_logout_uri TEXT NOT NULL DEFAULT '', frontchannel_logout_session_required INTEGER NOT NULL DEFAULT false, post_logout_redirect_uris TEXT NOT NULL DEFAULT '', backchannel_logout_uri TEXT NOT NULL DEFAULT '', backchannel_logout_session_required INTEGER NOT NULL DEFAULT false, metadata TEXT NOT NULL DEFAULT '{}', token_endpoint_auth_signing_alg VARCHAR(10) NOT NULL DEFAULT '' ); CREATE UNIQUE INDEX hydra_client_id_idx ON hydra_client (id); CREATE TABLE IF NOT EXISTS hydra_jwk ( sid VARCHAR(255) NOT NULL, kid VARCHAR(255) NOT NULL, version INTEGER NOT NULL DEFAULT 0, keydata TEXT NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, pk INTEGER PRIMARY KEY ); CREATE UNIQUE INDEX hydra_jwk_sid_kid_key ON hydra_jwk (sid, kid); CREATE TABLE hydra_oauth2_authentication_session ( id VARCHAR(40) NOT NULL PRIMARY KEY, authenticated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, subject VARCHAR(255) NOT NULL, remember INTEGER NOT NULL DEFAULT false ); CREATE INDEX hydra_oauth2_authentication_session_subject_idx ON hydra_oauth2_authentication_session (subject); CREATE TABLE hydra_oauth2_authentication_request ( challenge VARCHAR(40) NOT NULL PRIMARY KEY, requested_scope TEXT NOT NULL, verifier VARCHAR(40) NOT NULL, csrf VARCHAR(40) NOT NULL, subject VARCHAR(255) NOT NULL, request_url TEXT NOT NULL, skip INTEGER NOT NULL, client_id VARCHAR(255) NOT NULL REFERENCES hydra_client (id) ON DELETE CASCADE, requested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, authenticated_at TIMESTAMP NULL, oidc_context TEXT NOT NULL, login_session_id VARCHAR(40) NULL REFERENCES hydra_oauth2_authentication_session (id) ON DELETE CASCADE DEFAULT '', requested_at_audience TEXT NULL DEFAULT '' ); CREATE INDEX hydra_oauth2_authentication_request_client_id_idx ON hydra_oauth2_authentication_request (client_id); CREATE INDEX hydra_oauth2_authentication_request_login_session_id_idx ON hydra_oauth2_authentication_request (login_session_id); CREATE INDEX hydra_oauth2_authentication_request_subject_idx ON hydra_oauth2_authentication_request (subject); CREATE UNIQUE INDEX hydra_oauth2_authentication_request_verifier_idx ON hydra_oauth2_authentication_request (verifier); CREATE TABLE hydra_oauth2_consent_request ( challenge VARCHAR(40) NOT NULL PRIMARY KEY, verifier VARCHAR(40) NOT NULL, client_id VARCHAR(255) NOT NULL REFERENCES hydra_client (id) ON DELETE CASCADE, subject VARCHAR(255) NOT NULL, request_url TEXT NOT NULL, skip INTEGER NOT NULL, requested_scope TEXT NOT NULL, csrf VARCHAR(40) NOT NULL, authenticated_at TIMESTAMP NULL, requested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, oidc_context TEXT NOT NULL, forced_subject_identifier VARCHAR(255) NULL DEFAULT '', login_session_id VARCHAR(40) NULL REFERENCES hydra_oauth2_authentication_session (id) ON DELETE SET NULL, login_challenge VARCHAR(40) NULL REFERENCES hydra_oauth2_authentication_request (challenge) ON DELETE SET NULL, requested_at_audience TEXT NULL DEFAULT '', acr TEXT NULL DEFAULT '', context TEXT NOT NULL DEFAULT '{}' ); CREATE INDEX hydra_oauth2_consent_request_client_id_idx ON hydra_oauth2_consent_request (client_id); CREATE INDEX hydra_oauth2_consent_request_subject_idx ON hydra_oauth2_consent_request (subject); CREATE INDEX hydra_oauth2_consent_request_login_session_id_idx ON hydra_oauth2_consent_request (login_session_id); CREATE INDEX hydra_oauth2_consent_request_login_challenge_idx ON hydra_oauth2_consent_request (login_challenge); CREATE TABLE hydra_oauth2_consent_request_handled ( challenge VARCHAR(40) NOT NULL PRIMARY KEY REFERENCES hydra_oauth2_consent_request (challenge) ON DELETE CASCADE, granted_scope TEXT NOT NULL, remember INTEGER NOT NULL, remember_for INTEGER NOT NULL, error TEXT NOT NULL, requested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, session_access_token TEXT NOT NULL, session_id_token TEXT NOT NULL, authenticated_at TIMESTAMP NULL, was_used INTEGER NOT NULL, granted_at_audience TEXT NULL DEFAULT '', handled_at TIMESTAMP NULL ); CREATE TABLE hydra_oauth2_access ( signature VARCHAR(255) NOT NULL PRIMARY KEY, request_id VARCHAR(40) NOT NULL, requested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, client_id VARCHAR(255) NOT NULL REFERENCES hydra_client (id) ON DELETE CASCADE, scope TEXT NOT NULL, granted_scope TEXT NOT NULL, form_data TEXT NOT NULL, session_data TEXT NOT NULL, subject VARCHAR(255) NOT NULL DEFAULT '', active INTEGER NOT NULL DEFAULT true, requested_audience TEXT NULL DEFAULT '', granted_audience TEXT NULL DEFAULT '', challenge_id VARCHAR(40) NULL REFERENCES hydra_oauth2_consent_request_handled (challenge) ON DELETE CASCADE, UNIQUE (request_id) ); CREATE INDEX hydra_oauth2_access_requested_at_idx ON hydra_oauth2_access (requested_at); CREATE INDEX hydra_oauth2_access_client_id_idx ON hydra_oauth2_access (client_id); CREATE INDEX hydra_oauth2_access_challenge_id_idx ON hydra_oauth2_access (challenge_id); CREATE INDEX hydra_oauth2_access_client_id_subject_idx ON hydra_oauth2_access (client_id, subject); CREATE TABLE hydra_oauth2_authentication_request_handled ( challenge VARCHAR(40) NOT NULL PRIMARY KEY REFERENCES hydra_oauth2_authentication_request (challenge) ON DELETE CASCADE, subject VARCHAR(255) NOT NULL, remember INTEGER NOT NULL, remember_for INTEGER NOT NULL, error TEXT NOT NULL, acr TEXT NOT NULL, requested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, authenticated_at TIMESTAMP NULL, was_used INTEGER NOT NULL, forced_subject_identifier VARCHAR(255) NULL DEFAULT '', context TEXT NOT NULL DEFAULT '{}' ); CREATE TABLE hydra_oauth2_code ( signature VARCHAR(255) NOT NULL, request_id VARCHAR(40) NOT NULL, requested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, client_id VARCHAR(255) NOT NULL REFERENCES hydra_client (id) ON DELETE CASCADE, scope TEXT NOT NULL, granted_scope TEXT NOT NULL, form_data TEXT NOT NULL, session_data TEXT NOT NULL, subject VARCHAR(255) NOT NULL DEFAULT '', active INTEGER NOT NULL DEFAULT true, requested_audience TEXT NULL DEFAULT '', granted_audience TEXT NULL DEFAULT '', challenge_id VARCHAR(40) NULL REFERENCES hydra_oauth2_consent_request_handled (challenge) ON DELETE CASCADE ); CREATE INDEX hydra_oauth2_code_client_id_idx ON hydra_oauth2_code (client_id); CREATE INDEX hydra_oauth2_code_challenge_id_idx ON hydra_oauth2_code (challenge_id); CREATE TABLE hydra_oauth2_jti_blacklist ( signature VARCHAR(64) NOT NULL PRIMARY KEY, expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); CREATE INDEX hydra_oauth2_jti_blacklist_expires_at_idx ON hydra_oauth2_jti_blacklist (expires_at); CREATE TABLE hydra_oauth2_logout_request ( challenge VARCHAR(36) NOT NULL PRIMARY KEY, verifier VARCHAR(36) NOT NULL, subject VARCHAR(255) NOT NULL, sid VARCHAR(36) NOT NULL, client_id VARCHAR(255) NULL REFERENCES hydra_client (id) ON DELETE CASCADE, request_url TEXT NOT NULL, redir_url TEXT NOT NULL, was_used INTEGER NOT NULL DEFAULT false, accepted INTEGER NOT NULL DEFAULT false, rejected INTEGER NOT NULL DEFAULT false, rp_initiated INTEGER NOT NULL DEFAULT false, UNIQUE (verifier) ); CREATE INDEX hydra_oauth2_logout_request_client_id_idx ON hydra_oauth2_logout_request (client_id); CREATE TABLE hydra_oauth2_obfuscated_authentication_session ( subject VARCHAR(255) NOT NULL, client_id VARCHAR(255) NOT NULL REFERENCES hydra_client (id) ON DELETE CASCADE, subject_obfuscated VARCHAR(255) NOT NULL, PRIMARY KEY (subject, client_id) ); CREATE INDEX hydra_oauth2_obfuscated_authentication_session_client_id_subject_obfuscated_idx ON hydra_oauth2_obfuscated_authentication_session (client_id, subject_obfuscated); CREATE TABLE hydra_oauth2_oidc ( signature VARCHAR(255) NOT NULL PRIMARY KEY, request_id VARCHAR(40) NOT NULL, requested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, client_id VARCHAR(255) NOT NULL REFERENCES hydra_client (id) ON DELETE CASCADE, scope TEXT NOT NULL, granted_scope TEXT NOT NULL, form_data TEXT NOT NULL, session_data TEXT NOT NULL, subject VARCHAR(255) NOT NULL DEFAULT '', active INTEGER NOT NULL DEFAULT true, requested_audience TEXT NULL DEFAULT '', granted_audience TEXT NULL DEFAULT '', challenge_id VARCHAR(40) NULL REFERENCES hydra_oauth2_consent_request_handled (challenge) ON DELETE CASCADE ); CREATE INDEX hydra_oauth2_oidc_client_id_idx ON hydra_oauth2_oidc (client_id); CREATE INDEX hydra_oauth2_oidc_challenge_id_idx ON hydra_oauth2_oidc (challenge_id); CREATE TABLE hydra_oauth2_pkce ( signature VARCHAR(255) NOT NULL PRIMARY KEY, request_id VARCHAR(40) NOT NULL, requested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, client_id VARCHAR(255) NOT NULL REFERENCES hydra_client (id) ON DELETE CASCADE, scope TEXT NOT NULL, granted_scope TEXT NOT NULL, form_data TEXT NOT NULL, session_data TEXT NOT NULL, subject VARCHAR(255) NOT NULL, active INTEGER NOT NULL DEFAULT true, requested_audience TEXT NULL DEFAULT '', granted_audience TEXT NULL DEFAULT '', challenge_id VARCHAR(40) NULL REFERENCES hydra_oauth2_consent_request_handled (challenge) ON DELETE CASCADE ); CREATE INDEX hydra_oauth2_pkce_client_id_idx ON hydra_oauth2_pkce (client_id); CREATE INDEX hydra_oauth2_pkce_challenge_id_idx ON hydra_oauth2_pkce (challenge_id); CREATE TABLE hydra_oauth2_refresh ( signature VARCHAR(255) NOT NULL PRIMARY KEY, request_id VARCHAR(40) NOT NULL, requested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, client_id VARCHAR(255) NOT NULL REFERENCES hydra_client (id) ON DELETE CASCADE, scope TEXT NOT NULL, granted_scope TEXT NOT NULL, form_data TEXT NOT NULL, session_data TEXT NOT NULL, subject VARCHAR(255) NOT NULL DEFAULT '', active INTEGER NOT NULL DEFAULT true, requested_audience TEXT NULL DEFAULT '', granted_audience TEXT NULL DEFAULT '', challenge_id VARCHAR(40) NULL REFERENCES hydra_oauth2_consent_request_handled (challenge) ON DELETE CASCADE, UNIQUE (request_id) ); CREATE INDEX hydra_oauth2_refresh_client_id_idx ON hydra_oauth2_refresh (client_id); CREATE INDEX hydra_oauth2_refresh_challenge_id_idx ON hydra_oauth2_refresh (challenge_id); CREATE INDEX hydra_oauth2_refresh_client_id_subject_idx ON hydra_oauth2_refresh (client_id, subject);
SQL
hydra/persistence/sql/migrations/20201110104000000000_drop_uq_oauth2.cockroach.down.sql
DROP INDEX hydra_oauth2_access_request_id_idx; DROP INDEX hydra_oauth2_refresh_request_id_idx; CREATE UNIQUE INDEX hydra_oauth2_access_request_id_idx ON hydra_oauth2_access (request_id); CREATE UNIQUE INDEX hydra_oauth2_refresh_request_id_idx ON hydra_oauth2_refresh (request_id); DROP INDEX hydra_oauth2_code_request_id_idx; DROP INDEX hydra_oauth2_oidc_request_id_idx; DROP INDEX hydra_oauth2_pkce_request_id_idx;
SQL
hydra/persistence/sql/migrations/20201110104000000000_drop_uq_oauth2.cockroach.up.sql
--- This is hardcoded and if it fails we need to manually figure out the constraint name: --- SELECT constraint_name FROM information_schema.table_constraints WHERE table_name='hydra_oauth2_access' AND constraint_type='UNIQUE'; DROP INDEX hydra_oauth2_access_request_id_key CASCADE; DROP INDEX hydra_oauth2_refresh_request_id_key CASCADE; CREATE INDEX hydra_oauth2_access_request_id_idx ON hydra_oauth2_access (request_id); CREATE INDEX hydra_oauth2_refresh_request_id_idx ON hydra_oauth2_refresh (request_id); CREATE INDEX hydra_oauth2_code_request_id_idx ON hydra_oauth2_code (request_id); CREATE INDEX hydra_oauth2_oidc_request_id_idx ON hydra_oauth2_oidc (request_id); CREATE INDEX hydra_oauth2_pkce_request_id_idx ON hydra_oauth2_pkce (request_id);
SQL
hydra/persistence/sql/migrations/20201110104000000000_drop_uq_oauth2.mysql.down.sql
DROP INDEX hydra_oauth2_access_request_id_idx ON hydra_oauth2_access; DROP INDEX hydra_oauth2_refresh_request_id_idx ON hydra_oauth2_refresh; CREATE UNIQUE INDEX hydra_oauth2_access_request_id_idx ON hydra_oauth2_access (request_id); CREATE UNIQUE INDEX hydra_oauth2_refresh_request_id_idx ON hydra_oauth2_refresh (request_id); DROP INDEX hydra_oauth2_code_request_id_idx; DROP INDEX hydra_oauth2_oidc_request_id_idx; DROP INDEX hydra_oauth2_pkce_request_id_idx;
SQL
hydra/persistence/sql/migrations/20201110104000000000_drop_uq_oauth2.mysql.up.sql
DROP INDEX hydra_oauth2_access_request_id_idx ON hydra_oauth2_access; DROP INDEX hydra_oauth2_refresh_request_id_idx ON hydra_oauth2_refresh; CREATE INDEX hydra_oauth2_access_request_id_idx ON hydra_oauth2_access (request_id); CREATE INDEX hydra_oauth2_refresh_request_id_idx ON hydra_oauth2_refresh (request_id); CREATE INDEX hydra_oauth2_code_request_id_idx ON hydra_oauth2_code (request_id); CREATE INDEX hydra_oauth2_oidc_request_id_idx ON hydra_oauth2_oidc (request_id); CREATE INDEX hydra_oauth2_pkce_request_id_idx ON hydra_oauth2_pkce (request_id);
SQL
hydra/persistence/sql/migrations/20201110104000000000_drop_uq_oauth2.postgres.down.sql
DROP INDEX hydra_oauth2_access_request_id_idx; DROP INDEX hydra_oauth2_refresh_request_id_idx; CREATE UNIQUE INDEX hydra_oauth2_access_request_id_idx ON hydra_oauth2_access (request_id); CREATE UNIQUE INDEX hydra_oauth2_refresh_request_id_idx ON hydra_oauth2_refresh (request_id); DROP INDEX hydra_oauth2_code_request_id_idx; DROP INDEX hydra_oauth2_oidc_request_id_idx; DROP INDEX hydra_oauth2_pkce_request_id_idx;
SQL
hydra/persistence/sql/migrations/20201110104000000000_drop_uq_oauth2.postgres.up.sql
DROP INDEX hydra_oauth2_access_request_id_idx; DROP INDEX hydra_oauth2_refresh_request_id_idx; CREATE INDEX hydra_oauth2_access_request_id_idx ON hydra_oauth2_access (request_id); CREATE INDEX hydra_oauth2_refresh_request_id_idx ON hydra_oauth2_refresh (request_id); CREATE INDEX hydra_oauth2_code_request_id_idx ON hydra_oauth2_code (request_id); CREATE INDEX hydra_oauth2_oidc_request_id_idx ON hydra_oauth2_oidc (request_id); CREATE INDEX hydra_oauth2_pkce_request_id_idx ON hydra_oauth2_pkce (request_id);
SQL
hydra/persistence/sql/migrations/20201110104000000000_drop_uq_oauth2.sqlite.down.sql
DROP INDEX hydra_oauth2_access_request_id_idx; DROP INDEX hydra_oauth2_refresh_request_id_idx; DROP INDEX hydra_oauth2_code_request_id_idx; DROP INDEX hydra_oauth2_oidc_request_id_idx; DROP INDEX hydra_oauth2_pkce_request_id_idx; --- CREATE TABLE "_hydra_oauth2_access_tmp" ( signature VARCHAR(255) NOT NULL PRIMARY KEY, request_id VARCHAR(40) NOT NULL, requested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, client_id VARCHAR(255) NOT NULL REFERENCES hydra_client (id) ON DELETE CASCADE, scope TEXT NOT NULL, granted_scope TEXT NOT NULL, form_data TEXT NOT NULL, session_data TEXT NOT NULL, subject VARCHAR(255) NOT NULL DEFAULT '', active INTEGER NOT NULL DEFAULT true, requested_audience TEXT NULL DEFAULT '', granted_audience TEXT NULL DEFAULT '', challenge_id VARCHAR(40) NULL REFERENCES hydra_oauth2_consent_request_handled (challenge) ON DELETE CASCADE, UNIQUE (request_id) ); INSERT INTO "_hydra_oauth2_access_tmp" ( signature, request_id, requested_at, client_id, scope, granted_scope, form_data, session_data, subject, active, requested_audience, granted_audience, challenge_id ) SELECT signature, request_id, requested_at, client_id, scope, granted_scope, form_data, session_data, subject, active, requested_audience, granted_audience, challenge_id FROM "hydra_oauth2_access"; DROP TABLE "hydra_oauth2_access"; ALTER TABLE "_hydra_oauth2_access_tmp" RENAME TO "hydra_oauth2_access"; CREATE INDEX hydra_oauth2_access_requested_at_idx ON hydra_oauth2_access (requested_at); CREATE INDEX hydra_oauth2_access_client_id_idx ON hydra_oauth2_access (client_id); CREATE INDEX hydra_oauth2_access_challenge_id_idx ON hydra_oauth2_access (challenge_id); CREATE INDEX hydra_oauth2_access_client_id_subject_idx ON hydra_oauth2_access (client_id, subject); --- CREATE TABLE "_hydra_oauth2_refresh_tmp" ( signature VARCHAR(255) NOT NULL PRIMARY KEY, request_id VARCHAR(40) NOT NULL, requested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, client_id VARCHAR(255) NOT NULL REFERENCES hydra_client (id) ON DELETE CASCADE, scope TEXT NOT NULL, granted_scope TEXT NOT NULL, form_data TEXT NOT NULL, session_data TEXT NOT NULL, subject VARCHAR(255) NOT NULL DEFAULT '', active INTEGER NOT NULL DEFAULT true, requested_audience TEXT NULL DEFAULT '', granted_audience TEXT NULL DEFAULT '', challenge_id VARCHAR(40) NULL REFERENCES hydra_oauth2_consent_request_handled (challenge) ON DELETE CASCADE, UNIQUE (request_id) ); INSERT INTO "_hydra_oauth2_refresh_tmp" ( signature, request_id, requested_at, client_id, scope, granted_scope, form_data, session_data, subject, active, requested_audience, granted_audience, challenge_id ) SELECT signature, request_id, requested_at, client_id, scope, granted_scope, form_data, session_data, subject, active, requested_audience, granted_audience, challenge_id FROM "hydra_oauth2_refresh"; DROP TABLE "hydra_oauth2_refresh"; ALTER TABLE "_hydra_oauth2_refresh_tmp" RENAME TO "hydra_oauth2_refresh"; CREATE INDEX hydra_oauth2_refresh_client_id_idx ON hydra_oauth2_refresh (client_id); CREATE INDEX hydra_oauth2_refresh_challenge_id_idx ON hydra_oauth2_refresh (challenge_id); CREATE INDEX hydra_oauth2_refresh_client_id_subject_idx ON hydra_oauth2_refresh (client_id, subject);
SQL
hydra/persistence/sql/migrations/20201110104000000000_drop_uq_oauth2.sqlite.up.sql
CREATE TABLE "_hydra_oauth2_access_tmp" ( signature VARCHAR(255) NOT NULL PRIMARY KEY, request_id VARCHAR(40) NOT NULL, requested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, client_id VARCHAR(255) NOT NULL REFERENCES hydra_client (id) ON DELETE CASCADE, scope TEXT NOT NULL, granted_scope TEXT NOT NULL, form_data TEXT NOT NULL, session_data TEXT NOT NULL, subject VARCHAR(255) NOT NULL DEFAULT '', active INTEGER NOT NULL DEFAULT true, requested_audience TEXT NULL DEFAULT '', granted_audience TEXT NULL DEFAULT '', challenge_id VARCHAR(40) NULL REFERENCES hydra_oauth2_consent_request_handled (challenge) ON DELETE CASCADE ); INSERT INTO "_hydra_oauth2_access_tmp" ( signature, request_id, requested_at, client_id, scope, granted_scope, form_data, session_data, subject, active, requested_audience, granted_audience, challenge_id ) SELECT signature, request_id, requested_at, client_id, scope, granted_scope, form_data, session_data, subject, active, requested_audience, granted_audience, challenge_id FROM "hydra_oauth2_access"; DROP TABLE "hydra_oauth2_access"; ALTER TABLE "_hydra_oauth2_access_tmp" RENAME TO "hydra_oauth2_access"; CREATE INDEX hydra_oauth2_access_requested_at_idx ON hydra_oauth2_access (requested_at); CREATE INDEX hydra_oauth2_access_client_id_idx ON hydra_oauth2_access (client_id); CREATE INDEX hydra_oauth2_access_challenge_id_idx ON hydra_oauth2_access (challenge_id); CREATE INDEX hydra_oauth2_access_client_id_subject_idx ON hydra_oauth2_access (client_id, subject); --- CREATE TABLE "_hydra_oauth2_refresh_tmp" ( signature VARCHAR(255) NOT NULL PRIMARY KEY, request_id VARCHAR(40) NOT NULL, requested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, client_id VARCHAR(255) NOT NULL REFERENCES hydra_client (id) ON DELETE CASCADE, scope TEXT NOT NULL, granted_scope TEXT NOT NULL, form_data TEXT NOT NULL, session_data TEXT NOT NULL, subject VARCHAR(255) NOT NULL DEFAULT '', active INTEGER NOT NULL DEFAULT true, requested_audience TEXT NULL DEFAULT '', granted_audience TEXT NULL DEFAULT '', challenge_id VARCHAR(40) NULL REFERENCES hydra_oauth2_consent_request_handled (challenge) ON DELETE CASCADE ); INSERT INTO "_hydra_oauth2_refresh_tmp" ( signature, request_id, requested_at, client_id, scope, granted_scope, form_data, session_data, subject, active, requested_audience, granted_audience, challenge_id ) SELECT signature, request_id, requested_at, client_id, scope, granted_scope, form_data, session_data, subject, active, requested_audience, granted_audience, challenge_id FROM "hydra_oauth2_refresh"; DROP TABLE "hydra_oauth2_refresh"; ALTER TABLE "_hydra_oauth2_refresh_tmp" RENAME TO "hydra_oauth2_refresh"; CREATE INDEX hydra_oauth2_refresh_client_id_idx ON hydra_oauth2_refresh (client_id); CREATE INDEX hydra_oauth2_refresh_challenge_id_idx ON hydra_oauth2_refresh (challenge_id); CREATE INDEX hydra_oauth2_refresh_client_id_subject_idx ON hydra_oauth2_refresh (client_id, subject); --- CREATE INDEX hydra_oauth2_access_request_id_idx ON hydra_oauth2_access (request_id); CREATE INDEX hydra_oauth2_refresh_request_id_idx ON hydra_oauth2_refresh (request_id); CREATE INDEX hydra_oauth2_code_request_id_idx ON hydra_oauth2_code (request_id); CREATE INDEX hydra_oauth2_oidc_request_id_idx ON hydra_oauth2_oidc (request_id); CREATE INDEX hydra_oauth2_pkce_request_id_idx ON hydra_oauth2_pkce (request_id);
SQL
hydra/persistence/sql/migrations/20201116133000000000_set_null_time.cockroach.down.sql
ALTER TABLE hydra_oauth2_authentication_session ALTER COLUMN authenticated_at SET DEFAULT NOW(); ALTER TABLE hydra_oauth2_authentication_session ALTER COLUMN authenticated_at SET NOT NULL;
SQL
hydra/persistence/sql/migrations/20201116133000000000_set_null_time.cockroach.up.sql
ALTER TABLE hydra_oauth2_authentication_session ALTER COLUMN authenticated_at DROP NOT NULL; ALTER TABLE hydra_oauth2_authentication_session ALTER COLUMN authenticated_at DROP DEFAULT;
SQL
hydra/persistence/sql/migrations/20201116133000000000_set_null_time.mysql.down.sql
ALTER TABLE hydra_oauth2_authentication_session MODIFY authenticated_at timestamp NOT NULL DEFAULT NOW();
SQL
hydra/persistence/sql/migrations/20201116133000000000_set_null_time.postgres.down.sql
ALTER TABLE hydra_oauth2_authentication_session ALTER COLUMN authenticated_at SET DEFAULT NOW(); ALTER TABLE hydra_oauth2_authentication_session ALTER COLUMN authenticated_at SET NOT NULL;
SQL
hydra/persistence/sql/migrations/20201116133000000000_set_null_time.postgres.up.sql
ALTER TABLE hydra_oauth2_authentication_session ALTER COLUMN authenticated_at DROP NOT NULL; ALTER TABLE hydra_oauth2_authentication_session ALTER COLUMN authenticated_at DROP DEFAULT;
SQL
hydra/persistence/sql/migrations/20201116133000000000_set_null_time.sqlite.down.sql
CREATE TABLE "_hydra_oauth2_authentication_session_tmp" ( id VARCHAR(40) NOT NULL PRIMARY KEY, authenticated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, subject VARCHAR(255) NOT NULL, remember INTEGER NOT NULL DEFAULT false ); DELETE FROM hydra_oauth2_authentication_session WHERE authenticated_at = NULL; INSERT INTO "_hydra_oauth2_authentication_session_tmp" ( id, authenticated_at, subject, remember ) SELECT id, authenticated_at, subject, remember FROM "hydra_oauth2_authentication_session"; DROP INDEX hydra_oauth2_authentication_session_subject_idx; DROP TABLE "hydra_oauth2_authentication_session"; ALTER TABLE "_hydra_oauth2_authentication_session_tmp" RENAME TO "hydra_oauth2_authentication_session"; CREATE INDEX hydra_oauth2_authentication_session_subject_idx ON hydra_oauth2_authentication_session (subject);
SQL
hydra/persistence/sql/migrations/20201116133000000000_set_null_time.sqlite.up.sql
CREATE TABLE "_hydra_oauth2_authentication_session_tmp" ( id VARCHAR(40) NOT NULL PRIMARY KEY, authenticated_at TIMESTAMP NULL, subject VARCHAR(255) NOT NULL, remember INTEGER NOT NULL DEFAULT false ); INSERT INTO "_hydra_oauth2_authentication_session_tmp" ( id, authenticated_at, subject, remember ) SELECT id, authenticated_at, subject, remember FROM "hydra_oauth2_authentication_session"; DROP INDEX hydra_oauth2_authentication_session_subject_idx; DROP TABLE "hydra_oauth2_authentication_session"; ALTER TABLE "_hydra_oauth2_authentication_session_tmp" RENAME TO "hydra_oauth2_authentication_session"; CREATE INDEX hydra_oauth2_authentication_session_subject_idx ON hydra_oauth2_authentication_session (subject);
SQL
hydra/persistence/sql/migrations/20210928155900000000_support_amr_claim.cockroach.down.sql
ALTER TABLE hydra_oauth2_consent_request DROP COLUMN amr; ALTER TABLE hydra_oauth2_authentication_request_handled DROP COLUMN amr;
SQL
hydra/persistence/sql/migrations/20210928155900000000_support_amr_claim.cockroach.up.sql
ALTER TABLE hydra_oauth2_consent_request ADD COLUMN amr TEXT NOT NULL DEFAULT ''; ALTER TABLE hydra_oauth2_authentication_request_handled ADD COLUMN amr TEXT NOT NULL DEFAULT '';
SQL
hydra/persistence/sql/migrations/20210928155900000000_support_amr_claim.mysql.down.sql
ALTER TABLE hydra_oauth2_consent_request DROP COLUMN amr; ALTER TABLE hydra_oauth2_authentication_request_handled DROP COLUMN amr;
SQL
hydra/persistence/sql/migrations/20210928155900000000_support_amr_claim.mysql.up.sql
ALTER TABLE hydra_oauth2_consent_request ADD amr TEXT NULL; UPDATE hydra_oauth2_consent_request SET amr=''; ALTER TABLE hydra_oauth2_consent_request MODIFY amr TEXT NOT NULL; ALTER TABLE hydra_oauth2_authentication_request_handled ADD amr TEXT NULL; UPDATE hydra_oauth2_authentication_request_handled SET amr=''; ALTER TABLE hydra_oauth2_authentication_request_handled MODIFY amr TEXT NOT NULL;
SQL
hydra/persistence/sql/migrations/20210928155900000000_support_amr_claim.postgres.down.sql
ALTER TABLE hydra_oauth2_consent_request DROP COLUMN amr; ALTER TABLE hydra_oauth2_authentication_request_handled DROP COLUMN amr;