Skip to content

Commit

Permalink
Small fix for postgres database
Browse files Browse the repository at this point in the history
  • Loading branch information
forsaken1 committed Jan 15, 2015
1 parent f89d112 commit ce8c44e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rails-backup-migrate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def restore_db_from_yml

puts "Loading #{tbl}..." if VERBOSE
YAML.load_file("#{tbl}.yml").each do |fixture|
ActiveRecord::Base.connection.execute "INSERT INTO #{tbl} (#{fixture.keys.map{|k| "`#{k}`"}.join(",")}) VALUES (#{fixture.values.collect { |value| ActiveRecord::Base.connection.quote(value) }.join(",")})", 'Fixture Insert'
ActiveRecord::Base.connection.execute "INSERT INTO #{tbl} (#{fixture.keys.map{|k| "#{k}"}.join(",")}) VALUES (#{fixture.values.collect { |value| ActiveRecord::Base.connection.quote(value) }.join(",")})", 'Fixture Insert'
end
end
end
Expand Down

6 comments on commit ce8c44e

@mattconnolly
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backticks are valid syntax in MySQL which was my original use case. Is there a way you can detect Postgres and conditionally do this?

@forsaken1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was a quick solution for mattconnolly#15 ...

@mattconnolly
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'm sorry that I didn't have better postgres support - it wasn't my use case when I started the project.

To move forward I would like to see both supported. I have seen use cases where the backticks are needed for MySQL. See if you can use this in there:

fixtures.keys.map { |k| ActiveRecord::Base.connection.quote_column_name(k) }…

@mattconnolly
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... that way the column escaping is done by the rails driver which might work for everyone!

@forsaken1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I hurried with pull request, before, when I was writing on a clean sql (mysql) and didn't use backtricks.. I think it's better to cancel this pull request

@kbighorse
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a recommended solution here I can help contribute?

Please sign in to comment.