Load a structure.sql into a rails database via rake

locoboy picture locoboy · Apr 15, 2014 · Viewed 26.1k times · Source

rake db:schema:load will load a schema.rb file into a rails database. Is there a way to load a structure.sql file into the database through rake or do I just need to do this manually?

Answer

Tsutomu picture Tsutomu · Sep 15, 2014

Use rake db:structure:load, which will load db/structure.sql.

[Update]

If you want to load another file, you can specify its path via

  • SCHEMA environment variable (Rails 5.0 or later)
  • DB_STRUCTURE environment variable (Rails 4.x)

For example, run

rake db:structure:load SCHEMA=db/another.sql

or

rake db:structure:load DB_STRUCTURE=db/another.sql