aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-03-01 04:23:21 -0800
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-03-01 04:23:21 -0800
commitb49a2a779ba6deba108d1f842ab5b7bc7460aa14 (patch)
treedadb0c23877b488daef2e5896c4193213a5b91a0 /guides
parentbb9f8312e7fe31566b898f87be149b13daf4dc57 (diff)
parent20e041579f5fe9df51bdc40048cc1ef78915e116 (diff)
downloadrails-b49a2a779ba6deba108d1f842ab5b7bc7460aa14.tar.gz
rails-b49a2a779ba6deba108d1f842ab5b7bc7460aa14.tar.bz2
rails-b49a2a779ba6deba108d1f842ab5b7bc7460aa14.zip
Merge pull request #8652 from codeodor/create_table_migration
Support creating a table migration generator Sometimes you want to create a table without an associated model and test, which is also not a join table. With this commit, you can now do that. Example: rails g migration create_posts title:string or rails g migration CreatePosts title:string This commit also moves the template the model generator uses for the migration to the migration templates folder, as it seems a more sensible place for it now that it is shared code.
Diffstat (limited to 'guides')
-rw-r--r--guides/source/migrations.md21
1 files changed, 21 insertions, 0 deletions
diff --git a/guides/source/migrations.md b/guides/source/migrations.md
index d738d847e9..89ae564c24 100644
--- a/guides/source/migrations.md
+++ b/guides/source/migrations.md
@@ -179,6 +179,27 @@ class AddDetailsToProducts < ActiveRecord::Migration
end
```
+If the migration name is of the form "CreateXXX" and is
+followed by a list of column names and types then a migration creating the table
+XXX with the columns listed will be generated. For example:
+
+```bash
+$ rails generate migration CreateProducts name:string part_number:string
+```
+
+generates
+
+```ruby
+class CreateProducts < ActiveRecord::Migration
+ def change
+ create_table :products do |t|
+ t.string :name
+ t.string :part_number
+ end
+ end
+end
+```
+
As always, what has been generated for you is just a starting point. You can add
or remove from it as you see fit by editing the
`db/migrate/YYYYMMDDHHMMSS_add_details_to_products.rb` file.