Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

James Harker's Profile

GitHub User: jamesharker

Site: www.njtechnologies.co.uk

Comments by James Harker

Avatar

I eventually went with something like this. Works well for me.

ruby
  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
Avatar

Has anyone figured out how to do this if you're also using hstore?
I can't work out how to replace:

ruby
load Rails.root.join("db/schema.rb")

with a similar line that will load and execute the file db/structure.sql instead.