Skip to content

Instantly share code, notes, and snippets.

@maciejkowalski
Created March 21, 2014 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maciejkowalski/9685944 to your computer and use it in GitHub Desktop.
Save maciejkowalski/9685944 to your computer and use it in GitHub Desktop.
Add PostgreSQL Hstore extension to structure.sql (HACK
namespace :db do
namespace :structure do
task :add_hstore_extension do
puts "HACK! Adding `CREATE EXTENSION hstore SCHEMA hstore;` to structure.sql (see db_strucute_dump.rake)"
structure_dump = Rails.root + "db/structure.sql"
new_structure_dump = Rails.root + "db/new_structure.sql"
new_file = File.open(new_structure_dump, 'w')
existing = File.open(structure_dump)
existing.each do |line|
new_file << line
if line == "CREATE SCHEMA hstore;\n"
new_file << "CREATE EXTENSION hstore SCHEMA hstore;"
end
end
existing.close
new_file.close
FileUtils.mv(new_structure_dump, structure_dump)
end
end
end
Rake::Task["db:structure:dump"].enhance do
Rake::Task["db:structure:add_hstore_extension"].invoke
end
@maciejkowalski
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment