Reputation: 12214
In a Rails 3.2.3 application, I have a need to allow an administrator to create a database and populate it with tables from schema.rb.
Just executing the code in schema.rb is ideal. Basically, I am looking for a way to do:
rake db:setup
without using "rake".
I have several things I'd also like to do, such as back up a database, and I'm wondering if there's a Rails DSL I can work with or if I just need to write the SQL and run it through ActiveRecord::Base.connection.execute.
Thanks for any help you can offer.
Upvotes: 3
Views: 5236
Reputation: 1095
You can load it with 'load "path/to/schema.rb" and it will create the database from the current connection opened
Upvotes: 1
Reputation: 111
i do not know if i understand it right but
you can use seeds.rb so you can create table entries like:
Person.create(email: "[email protected]", firstname: "Tom", phone: "0049-0")
and then make a
rake db:seed
in the console
Upvotes: 0