Created
December 13, 2012 21:34
-
-
Save leklund/4280172 to your computer and use it in GitHub Desktop.
How to create a schema other than public when running rake db:setup. This will allow you to include a schema_searth_path in database.yml without causing rake db:setup to fail.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SCHEMA_NAMES = %w(foo bar) | |
namespace :db do | |
task :create do | |
config = Rails.configuration.database_configuration[Rails.env].merge!({'schema_search_path' => 'public'}) | |
ActiveRecord::Base.establish_connection(config) | |
SCHEMA_NAMES.each do |schema| | |
ActiveRecord::Base.connection.execute("CREATE SCHEMA #{schema}") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great example. I'll use that snippet. Thanks.
Maybe you should set the Authorization too. Ex:
"CREATE SCHEMA "#{schema_name}" AUTHORIZATION "#{pg_username}""
Just in case you need the owner to be another user other than postgres