Is there a way to use schema.rb to create a database from inside Rails?

In a Rails 3.2.3 application, I need to allow an administrator to create a database and populate it with tables from schema.rb.

Simple code execution in schema.rb is ideal. Basically, I'm looking for a way to do:

rake db:setup

without using rake.

I have a few things that I would also like to do, such as backing up the database, and I wonder if there is a Rails DSL that I can work with, or just need to write SQL and run it through ActiveRecord :: Base .connection.execute.

Thanks for any help you can offer.

+3
source share
4 answers

:

 system("rake db:setup")
+5
rake db:setup
rake db:schema:load 

( ) schema.rb . rake, sql .

backup gem .

+2

, ,

seeds.rb :

Person.create(email: "tom@mail.com", firstname: "Tom", phone: "0049-0")

rake db:seed

+1

"load" path/to/schema.rb ", .

0

All Articles