Make sure you view the (short) screencast by DHH
VERIFY: To enable full use of ruby schema support, uncomment ‘config.active_record.schema_format = :ruby’ in your /config/environment. (Update: The rails schema mechanism is the default as of Rails 1.1)
(run rake -T for most of this information as rake usage information)
Example schema.rb:
ActiveRecord::Schema.define(:version => 2) do
create_table "comments", :force => true do |t|
t.column "body", :text
t.column "post_id", :integer
end
create_table "posts", :force => true do |t|
t.column "title", :string
t.column "body", :text
t.column "created_at", :datetime
t.column "author_name", :string
t.column "comments_count", :integer, :default => 0
end
end
See the Rails API for details on these.
Example migration:
class UpdateUsersAndCreateProducts < ActiveRecord::Migration
def self.up
rename_column "users", "password", "hashed_password"
remove_column "users", "email"
create_table "products", :force => true do |t|
t.column "name", :text
t.column "description", :text
end
end
def self.down
rename_column "users", "hashed_password", "password"
add_column "users", "email"
drop_table "products"
end
end
Remember to be cautious of DB specific SQL!
ruby script/runner 'ActiveRecord::Base.connection.execute( "INSERT INTO schema_info (version) VALUES(0)")'
On OS X, I’m using TextMate with the syncPEOPLE on Rails v.0.9
TextMate Bundle. This provides the following…
(snipped from the release notes)
Snippets are small capsules of code that are activated by a key sequence followed by the [tab] key. For example, mcdt[tab] will activate the Migration Create and Drop Table snippet.
See Also Sami Samhuri’s information for a more complete description of these snippets
Published with Backpack. This page is subject to the terms of service.