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

hair trigger should drop raw triggers before creating in schema.rb #27

Closed
jenseng opened this issue Mar 30, 2014 · 4 comments
Closed

hair trigger should drop raw triggers before creating in schema.rb #27

jenseng opened this issue Mar 30, 2014 · 4 comments
Labels

Comments

@jenseng
Copy link
Owner

jenseng commented Mar 30, 2014

Spawned from discussion #26 ... in schema.rb, although create_trigger will drop the existing trigger first (if it exists), that is not the case for raw execute "CREATE TRIGGER..." calls that it does. Because of this, if you have any triggers that don't correspond to a create_trigger in a migration, schema.rb cannot be used to update an existing test database (à la rake db:test:prepare), only an empty one.

For any adapter-specific execute "CREATE TRIGGER..." calls, HairTrigger should first do a DROP TRIGGER IF EXISTS call

@jenseng jenseng changed the title hair trigger should drop triggers before creating in schema.rb hair trigger should drop raw triggers before creating in schema.rb Mar 30, 2014
@jenseng jenseng added the bug label Mar 30, 2014
@jenseng
Copy link
Owner Author

jenseng commented Mar 31, 2014

@sshaw can you provide a little more info on how you're getting duplicate trigger errors from the execute "CREATE TRIGGER..." calls in schema.rb (per your comments on #26)? I have a fix, but am unable to actually reproduce the problem on the current code. I'd like to truly verify it fixes the problem you're seeing.

I've got a vanilla Rails app and have been testing it under MySQL, Postgres and SQLite. Some findings:

  1. db:test:prepare drops the db before doing a db:schema:load, so any triggers are wiped out long before schema.rb adds any
  2. db:schema:load doesn't drop the db, but it does drop every table (due to force: true). When a table is dropped, any triggers on it are dropped automatically as well. I've verified this under all three adapters.

Any info you can provide would be helpful (which rake command you run, other gems that might be affecting things, database you're using, etc.)

@sshaw
Copy link

sshaw commented Apr 1, 2014

Yes, I had trouble reproducing it too... Let me have a look at the app that was causing the problem, I'll get back to you.

@sshaw
Copy link

sshaw commented Apr 4, 2014

It turns out that some code I had added to deal with triggers before I found your gem was causing the problem. Sorry for the runaround... 🙊

@jenseng
Copy link
Owner Author

jenseng commented Apr 4, 2014

haha, no worries. thanks for all the other good info and pointers 👍

@jenseng jenseng closed this as completed Apr 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants