RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: jamesharker
Site: www.njtechnologies.co.uk
I eventually went with something like this. Works well for me.
def create_schema() original_search_path = connection.schema_search_path connection.execute("create schema tennant#{id}") connection.schema_search_path = "tennant#{id},public" structure_sql = open("#{Rails.root}/db/structure.sql", 'r').read structure_sql = structure_sql.gsub("SET search_path = public, pg_catalog;", "") # Remove line from SQL dump file connection.execute(structure_sql) connection.execute("drop table my_table") ensure return connection.schema_search_path = original_search_path end
Thanks for the tip.
Has anyone figured out how to do this if you're also using hstore? I can't work out how to replace:
load Rails.root.join("db/schema.rb")
with a similar line that will load and execute the file db/structure.sql instead.
db/structure.sql
I eventually went with something like this. Works well for me.
Thanks for the tip.
Has anyone figured out how to do this if you're also using hstore?
I can't work out how to replace:
with a similar line that will load and execute the file
db/structure.sql
instead.