Skip to content

Commit

Permalink
Updated README and corrected some description lines that said DATABAS…
Browse files Browse the repository at this point in the history
…E_ENV instead of DB and fixed the description line for the generate task
  • Loading branch information
rberger committed Jun 5, 2011
1 parent a254066 commit b7ff503
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
32 changes: 31 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Add database configuration to `db/config.yml` in your projects base directory e.

... and fill in the up and down migrations [Cheatsheet](http://dizzy.co.uk/ruby_on_rails/cheatsheets/rails-migrations).

If you're lazy and want to just execute raw SQL:
#### If you really want to, you can just execute raw SQL:

def self.up
execute "insert into foo values (123,'something');"
Expand All @@ -64,6 +64,35 @@ If you're lazy and want to just execute raw SQL:
execute "delete from foo where field='something';"
end

#### Even better, you can use the _generate_ task to create the initial migration ####

The general form is:

rake db:generate model="model_name" fields="type:column_name0 type:column_name1 ... type:column_namen"

You can have as many fields as you would like.

An example to create a Person table with 3 columns (and it will automatically add the t.timestamps line)

rake db:generate model="Person" fields="string:first_name string:last_name integer:age"

This will create a migration in db/migrations/

class CreatePerson < ActiveRecord::Migration
def self.up
create_table :Person do |t|
t.string :first_name
t.string :last_name
t.integer :age
t.timestamps
end
end

def self.down
drop_table :Person
end
end

### To apply your newest migration:

rake db:migrate
Expand Down Expand Up @@ -111,3 +140,4 @@ This work is based on [Lincoln Stoll's blog post](http://lstoll.net/2008/04/stan
- [Steve Hodgkiss](http://stevehodgkiss.com/)
- [Rich Meyers](https://github.com/richmeyers)
- [Wes Bailey](http://exposinggotchas.blogspot.com/)
- [Robert J. Berger](http://blog.ibd.com/)
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.8
0.4.9
6 changes: 3 additions & 3 deletions lib/tasks/standalone_migrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def create_database(config)
end
end

desc 'Create the database from config/database.yml for the current DATABASE_ENV'
desc 'Create the database from config/database.yml for the current DB'
task :create do
ar_init(false)
config = ActiveRecord::Base.configurations[self.current_env]
Expand All @@ -180,7 +180,7 @@ def drop_database(config)
end
end

desc 'Drops the database for the current DATABASE_ENV'
desc 'Drops the database for the current DB'
task :drop => :ar_init do
config = ActiveRecord::Base.configurations[current_env]
drop_database(config)
Expand Down Expand Up @@ -289,7 +289,7 @@ def drop_database(config)
task :prepare => ["db:#{sub_namespace_with_separator}abort_if_pending_migrations", "db:#{sub_namespace_with_separator}test:load"]
end

desc 'generate a model=name field="field1:type field2:type"'
desc 'generate a model=name field="type:column_name0 type:column_name1 ... type:column_namen"'
task :generate do
ts = Time.now.strftime '%Y%m%d%H%%M%S'

Expand Down

0 comments on commit b7ff503

Please sign in to comment.