Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing "on delete" directive on oic_sessions foreign key #62

Closed
rmdir opened this issue Mar 7, 2022 · 1 comment · Fixed by #63
Closed

Missing "on delete" directive on oic_sessions foreign key #62

rmdir opened this issue Mar 7, 2022 · 1 comment · Fixed by #63

Comments

@rmdir
Copy link
Contributor

rmdir commented Mar 7, 2022

Hi,
With postgres, when deleting a user added via OIC, I get an error

update or delete on table "users" violates foreign key constraint "fk_rails_fb3c08edd2" on table "oic_sessions"

An on delete casacde on the foreign key fix the issue


alter table oic_sessions drop constraint fk_rails_fb3c08edd2;
alter table oic_sessions add constraint fk_rails_fb3c08edd2 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


Many thanks
Joris

Redmine version 4.2.4.stable
Ruby version 2.7.5-p203 (2021-11-24) [x86_64-linux]
Rails version 5.2.6.2
Database adapter PostgreSQL
redmine_openid_connect 0.9.4

@rmdir
Copy link
Contributor Author

rmdir commented Mar 7, 2022

This patch does the job

diff --git a/db/migrate/001_create_oic_sessions.rb b/db/migrate/001_create_oic_sessions.rb
index 286402d..a509e8a 100644
--- a/db/migrate/001_create_oic_sessions.rb
+++ b/db/migrate/001_create_oic_sessions.rb
@@ -1,7 +1,7 @@
 class CreateOicSessions < ActiveRecord::Migration[4.2]
   def self.up
     create_table :oic_sessions do |t|
-      t.references :user, foreign_key: true
+      t.references :user, foreign_key: {on_delete: :cascade}
       t.text :code
       t.string :state
       t.string :nonce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant