Skip to content

Commit

Permalink
sql: Remove superuser requirements from postgres migrations (ory#1226)
Browse files Browse the repository at this point in the history
Closes ory#1209

Signed-off-by: aeneasr <[email protected]>
  • Loading branch information
aeneasr authored Dec 12, 2018
1 parent be81806 commit a455fdf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions client/sql_migration_files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions consent/migrations/sql/postgres/7.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ DELETE FROM hydra_oauth2_authentication_request_handled WHERE NOT EXISTS (SELECT

-- Actual indices

SET session_replication_role = replica;
-- 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;
Expand All @@ -55,7 +56,8 @@ ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_req
-- 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;

SET session_replication_role = DEFAULT;
-- This caused #1209:
-- SET session_replication_role = DEFAULT;

-- +migrate Down
ALTER TABLE hydra_oauth2_consent_request_handled DROP CONSTRAINT hydra_oauth2_consent_request_handled_challenge_fk;
Expand Down
4 changes: 2 additions & 2 deletions consent/sql_migration_files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions oauth2/migrations/sql/postgres/9.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ CREATE INDEX hydra_oauth2_pkce_client_id_idx ON hydra_oauth2_pkce (client_id);

-- Foreign keys start here

SET session_replication_role = replica;
-- 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;
Expand All @@ -60,7 +61,8 @@ ALTER TABLE hydra_oauth2_code ADD CONSTRAINT hydra_oauth2_code_challenge_id_fk F
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;

SET session_replication_role = DEFAULT;
-- This caused #1209:
-- SET session_replication_role = DEFAULT;

-- +migrate Down

Expand Down
Loading

0 comments on commit a455fdf

Please sign in to comment.