From 20e041579f5fe9df51bdc40048cc1ef78915e116 Mon Sep 17 00:00:00 2001 From: Sammy Larbi Date: Wed, 26 Dec 2012 13:02:28 -0600 Subject: 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. --- .../migration/templates/create_table_migration.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb (limited to 'activerecord/lib/rails/generators/active_record/migration/templates') diff --git a/activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb b/activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb new file mode 100644 index 0000000000..3a3cf86d73 --- /dev/null +++ b/activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb @@ -0,0 +1,15 @@ +class <%= migration_class_name %> < ActiveRecord::Migration + def change + create_table :<%= table_name %> do |t| +<% attributes.each do |attribute| -%> + t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %> +<% end -%> +<% if options[:timestamps] %> + t.timestamps +<% end -%> + end +<% attributes_with_index.each do |attribute| -%> + add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %> +<% end -%> + end +end -- cgit v1.2.3