migrant 1.5.0 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -29
  3. data/.rspec +2 -0
  4. data/.travis.yml +8 -5
  5. data/Gemfile +3 -4
  6. data/LICENSE.txt +21 -0
  7. data/{README.rdoc → README.md} +57 -57
  8. data/Rakefile +4 -31
  9. data/VERSION +1 -1
  10. data/lib/dsl/data_type.rb +5 -1
  11. data/lib/dsl/data_types/primitives.rb +11 -0
  12. data/lib/generators/templates/change_migration.erb +1 -1
  13. data/lib/generators/templates/create_migration.erb +1 -1
  14. data/lib/generators/templates/create_migration.rb +1 -1
  15. data/lib/migrant/migration_generator.rb +10 -6
  16. data/lib/migrant/model_extensions.rb +1 -1
  17. data/lib/migrant/schema.rb +0 -2
  18. data/lib/railtie.rb +2 -2
  19. data/lib/tasks/db.rake +0 -6
  20. data/migrant.gemspec +30 -31
  21. metadata +63 -193
  22. data/.rvmrc +0 -1
  23. data/LICENSE +0 -20
  24. data/lib/simple_object.rb +0 -13
  25. data/test/additional_models/review.rb +0 -11
  26. data/test/helper.rb +0 -64
  27. data/test/rails_app/.gitignore +0 -4
  28. data/test/rails_app/README +0 -256
  29. data/test/rails_app/Rakefile +0 -7
  30. data/test/rails_app/app/controllers/application_controller.rb +0 -3
  31. data/test/rails_app/app/helpers/application_helper.rb +0 -2
  32. data/test/rails_app/app/models/business.rb +0 -25
  33. data/test/rails_app/app/models/business_category.rb +0 -6
  34. data/test/rails_app/app/models/category.rb +0 -10
  35. data/test/rails_app/app/models/chameleon.rb +0 -5
  36. data/test/rails_app/app/models/customer.rb +0 -9
  37. data/test/rails_app/app/models/non_migrant_model.rb +0 -3
  38. data/test/rails_app/app/models/user.rb +0 -8
  39. data/test/rails_app/app/views/layouts/application.html.erb +0 -14
  40. data/test/rails_app/config.ru +0 -4
  41. data/test/rails_app/config/application.rb +0 -16
  42. data/test/rails_app/config/boot.rb +0 -13
  43. data/test/rails_app/config/database.yml +0 -7
  44. data/test/rails_app/config/environment.rb +0 -5
  45. data/test/rails_app/config/environments/development.rb +0 -26
  46. data/test/rails_app/config/environments/production.rb +0 -49
  47. data/test/rails_app/config/environments/test.rb +0 -35
  48. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  49. data/test/rails_app/config/initializers/inflections.rb +0 -10
  50. data/test/rails_app/config/initializers/mime_types.rb +0 -5
  51. data/test/rails_app/config/initializers/secret_token.rb +0 -7
  52. data/test/rails_app/config/initializers/session_store.rb +0 -8
  53. data/test/rails_app/config/locales/en.yml +0 -5
  54. data/test/rails_app/config/routes.rb +0 -58
  55. data/test/rails_app/db/seeds.rb +0 -7
  56. data/test/rails_app/lib/tasks/.gitkeep +0 -0
  57. data/test/rails_app/public/404.html +0 -26
  58. data/test/rails_app/public/422.html +0 -26
  59. data/test/rails_app/public/500.html +0 -26
  60. data/test/rails_app/script/rails +0 -6
  61. data/test/rails_app/test/performance/browsing_test.rb +0 -9
  62. data/test/rails_app/test/test_helper.rb +0 -13
  63. data/test/rails_app/vendor/plugins/.gitkeep +0 -0
  64. data/test/test_data_schema.rb +0 -108
  65. data/test/test_migration_generator.rb +0 -251
  66. data/test/test_validations.rb +0 -49
  67. data/test/test_zzz_performance.rb +0 -13
  68. data/test/verified_output/migrations/added_incompatible_spot_and_deleted_spots.rb +0 -11
  69. data/test/verified_output/migrations/business_id.rb +0 -10
  70. data/test/verified_output/migrations/businesses_indexed_name.rb +0 -8
  71. data/test/verified_output/migrations/chameleons_added_new_longer_spots_and_moved_new_spots.rb +0 -15
  72. data/test/verified_output/migrations/create_business_categories.rb +0 -14
  73. data/test/verified_output/migrations/create_businesses.rb +0 -31
  74. data/test/verified_output/migrations/create_categories.rb +0 -13
  75. data/test/verified_output/migrations/create_chameleons.rb +0 -11
  76. data/test/verified_output/migrations/create_reviews.rb +0 -18
  77. data/test/verified_output/migrations/create_users.rb +0 -19
  78. data/test/verified_output/migrations/created_at.rb +0 -11
  79. data/test/verified_output/migrations/deleted_incompatible_spot.rb +0 -9
  80. data/test/verified_output/migrations/deleted_spots.rb +0 -9
  81. data/test/verified_output/migrations/estimated_value_notes.rb +0 -11
  82. data/test/verified_output/migrations/landline.rb +0 -9
  83. data/test/verified_output/migrations/modified_verified.rb +0 -9
  84. data/test/verified_output/migrations/renamed_old_spots.rb +0 -9
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7243c8702af3af369dff750362ade70c4c23c21f
4
+ data.tar.gz: 728ffd44c39b986c85c25451bb0b10fcf5ede105
5
+ SHA512:
6
+ metadata.gz: fdbbcb72130f81e5e8df8a1f5fcb7bf9b4529010c5255c6031e156bc7a479adac5a8f03885d3bf0810db518cb1338ff67ee5121575672fa8bd56821b892e78c8
7
+ data.tar.gz: e2fe03b07fe4f71046cccc21e65d3ec01c7dca6623125f2d85ef1c01cbc79ae6cd9879fad7aa11f0bae46b1a100ee0edb66c004083e9d2090d62502d756b0543
data/.gitignore CHANGED
@@ -1,29 +1,15 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- # Rubinius
17
- *.rbc
18
-
19
- ## PROJECT::GENERAL
20
- coverage
21
- rdoc
22
- pkg
23
-
24
- ## PROJECT::SPECIFIC
25
- tmp/*
26
- test/rails_app/db/migrate/*
27
- test/rails_app/db/schema.rb
28
- Gemfile.lock
29
- .rbenv-version
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ /log/*
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
15
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml CHANGED
@@ -1,8 +1,11 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
- - 2.0.0
4
- - 1.9.3
5
- - rbx-19mode
4
+ - 2.4.2
5
+ - 2.3.5
6
+ - 2.2.8
7
+ before_install: gem install bundler -v 1.16 --no-rdoc --no-ri
6
8
  env:
7
- - "RAILS_VERSION='~> 3.2'"
8
- - "RAILS_VERSION='~> 4.0'"
9
+ - "RAILS_VERSION=4.2.0"
10
+ - "RAILS_VERSION=5.0.0"
11
+ - "RAILS_VERSION=5.1.0"
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source "https://rubygems.org"
2
- gemspec
3
2
 
4
- if ENV['RAILS_VERSION']
5
- gem 'rails', ENV['RAILS_VERSION']
6
- end
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
7
4
 
5
+ # Specify your gem's dependencies in migrant.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Pascal Houliston
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -1,7 +1,8 @@
1
- = Migrant
2
- {<img src="https://secure.travis-ci.org/pascalh1011/migrant.png?branch=master" />}[http://travis-ci.org/pascalh1011/migrant]
1
+ # Migrant
2
+ [![Build Status](https://api.travis-ci.org/pascalh1011/migrant.png)](https://travis-ci.org/pascalh1011/migrant)
3
+ [![Coverage Status](https://coveralls.io/repos/github/pascalh1011/migrant/badge.svg?branch=master)](https://coveralls.io/github/pascalh1011/migrant?branch=master)
3
4
 
4
- == Summary
5
+ ## Summary
5
6
 
6
7
  Migrant gives you a clean DSL to describe your model schema (somewhat similar to DataMapper).
7
8
  It generates your migrations for you so you can spend more time describing your domain
@@ -9,22 +10,27 @@ model cleanly and less time managing your database layer.
9
10
 
10
11
  You'll also get a handy .mock method to instantiate a filled-in model for testing or debugging.
11
12
 
12
- == Getting Started
13
+ ## Getting Started
13
14
 
14
15
  In your Gemfile:
15
16
 
17
+ ```
16
18
  gem "migrant"
19
+ ```
17
20
 
18
- == Jumping right in
21
+ ## Usage
19
22
 
20
23
  Start by creating some models with the structure you need:
21
24
 
25
+ ```
22
26
  > rails generate migrant:model business
27
+ ```
23
28
 
29
+ ```ruby
24
30
  class Business < ActiveRecord::Base
25
31
  belongs_to :user
26
32
 
27
- # Here's where you describe the columns in your model
33
+ # Heres where you describe the columns in your model
28
34
  structure do
29
35
  name "The kernel's favourite fried chickens"
30
36
  website "http://www.google.co.za/"
@@ -32,11 +38,12 @@ Start by creating some models with the structure you need:
32
38
  date_established Time.now - 300.years
33
39
  end
34
40
  end
35
-
41
+ ```
36
42
  Simply specify an example of the type of data you'll be storing, and Migrant will work out the
37
43
  correct database schema for you. Note that you don't need to specify foreign keys in the structure,
38
44
  they are automatically inferred from your relations. Here is a further example:
39
45
 
46
+ ```ruby
40
47
  class User < ActiveRecord::Base
41
48
  has_many :businesses
42
49
 
@@ -50,35 +57,45 @@ they are automatically inferred from your relations. Here is a further example:
50
57
  secret_code 5521, :validates => [:uniqueness, :numericality]
51
58
  end
52
59
  end
60
+ ```
53
61
 
54
62
  Now, to get your database up to date simply run:
55
63
 
64
+ ```
56
65
  > rake db:upgrade
57
66
 
58
67
  Wrote db/migrate/20101028192913_create_businesses.rb...
59
68
  Wrote db/migrate/20101028192916_create_users.rb...
69
+ ```
60
70
 
61
71
  OR, if you'd prefer to look over the migrations yourself first, run:
62
72
 
73
+ ```
63
74
  > rails generate migrations
75
+ ```
64
76
 
65
77
  Result:
66
78
 
79
+ ```r
67
80
  irb(main):001:0> Business
68
81
  => Business(id: integer, user_id: integer, name: string, website: string, address: text, date_established: datetime)
69
82
 
70
83
  irb(main):002:0> Awesome!!!!
71
84
  NoMethodError: undefined method `Awesome!!!!' for main:Object
85
+ ```
72
86
 
73
87
  By default, your database structure will be cloned to your test environment. If you don't want this to happen
74
88
  automatically, simply specify an environment variable directly:
75
89
 
90
+ ```
76
91
  > rake db:upgrade RAILS_ENV=development
92
+ ```
77
93
 
78
- == Serialization
94
+ ### Serialization
79
95
 
80
96
  Keeping track of your serialized attributes can be done in the Migrant DSL (v1.3+), here's some examples:
81
97
 
98
+ ```ruby
82
99
  class Business < ActiveRecord::Base
83
100
  structure do
84
101
  # Specify serialization automatically (e.g. using Hash, Array, OpenStruct)
@@ -92,28 +109,33 @@ Keeping track of your serialized attributes can be done in the Migrant DSL (v1.3
92
109
  locations :serialized
93
110
  end
94
111
  end
112
+ ```
95
113
 
96
114
  These will call ActiveRecord::Base.serialize for you so don't do it again yourself! The mock generated would appear as:
97
115
 
116
+ ```
98
117
  irb(main):002:0> my_business = Business.mock
99
118
  => #<Business id: nil, awards: ["Best Chicken 2007", "Business of the year 2008"], staff: #<OpenStruct manager="Joe">,
100
119
  locations: {}>
120
+ ```
101
121
 
102
- == Want more examples?
122
+ ### Want more examples?
103
123
 
104
- Check out the test models in +test/rails_app/app/models/*+
124
+ Check out the test models in `spec/support/models.rb`
105
125
 
106
- == Model Generator
126
+ ### Model Generator
107
127
 
128
+ ```
108
129
  > rails generate migrant:model business name:string website:text
109
-
130
+ ```
131
+
110
132
  The model generator works as per the default ActiveRecord one, i.e. you can specify
111
133
  fields to be included in the model. However, a migration is not generated immediately,
112
134
  but the structure block in the model is automatically filled out for you.
113
135
 
114
- Simply run rake db:upgrade or rails generate migrations to get the required migrations when you're ready.
136
+ Simply run `rake db:upgrade` or rails generate migrations to get the required migrations when you're ready.
115
137
 
116
- == What will happen seamlessly
138
+ ## What will happen seamlessly
117
139
 
118
140
  * Creating tables or adding columns (as appropriate)
119
141
  * Adding indexes (happens on foreign keys automatically)
@@ -121,15 +143,20 @@ Simply run rake db:upgrade or rails generate migrations to get the required migr
121
143
  * Changing column types
122
144
  * Rollbacks for all the above
123
145
 
124
- == Compatibility
146
+ ## Currently unsupported
147
+
148
+ * Migrations through plugins (Rails 5+)
125
149
 
126
- * Officially supported: Ruby 1.9.3, 2.0.0, rbx-head
127
- * Unofficially supported: Ruby 1.8.7, 1.9.2
128
- * Rails 3.0 (all versions)
129
- * Rails 4.0 (only from v1.4.3 onwards)
150
+ ## Compatibility
130
151
 
131
- == Getting a mock of your model
152
+ * Ruby 2.2 or greater
153
+ * Rails 4.2 through to Rails 5.1
132
154
 
155
+ **Note**: Really old Ruby versions (1.8) and Rails (3.2+) are supported on v1.4
156
+
157
+ ## Getting a mock of your model
158
+
159
+ ```
133
160
  > rails console
134
161
 
135
162
  irb(main):002:0> my_business = Business.mock
@@ -138,60 +165,33 @@ Simply run rake db:upgrade or rails generate migrations to get the required migr
138
165
 
139
166
  irb(main):003:0> my_business.user
140
167
  => #<User id: nil, name: "John", surname: "Smith", description: "Some string">
168
+ ```
141
169
 
142
- == Pickle/Cucumber Integration
143
-
144
- Add the following to support/env/pickle.rb:
145
-
146
- require 'pickle/migrant'
147
- Pickle.configure do |config|
148
- config.adapters = [Pickle::Migrant]
149
- end
150
-
151
- All pickle steps will then return a mocked model by default, overriden with any values you provide.
152
-
153
- == Help
170
+ ## Help
154
171
 
155
172
  Be sure to check out the Github Wiki, or give me a shout on Twitter: @101pascal
156
173
 
157
- == Maintability / Usability concerns
174
+ ## Maintability / Usability concerns
158
175
  * You don't have to define a structure on every model, Migrant ignores models with no definitions
159
176
  * You can remove the structure definitions later and nothing bad will happen (besides losing automigration for those fields)
160
177
  * If you have a model with relations but no columns, you can still have migrations generated by adding "no_structure" or define a blank structure block.
161
178
  * It's probably a good idea to review the generated migrations before committing to SCM, just to check there's nothing left out.
162
179
 
163
- == Roadmap / Planned features
180
+ ## Roadmap / Planned features
164
181
  * 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)
165
182
  * Fabricator/Factory integration/seperation - Need to assess how useful this is, then optimize or kill.
166
183
 
167
- == License
168
-
169
- Copyright (c) 2011 Pascal Houliston
170
-
171
- Permission is hereby granted, free of charge, to any person obtaining
172
- a copy of this software and associated documentation files (the
173
- "Software"), to deal in the Software without restriction, including
174
- without limitation the rights to use, copy, modify, merge, publish,
175
- distribute, sublicense, and/or sell copies of the Software, and to
176
- permit persons to whom the Software is furnished to do so, subject to
177
- the following conditions:
178
-
179
- The above copyright notice and this permission notice shall be
180
- included in all copies or substantial portions of the Software.
184
+ ## License
181
185
 
182
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
183
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
184
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
185
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
186
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
187
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
188
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
186
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
189
187
 
190
- == Development
188
+ ## Development
191
189
 
192
190
  Please be sure to install all the development dependencies via Bundler, then to run tests do:
193
191
 
194
- > rake test
192
+ ```
193
+ > bundle exec rake
194
+ ```
195
195
 
196
196
  Simplecov reports will be generated for each run. If it's not at 100% line coverage, something's wrong!
197
197
 
data/Rakefile CHANGED
@@ -1,33 +1,6 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- require 'simplecov'
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
4
3
 
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
-
13
- SimpleCov.adapters.define 'migrant' do
14
- add_filter '/test'
15
- add_filter '/lib/tasks'
16
- add_filter '/lib/railtie' # Not covering lines it's running here .. disabling for now
17
- add_filter '/lib/simple_object'
18
-
19
- add_group 'Core Extensions', '/lib/migrant'
20
- add_group 'Schema Data Types', '/lib/datatype'
21
- end
22
- SimpleCov.start 'migrant'
23
-
24
- require 'rake'
25
- require 'rake/testtask'
26
- Rake::TestTask.new(:test) do |test|
27
- test.libs << 'lib' << 'test'
28
- test.pattern = 'test/**/test_*.rb'
29
- test.verbose = true
30
- end
31
-
32
- task :default => :test
4
+ RSpec::Core::RakeTask.new(:spec)
33
5
 
6
+ task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.0
1
+ 2.0.0.pre
data/lib/dsl/data_type.rb CHANGED
@@ -59,7 +59,7 @@ module DataType
59
59
  # General RDBMS data loss scenarios
60
60
  if new_structure[:limit] && current_structure[:limit].to_i != new_structure[:limit].to_i ||
61
61
  new_structure[:type] != current_structure[:type] ||
62
- new_structure[:default] && new_structure[:default] != current_structure[:default]
62
+ !new_structure[:default].nil? && column_default_changed?(current_structure[:default], new_structure[:default])
63
63
 
64
64
  column
65
65
  else
@@ -73,6 +73,10 @@ module DataType
73
73
  def dangerous_migration_from?(current_structure = nil)
74
74
  current_structure && (column[:type] != :text && [:string, :text].include?(current_structure[:type]) && column[:type] != current_structure[:type])
75
75
  end
76
+
77
+ def column_default_changed?(old_default, new_default)
78
+ new_default.to_s != old_default.to_s
79
+ end
76
80
 
77
81
  def self.migrant_data_type?; true; end
78
82
  end
@@ -12,12 +12,20 @@ module DataType
12
12
  def self.default_mock
13
13
  true
14
14
  end
15
+
16
+ def column_default_changed?(old_default, new_default)
17
+ old_default.to_s[0] != new_default.to_s[0]
18
+ end
15
19
  end
16
20
 
17
21
  class FalseClass < TrueClass
18
22
  def self.default_mock
19
23
  false
20
24
  end
25
+
26
+ def column_default_changed?(old_default, new_default)
27
+ old_default.to_s[0] != new_default.to_s[0]
28
+ end
21
29
  end
22
30
 
23
31
  # Datetime
@@ -60,6 +68,9 @@ module DataType
60
68
  end
61
69
  end
62
70
 
71
+ class Integer < Bignum
72
+ end
73
+
63
74
  class Float < Base
64
75
  def column_defaults
65
76
  {:type => :float}
@@ -1,4 +1,4 @@
1
- class <%= @activity.camelize.gsub(/\s/, '') %> < ActiveRecord::Migration
1
+ class <%= @activity.camelize.gsub(/\s/, '') %> < ActiveRecord::Migration<%= @class_suffix %>
2
2
  def self.up
3
3
  <% @columns[:added].each do |field, options| %>
4
4
  add_column :<%= @table_name %>, :<%= field %>, :<%= options.delete(:type) %><%= (options.blank?)? '': ", "+options.inspect[1..-2] %>