Alex
Alex

Reputation: 36101

Rails: How to create database schema with ActiveRecord::Schema like in django?

I like Rails, but I'm not a big fan of migrations.

How can I use the ActiveRecord::Scema tool to create a database without using SQL and without migrations?

I know you use it like this:

ActiveRecord::Schema.define do
    create_table :authors do |t|
        t.string :name, :null => false
    end

    add_index :authors, :name, :unique

    create_table :posts do |t|
        t.integer :author_id, :null => false
        t.string :subject
        t.text :body
        t.boolean :private, :default => false
    end

    add_index :posts, :author_id
end

But how do you run this?

Please don't recommend to use migrations, because I... simply don't like them.

Upvotes: 3

Views: 1199

Answers (2)

Damien MATHIEU
Damien MATHIEU

Reputation: 32629

Well migrations are the best way to manage the evolutions of your database ;)

However you can directly load a schema.rb into your database if you wish to.

rake db:schema:load

I wouldn't recomment it however.

Upvotes: 3

stephenmurdoch
stephenmurdoch

Reputation: 34603

try rake db:schema:load

Upvotes: 2

Related Questions