toastyapps-migratory 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/testtask'
3
3
 
4
4
  gem_spec = Gem::Specification.new do |gem_spec|
5
5
  gem_spec.name = 'migratory'
6
- gem_spec.version = '0.0.5'
6
+ gem_spec.version = '0.0.6'
7
7
  gem_spec.summary = 'Rails migration extender for default values and adding indexes'
8
8
  gem_spec.description = 'Rails migration extender for default values and adding indexes'
9
9
  gem_spec.email = 'matt@toastyapps.com'
@@ -0,0 +1,29 @@
1
+ Description:
2
+ Stubs out a new database migration. Pass the migration name, either
3
+ CamelCased or under_scored, and an optional list of attribute pairs as arguments.
4
+
5
+ A migration class is generated in db/migrate prefixed by a timestamp of the current date and time.
6
+
7
+ You can name your migration in either of these formats to generate add/remove
8
+ column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable
9
+
10
+ Example:
11
+ `./script/generate migration AddSslFlag`
12
+
13
+ If the current date is May 14, 2008 and the current time 09:09:12, this creates the AddSslFlag migration
14
+ db/migrate/20080514090912_add_ssl_flag.rb
15
+
16
+ `./script/generate migration AddTitleBodyToPost title:string body:text published:boolean`
17
+
18
+ This will create the AddTitleBodyToPost in db/migrate/20080514090912_add_title_body_to_post.rb with
19
+ this in the Up migration:
20
+
21
+ add_column :posts, :title, :string
22
+ add_column :posts, :body, :text
23
+ add_column :posts, :published, :boolean
24
+
25
+ And this in the Down migration:
26
+
27
+ remove_column :posts, :published
28
+ remove_column :posts, :body
29
+ remove_column :posts, :title
@@ -0,0 +1,23 @@
1
+ require 'migratory/generated_attribute'
2
+ require 'migratory/named_base'
3
+
4
+ class MigrationGenerator < Rails::Generator::NamedBase
5
+ def manifest
6
+ record do |m|
7
+ m.migration_template 'migration.rb', 'db/migrate', :assigns => get_local_assigns
8
+ end
9
+ end
10
+
11
+
12
+ private
13
+ def get_local_assigns
14
+ returning(assigns = {}) do
15
+ if class_name.underscore =~ /^(add|remove)_.*_(?:to|from)_(.*)/
16
+ assigns[:migration_action] = $1
17
+ assigns[:table_name] = $2.pluralize
18
+ else
19
+ assigns[:attributes] = []
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ class <%= class_name.underscore.camelize %> < ActiveRecord::Migration
2
+ def self.up<% attributes.each do |attribute| %>
3
+ <%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><%= attribute.options %><% end -%>
4
+ <% for attribute in attributes -%><% if attribute.is_indexed -%>
5
+ add_index :<%= attribute.name %>
6
+ <% end -%><% end -%>
7
+ <%- end %>
8
+ end
9
+
10
+ def self.down<% attributes.reverse.each do |attribute| %>
11
+ <%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><% end -%>
12
+ <%- end %>
13
+ end
14
+ end
15
+
@@ -0,0 +1,27 @@
1
+ Description:
2
+ Stubs out a new model. Pass the model name, either CamelCased or
3
+ under_scored, and an optional list of attribute pairs as arguments.
4
+
5
+ Attribute pairs are column_name:sql_type arguments specifying the
6
+ model's attributes. Timestamps are added by default, so you don't have to
7
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
8
+
9
+ You don't have to think up every attribute up front, but it helps to
10
+ sketch out a few so you can start working with the model immediately.
11
+
12
+ This generates a model class in app/models, a unit test in test/unit,
13
+ a test fixture in test/fixtures/singular_name.yml, and a migration in
14
+ db/migrate.
15
+
16
+ Examples:
17
+ `./script/generate model account`
18
+
19
+ creates an Account model, test, fixture, and migration:
20
+ Model: app/models/account.rb
21
+ Test: test/unit/account_test.rb
22
+ Fixtures: test/fixtures/accounts.yml
23
+ Migration: db/migrate/XXX_add_accounts.rb
24
+
25
+ `./script/generate model post title:string body:text published:boolean`
26
+
27
+ creates a Post model with a string title, text body, and published flag.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toastyapps-migratory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Mongeau
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-02 21:00:00 -07:00
12
+ date: 2009-08-08 21:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -25,6 +25,11 @@ files:
25
25
  - MIT-LICENSE
26
26
  - Rakefile
27
27
  - README.textile
28
+ - generators/migration
29
+ - generators/migration/migration_generator.rb
30
+ - generators/migration/templates
31
+ - generators/migration/templates/migration.rb
32
+ - generators/migration/USAGE
28
33
  - generators/model
29
34
  - generators/model/model_generator.rb
30
35
  - generators/model/templates
@@ -32,6 +37,7 @@ files:
32
37
  - generators/model/templates/migration.rb
33
38
  - generators/model/templates/model.rb
34
39
  - generators/model/templates/unit_test.rb
40
+ - generators/model/USAGE
35
41
  - lib/migratory
36
42
  - lib/migratory/generated_attribute.rb
37
43
  - lib/migratory/named_base.rb