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

Quote table names in generated SQL #41

Closed
ghost opened this issue Apr 15, 2015 · 6 comments
Closed

Quote table names in generated SQL #41

ghost opened this issue Apr 15, 2015 · 6 comments

Comments

@ghost
Copy link

ghost commented Apr 15, 2015

We have a table named "user". In Postgres this is a reserved word, so the following SQL generated by hair_trigger fails:

DROP TRIGGER IF EXISTS user_after_update_of_login_id_row_tr ON user;

This could be solved by escaping table names in all generated SQL (in the case of postgres, using double quotes):

DROP TRIGGER IF EXISTS user_after_update_of_login_id_row_tr ON "user";

@jenseng
Copy link
Owner

jenseng commented Apr 15, 2015

Cool, good catch. I'll try to get a fix up for this soon. The quoting part is easy, just need to make sure we match regenerated trigger definitions (now with quotes) to existing ones in the db (possibly without), so we can avoid mismatches ... be nice to have the actual create_trigger calls in schema.rb, instead of adapter-specific execute('CREATE TRIGGER..')

@ghost
Copy link
Author

ghost commented Apr 15, 2015

Great, thanks. In the mean time I worked around it by using a manual migration definition and quoting the table name like this:

create_trigger("user_after_insert_row_tr", compatibility: 1).
  on('"user"').
...

@jenseng
Copy link
Owner

jenseng commented Apr 28, 2015

@bsutherland note that once I push a gem and you upgrade to it, you'll probably want to go back and remove the quoting from your manual migration

@ghost
Copy link
Author

ghost commented Apr 28, 2015

@jenseng Thanks for the fixes!

@jenseng
Copy link
Owner

jenseng commented Apr 28, 2015

no problem, thanks for the bug reports 👍

@ghost
Copy link
Author

ghost commented Aug 14, 2015

@jenseng, I've upgraded to the latest version, and went back to remove the quoting, but I'm having trouble.

This was what I had (to workaround the issue)

create_trigger("user_after_update_of_login_id_row_tr", compatibility: 1).
      on('"user"').
 ...

With the new version, this gets double-quoted and fails (as expected).

But, when I change to:

on('user').

It doesn't get quoted at all! I took a look at the commit that fixed it, but I'm not really sure what's going on. Your help would be greatly appreciated!

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

1 participant