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

For Postgres, use constraint triggers? #1

Open
pjungwir opened this issue Sep 7, 2018 · 5 comments
Open

For Postgres, use constraint triggers? #1

pjungwir opened this issue Sep 7, 2018 · 5 comments

Comments

@pjungwir
Copy link
Collaborator

pjungwir commented Sep 7, 2018

I'm so glad that someone has already written a gem for this!

I was looking at your Postgres adapter code, and what do you think of using CREATE CONSTRAINT TRIGGER instead? That is how Postgres implements its own foreign keys, and it would let you do SET CONSTRAINTS on these like you can with regular foreign keys. It would require changing the triggers from BEFORE to AFTER, but that doesn't look like a problem to me.

Incidentally, you should technically have an UPDATE trigger on the same table as the DELETE trigger in case the primary key changes, although I understand that is unlikely to happen in a Rails app.

@musaffa
Copy link
Owner

musaffa commented Sep 7, 2018

I don't personally use this gem anymore. Polymorphism is an antipattern in database system design. We should use alternative solutions although they aren't very pleasant ones.

@pjungwir
Copy link
Collaborator Author

pjungwir commented Sep 7, 2018

Polymorphism is an antipattern in database system design.

I'm inclined to agree. :-) Still it is used by some handy gems, e.g. Rolify, and it would be nice to lock them down.

I don't personally use this gem anymore.

So do you mind if I fork it? I'm interested in adding database integrity to Rails projects. I wrote a gem myself for database constraints, and I've contributed to another. Forking would be a useful occasion for the change I've suggested here. I'd also like to update the gem for Rails 5.

@musaffa
Copy link
Owner

musaffa commented Sep 7, 2018

@pjungwir You can either fork it or I can add you as a maintainer of this gem.

@pjungwir
Copy link
Collaborator Author

pjungwir commented Sep 7, 2018

Okay, I'd be happy to help as a maintainer. That would be less disruptive for sure. Then for changing the constraint type we can just add a version bump.

@musaffa
Copy link
Owner

musaffa commented Sep 7, 2018

I've added you as a collaborator in this repository.

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

No branches or pull requests

2 participants