Load a structure.sql into a rails database via rake
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
Just use
rake db:setup
which will use either schema.rb
or structure.sql
depending on your configuration.
Use the database's own SQL load mechanism.
For Postgres this should work (at least if the database exists and you don't need a password):
psql -d databaseName < db/structure.sql
On Heroku where rake db:setup doesn't work as you can't create a database like that you can do this:
heroku pg:psql < db/structure.sql