migrant 0.2.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- migrant (0.2.3)
4
+ migrant (0.2.4)
5
5
  migrant
6
6
  rails
7
7
 
@@ -36,7 +36,7 @@ GEM
36
36
  activesupport (= 3.0.4)
37
37
  activesupport (3.0.4)
38
38
  ansi (1.2.2)
39
- arel (2.0.8)
39
+ arel (2.0.9)
40
40
  builder (2.1.2)
41
41
  erubis (2.6.6)
42
42
  abstract (>= 1.0.0)
@@ -2,19 +2,28 @@
2
2
 
3
3
  == Summary
4
4
 
5
- Migrant gives you a clean DSL to describe your database schema (somewhat similar to DataMapper)
6
- and generates all your migrations for you so you can spend more time coding the tricky stuff!
5
+ Migrant gives you a clean DSL to describe your model schema (somewhat similar to DataMapper)
6
+ that generates your migrations for you and enables you to spend more time on describing your domain
7
+ model cleanly and less time managing your database layer.
7
8
 
8
9
  You'll also get a handy .mock method to instantiate a filled in model for testing or debugging purposes.
9
10
 
10
11
  == Getting Started
11
12
 
12
- Only for Rails 3 and Ruby 1.9+ folks. Simply install the gem "migrant", or add it to your bundler Gemfile
13
+ In your Gemfile:
14
+
15
+ gem "migrant"
16
+
17
+ Rails: 3.0+ (Sorry folks, no plans for Rails 2 support)
18
+ Ruby: Tested with 1.8.7 MRI, 1.9.2 MRI, and Rubinius 1.2.1
19
+ Adapters: Tested with SQLite3, MySQL, MySQL2, Pg. Should work with any AR adapter in theory.
13
20
 
14
21
  == Jumping right in
15
22
 
16
23
  Start by creating some models with the structure you need:
17
24
 
25
+ > rails generate migrant:model business
26
+
18
27
  class Business < ActiveRecord::Base
19
28
  belongs_to :user
20
29
 
@@ -27,8 +36,9 @@ Start by creating some models with the structure you need:
27
36
  end
28
37
  end
29
38
 
30
- The best and easiest way is to provide example data and then Migrant will work out the appropriate
31
- column type for you. Another example covering some more bases:
39
+ Simply specify an example of the type of data you'll be storing, and Migrant will work out the
40
+ correct database schema for you. Note that you don't need to specify foreign keys in the structure,
41
+ they are automatically inferred from your relations. Here is a further example:
32
42
 
33
43
  class User < ActiveRecord::Base
34
44
  has_many :businesses
@@ -38,9 +48,12 @@ column type for you. Another example covering some more bases:
38
48
  surname "Smith", :validates => :presence # You can add your validations in here too to keep DRY
39
49
  description :string # Passing a symbol works like it does in add_column
40
50
  timestamps # Gets you a created_at, and updated_at
51
+
52
+ # Use an array to specifiy multiple validations
53
+ secret_code 5521, :validates => [:uniqueness, :numericality]
41
54
  end
42
55
  end
43
-
56
+
44
57
  Now, to get your database up to date simply run:
45
58
 
46
59
  > rake db:upgrade
@@ -64,15 +77,26 @@ By default, your database structure will be cloned to your test environment. If
64
77
  automatically, simply specify an environment variable directly:
65
78
 
66
79
  > rake db:upgrade RAILS_ENV=development
67
-
80
+
68
81
  == Want more examples?
69
82
 
70
83
  Check out the test models in test/rails_app/app/models/*
71
84
 
85
+ == Model Generator
86
+
87
+ > rails generate migrant:model business name:string website:text
88
+
89
+ The model generator works as per the default ActiveRecord one, i.e. you can specify
90
+ fields to be included in the model. However, a migration is not generated immediately,
91
+ but the structure block in the model is automatically filled out for you.
92
+
93
+ Simply run rake db:upgrade or rails generate migrations to get the required migrations when you're ready.
94
+
72
95
  == What will happen seamlessly
73
96
 
74
97
  * Creating tables or adding columns (as appropriate)
75
98
  * Adding indexes (happens on foreign keys automatically)
99
+ * Validations (ActiveRecord 3)
76
100
  * Changing column types
77
101
  * Rollbacks for all the above
78
102
 
@@ -101,13 +125,12 @@ These actions won't be performed (because we don't want to hurt your data):
101
125
  * It's probably a good idea to review the generated migrations before committing to SCM, just to check there's nothing left out.
102
126
 
103
127
  == Roadmap / Planned features
104
- * To be implemented very soon - A :was => [:this,:then,:that] option to rename columns and add an alias method onto models (so as to not break existing code)
105
128
  * Rake task to consolidate a given set of migrations (a lot of people like to do this once in a while to keep migration levels sane)
106
- * Fabricator/Factory integration/seperation
129
+ * Fabricator/Factory integration/seperation - Need to assess how useful this is, then optimize or kill.
107
130
 
108
131
  == License
109
132
 
110
- Copyright (c) 2010 Pascal Houliston
133
+ Copyright (c) 2011 Pascal Houliston
111
134
 
112
135
  Permission is hereby granted, free of charge, to any person obtaining
113
136
  a copy of this software and associated documentation files (the
@@ -130,7 +153,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
130
153
 
131
154
  == Development
132
155
 
133
- Please be sure to install all the development dependencies from the gemspec, then to run tests do:
156
+ Please be sure to install all the development dependencies via Bundler, then to run tests do:
134
157
 
135
158
  > rake test
136
159
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 1.0.0
@@ -0,0 +1,24 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module Migrant
4
+ class Model < ActiveRecord::Generators::Base
5
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
6
+ desc "The migrant:model generator creates a skeleton ActiveRecord model for use with Migrant."
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ def create_model_file
10
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
11
+ end
12
+
13
+ hook_for :test_framework
14
+
15
+ def protip
16
+ puts "\nNow, go and edit app/models/#{file_name}.rb and/or generate more models, then run 'rake db:upgrade' to generate your schema."
17
+ end
18
+
19
+ protected
20
+ def parent_class_name
21
+ options[:parent] || "ActiveRecord::Base"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ class <%= class_name %> < <%= parent_class_name.classify %>
2
+ <% attributes.select {|attr| attr.reference? }.each do |attribute| -%>
3
+ belongs_to :<%= attribute.name %>
4
+ <% end -%>
5
+ structure do
6
+ <% unless attributes.blank?
7
+ max_field_length = attributes.collect { |attribute| attribute.name.to_s}.max { |name| name.length }.length
8
+ attributes.reject { |attr| attr.reference? }.each do |attribute| -%>
9
+ <%= attribute.name.to_s.ljust(max_field_length) %> :<%= attribute.type %>
10
+ <% end
11
+ end -%>
12
+ end
13
+ end
14
+
@@ -1,5 +1,4 @@
1
1
  require 'active_support'
2
- #require 'active_support/core_ext/class/attribute_accessors'
3
2
  require 'active_record'
4
3
  require 'datatype/base'
5
4
  require 'migrant/schema'
@@ -1,3 +1,5 @@
1
+ require 'simple_object'
2
+
1
3
  module Migrant
2
4
  # Converts the following DSL:
3
5
  #
@@ -10,6 +10,7 @@ module Migrant
10
10
 
11
11
  generators do
12
12
  load "generators/migrations.rb"
13
+ load "generators/model.rb"
13
14
  end
14
15
  end
15
16
  end
@@ -0,0 +1,13 @@
1
+
2
+ # Little patch for Ruby 1.8 to give it BasicObject support
3
+ unless defined?(BasicObject)
4
+ class BasicObject
5
+ KEEP_METHODS = %w"__id__ __send__ instance_eval == equal? initialize"
6
+
7
+ def self.remove_methods!
8
+ m = (private_instance_methods + instance_methods) - KEEP_METHODS
9
+ m.each{|m| undef_method(m)}
10
+ end
11
+ remove_methods!
12
+ end
13
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{migrant}
8
- s.version = "0.2.4"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Pascal Houliston"]
12
- s.date = %q{2011-02-15}
12
+ s.date = %q{2011-02-26}
13
13
  s.description = %q{Migrant gives you a super-clean DSL to describe your ActiveRecord models (somewhat similar to DataMapper) and generates all your migrations for you so you can spend more time coding the stuff that counts!}
14
14
  s.email = %q{101pascal@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -36,11 +36,14 @@ Gem::Specification.new do |s|
36
36
  "lib/datatype/symbol.rb",
37
37
  "lib/datatype/time.rb",
38
38
  "lib/generators/migrations.rb",
39
+ "lib/generators/model.rb",
40
+ "lib/generators/templates/model.rb",
39
41
  "lib/migrant.rb",
40
42
  "lib/migrant/migration_generator.rb",
41
43
  "lib/migrant/model_extensions.rb",
42
44
  "lib/migrant/schema.rb",
43
45
  "lib/railtie.rb",
46
+ "lib/simple_object.rb",
44
47
  "lib/tasks/db.rake",
45
48
  "migrant.gemspec",
46
49
  "test/additional_models/review.rb",
@@ -176,6 +179,13 @@ Gem::Specification.new do |s|
176
179
  s.add_development_dependency(%q<turn>, [">= 0"])
177
180
  s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
178
181
  s.add_development_dependency(%q<simplecov>, [">= 0"])
182
+ s.add_development_dependency(%q<bundler>, [">= 0"])
183
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
184
+ s.add_development_dependency(%q<ansi>, [">= 0"])
185
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
186
+ s.add_development_dependency(%q<turn>, [">= 0"])
187
+ s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
188
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
179
189
  s.add_runtime_dependency(%q<rails>, [">= 0"])
180
190
  else
181
191
  s.add_dependency(%q<migrant>, [">= 0"])
@@ -214,6 +224,13 @@ Gem::Specification.new do |s|
214
224
  s.add_dependency(%q<turn>, [">= 0"])
215
225
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
216
226
  s.add_dependency(%q<simplecov>, [">= 0"])
227
+ s.add_dependency(%q<bundler>, [">= 0"])
228
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
229
+ s.add_dependency(%q<ansi>, [">= 0"])
230
+ s.add_dependency(%q<jeweler>, [">= 0"])
231
+ s.add_dependency(%q<turn>, [">= 0"])
232
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
233
+ s.add_dependency(%q<simplecov>, [">= 0"])
217
234
  s.add_dependency(%q<rails>, [">= 0"])
218
235
  end
219
236
  else
@@ -253,6 +270,13 @@ Gem::Specification.new do |s|
253
270
  s.add_dependency(%q<turn>, [">= 0"])
254
271
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
255
272
  s.add_dependency(%q<simplecov>, [">= 0"])
273
+ s.add_dependency(%q<bundler>, [">= 0"])
274
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
275
+ s.add_dependency(%q<ansi>, [">= 0"])
276
+ s.add_dependency(%q<jeweler>, [">= 0"])
277
+ s.add_dependency(%q<turn>, [">= 0"])
278
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
279
+ s.add_dependency(%q<simplecov>, [">= 0"])
256
280
  s.add_dependency(%q<rails>, [">= 0"])
257
281
  end
258
282
  end
@@ -5,6 +5,7 @@ SimpleCov.adapters.define 'migrant' do
5
5
  add_filter '/test'
6
6
  add_filter '/lib/tasks'
7
7
  add_filter '/lib/railtie' # Not covering lines it's running here .. disabling for now
8
+ add_filter '/lib/simple_object'
8
9
 
9
10
  add_group 'Core Extensions', '/lib/migrant'
10
11
  add_group 'Schema Data Types', '/lib/datatype'
@@ -13,10 +13,12 @@ class TestMigrationGenerator < Test::Unit::TestCase
13
13
  assert_equal true, Migrant::MigrationGenerator.new.run, "Migration Generator reported an error"
14
14
  Dir.glob(File.join(File.dirname(__FILE__), 'rails_app', 'db' ,'migrate', '*.rb')).each do |migration_file|
15
15
  if migration_file.include?(template)
16
- correct = File.join(File.dirname(__FILE__), 'verified_output', 'migrations', template+'.rb')
17
- assert_equal(File.open(correct, 'r') { |r| r.read}.strip,
18
- File.open(migration_file, 'r') { |r| r.read}.strip,
19
- "Generated migration #{migration_file} does not match template #{correct}")
16
+ to_test = File.open(migration_file, 'r') { |r| r.read}.strip
17
+ File.open(File.join(File.dirname(__FILE__), 'verified_output', 'migrations', template+'.rb'), 'r') do |file|
18
+ while (line = file.gets)
19
+ assert_not_nil(to_test.match(line.strip), "Generated migration #{migration_file} missing line: #{line}")
20
+ end
21
+ end
20
22
  rake_migrate
21
23
  return
22
24
  end
@@ -28,10 +30,12 @@ class TestMigrationGenerator < Test::Unit::TestCase
28
30
  should "create migrations for all new tables" do
29
31
  assert_equal true, Migrant::MigrationGenerator.new.run, "Migration Generator reported an error"
30
32
  Dir.glob(File.join(File.dirname(__FILE__), 'rails_app', 'db' ,'migrate', '*.rb')).each do |migration_file|
31
- correct = File.join(File.dirname(__FILE__), 'verified_output', 'migrations', migration_file.sub(/^.*\d+_/, ''))
32
- assert_equal(File.open(correct, 'r') { |r| r.read}.strip,
33
- File.open(migration_file, 'r') { |r| r.read}.strip,
34
- "Generated migration #{migration_file} does not match template #{correct}")
33
+ to_test = File.open(migration_file, 'r') { |r| r.read}.strip
34
+ File.open(File.join(File.dirname(__FILE__), 'verified_output', 'migrations', migration_file.sub(/^.*\d+_/, '')), 'r') do |file|
35
+ while (line = file.gets)
36
+ assert_not_nil(to_test.match(line.strip), "Generated migration #{migration_file} missing line: #{line}")
37
+ end
38
+ end
35
39
  end
36
40
  rake_migrate
37
41
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: migrant
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.4
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Pascal Houliston
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-15 00:00:00 +00:00
13
+ date: 2011-02-26 00:00:00 +00:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -410,16 +410,93 @@ dependencies:
410
410
  prerelease: false
411
411
  version_requirements: *id036
412
412
  - !ruby/object:Gem::Dependency
413
- name: rails
413
+ name: bundler
414
414
  requirement: &id037 !ruby/object:Gem::Requirement
415
415
  none: false
416
416
  requirements:
417
417
  - - ">="
418
418
  - !ruby/object:Gem::Version
419
419
  version: "0"
420
- type: :runtime
420
+ type: :development
421
421
  prerelease: false
422
422
  version_requirements: *id037
423
+ - !ruby/object:Gem::Dependency
424
+ name: thoughtbot-shoulda
425
+ requirement: &id038 !ruby/object:Gem::Requirement
426
+ none: false
427
+ requirements:
428
+ - - ">="
429
+ - !ruby/object:Gem::Version
430
+ version: "0"
431
+ type: :development
432
+ prerelease: false
433
+ version_requirements: *id038
434
+ - !ruby/object:Gem::Dependency
435
+ name: ansi
436
+ requirement: &id039 !ruby/object:Gem::Requirement
437
+ none: false
438
+ requirements:
439
+ - - ">="
440
+ - !ruby/object:Gem::Version
441
+ version: "0"
442
+ type: :development
443
+ prerelease: false
444
+ version_requirements: *id039
445
+ - !ruby/object:Gem::Dependency
446
+ name: jeweler
447
+ requirement: &id040 !ruby/object:Gem::Requirement
448
+ none: false
449
+ requirements:
450
+ - - ">="
451
+ - !ruby/object:Gem::Version
452
+ version: "0"
453
+ type: :development
454
+ prerelease: false
455
+ version_requirements: *id040
456
+ - !ruby/object:Gem::Dependency
457
+ name: turn
458
+ requirement: &id041 !ruby/object:Gem::Requirement
459
+ none: false
460
+ requirements:
461
+ - - ">="
462
+ - !ruby/object:Gem::Version
463
+ version: "0"
464
+ type: :development
465
+ prerelease: false
466
+ version_requirements: *id041
467
+ - !ruby/object:Gem::Dependency
468
+ name: sqlite3-ruby
469
+ requirement: &id042 !ruby/object:Gem::Requirement
470
+ none: false
471
+ requirements:
472
+ - - ">="
473
+ - !ruby/object:Gem::Version
474
+ version: "0"
475
+ type: :development
476
+ prerelease: false
477
+ version_requirements: *id042
478
+ - !ruby/object:Gem::Dependency
479
+ name: simplecov
480
+ requirement: &id043 !ruby/object:Gem::Requirement
481
+ none: false
482
+ requirements:
483
+ - - ">="
484
+ - !ruby/object:Gem::Version
485
+ version: "0"
486
+ type: :development
487
+ prerelease: false
488
+ version_requirements: *id043
489
+ - !ruby/object:Gem::Dependency
490
+ name: rails
491
+ requirement: &id044 !ruby/object:Gem::Requirement
492
+ none: false
493
+ requirements:
494
+ - - ">="
495
+ - !ruby/object:Gem::Version
496
+ version: "0"
497
+ type: :runtime
498
+ prerelease: false
499
+ version_requirements: *id044
423
500
  description: Migrant gives you a super-clean DSL to describe your ActiveRecord models (somewhat similar to DataMapper) and generates all your migrations for you so you can spend more time coding the stuff that counts!
424
501
  email: 101pascal@gmail.com
425
502
  executables: []
@@ -449,11 +526,14 @@ files:
449
526
  - lib/datatype/symbol.rb
450
527
  - lib/datatype/time.rb
451
528
  - lib/generators/migrations.rb
529
+ - lib/generators/model.rb
530
+ - lib/generators/templates/model.rb
452
531
  - lib/migrant.rb
453
532
  - lib/migrant/migration_generator.rb
454
533
  - lib/migrant/model_extensions.rb
455
534
  - lib/migrant/schema.rb
456
535
  - lib/railtie.rb
536
+ - lib/simple_object.rb
457
537
  - lib/tasks/db.rake
458
538
  - migrant.gemspec
459
539
  - test/additional_models/review.rb
@@ -519,7 +599,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
519
599
  requirements:
520
600
  - - ">="
521
601
  - !ruby/object:Gem::Version
522
- hash: 645598675
602
+ hash: 204450561
523
603
  segments:
524
604
  - 0
525
605
  version: "0"