migrant 1.3.2 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,7 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
3
  - 1.9.2
5
4
  - 1.9.3
6
5
  - rbx-18mode
7
- - ree
data/README.rdoc CHANGED
@@ -16,8 +16,8 @@ In your Gemfile:
16
16
  gem "migrant"
17
17
 
18
18
  * Rails: 3.0+ (Sorry folks, no plans for Rails 2 support)
19
- * Ruby: Tested with 1.8.7 MRI, 1.9.2 MRI, and Rubinius 1.2.1
20
- * Adapters: Tested with SQLite3, MySQL, MySQL2, Pg. Should work with any AR adapter in theory.
19
+ * Ruby: 1.9, Rbx, JRuby Supported, 1.8 works but unsupported (See Travis CI)
20
+ * Adapters: Tested with SQLite3, MySQL2, Pg. May work with other ActiveRecord adapters
21
21
 
22
22
  == Jumping right in
23
23
 
@@ -42,7 +42,6 @@ correct database schema for you. Note that you don't need to specify foreign key
42
42
  they are automatically inferred from your relations. Here is a further example:
43
43
 
44
44
  class User < ActiveRecord::Base
45
- # Define your associations BEFORE your structure block!
46
45
  has_many :businesses
47
46
 
48
47
  structure do
data/Rakefile CHANGED
@@ -31,13 +31,3 @@ end
31
31
 
32
32
  task :default => :test
33
33
 
34
- require 'rake/rdoctask'
35
- Rake::RDocTask.new do |rdoc|
36
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
37
-
38
- rdoc.rdoc_dir = 'rdoc'
39
- rdoc.title = "migrant #{version}"
40
- rdoc.rdoc_files.include('README*')
41
- rdoc.rdoc_files.include('lib/**/*.rb')
42
- end
43
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.2
1
+ 1.4.0
data/changelog.md CHANGED
@@ -1,3 +1,23 @@
1
+ ### 1.4.0 / 2013-02-03
2
+
3
+ [full changelog](http://github.com/pascalh1011/migrant/compare/v1.3.2...v1.4.0)
4
+
5
+ * Features
6
+ * Changes to the column default are now detected
7
+ * Change migrations filenames are named using new default values (to avoid conflicts)
8
+ * Remove official 1.8 support (still works but too much testing overhead for now)
9
+
10
+ * Bug fixes
11
+ * Fixed associations failing to be added to the base model when using STI
12
+ * Fix possible issue with PostgreSQL regenerating migrations if the range primitive is used
13
+
14
+ ### 1.3.2 / 2012-03-08
15
+
16
+ [full changelog](http://github.com/pascalh1011/migrant/compare/v1.3.1...v1.3.2)
17
+
18
+ * Bug fixes
19
+ * [CRITICAL] Specifying a belongs_to association in a model no longer automatically assumes a schema creation
20
+
1
21
  ### 1.3.1 / 2012-02-12
2
22
 
3
23
  [full changelog](http://github.com/pascalh1011/migrant/compare/v1.3.0...v1.3.1)
data/lib/dsl/data_type.rb CHANGED
@@ -58,7 +58,9 @@ module DataType
58
58
  if current_structure
59
59
  # General RDBMS data loss scenarios
60
60
  if new_structure[:limit] && current_structure[:limit].to_i != new_structure[:limit].to_i ||
61
- new_structure[:type] != current_structure[:type]
61
+ new_structure[:type] != current_structure[:type] ||
62
+ new_structure[:default] && new_structure[:default] != current_structure[:default]
63
+
62
64
  column
63
65
  else
64
66
  nil # No changes
@@ -66,7 +66,6 @@ module DataType
66
66
  class Range < Base
67
67
  def column_defaults
68
68
  definition = {:type => :integer}
69
- definition[:limit] = @value.max.to_s.length if @value.respond_to?(:max)
70
69
  definition
71
70
  end
72
71
  end
@@ -36,7 +36,7 @@ module Migrant
36
36
 
37
37
  if model.table_exists?
38
38
  # Structure ActiveRecord::Base's column information so we can compare it directly to the schema
39
- db_schema = Hash[*model.columns.collect {|c| [c.name.to_sym, Hash[*[:type, :limit].map { |type| [type, c.send(type)] }.flatten] ] }.flatten]
39
+ db_schema = Hash[*model.columns.collect {|c| [c.name.to_sym, Hash[*[:type, :limit, :default].map { |type| [type, c.send(type)] }.flatten] ] }.flatten]
40
40
  model.schema.columns.to_a.sort { |a,b| a.to_s <=> b.to_s }.each do |field_name, data_type|
41
41
  if data_type.dangerous_migration_from?(db_schema[field_name]) &&
42
42
  ask_user("#{model}: '#{field_name}': Converting from ActiveRecord type #{db_schema[field_name][:type]} to #{data_type.column[:type]} could cause data loss. Continue?", %W{Yes No}, true) == "No"
@@ -90,7 +90,7 @@ module Migrant
90
90
 
91
91
  # Example: changed_table_added_something_and_modified_something
92
92
  @activity = 'changed_'+model.table_name+[['added', @columns[:added]], ['modified', @columns[:changed]], ['deleted', destroyed_columns],
93
- ['moved', @columns[:transferred]], ['renamed', @columns[:renamed]], ['indexed', @new_indexes]].reject { |v| v[1].empty? }.collect { |v| "_#{v[0]}_"+v[1].collect(&:first).join('_') }.join('_and')
93
+ ['moved', @columns[:transferred]], ['renamed', @columns[:renamed]], ['indexed', @new_indexes]].reject { |v| v[1].empty? }.collect { |v| "_#{v[0]}_"+v[1].collect(&:last).join('_') }.join('_and')
94
94
  @activity = @activity.split('_')[0..2].join('_')+'_with_multiple_changes' if @activity.length >= 240 # Most filesystems will raise Errno::ENAMETOOLONG otherwise
95
95
 
96
96
  render('change_migration')
@@ -116,24 +116,30 @@ module Migrant
116
116
 
117
117
  private
118
118
  def add_column(name, options)
119
- @columns[:added] << [name, options]
119
+ @columns[:added] << [name, options, name]
120
120
  end
121
121
 
122
122
  def change_column(name, new_schema, old_schema)
123
- @columns[:changed] << [name, new_schema, old_schema]
123
+ if new_schema[:default] && new_schema[:default].respond_to?(:to_s) && new_schema[:default].to_s.length < 31
124
+ change_description = "#{name}_defaulted_to_#{new_schema[:default].to_s.underscore}"
125
+ else
126
+ change_description = name
127
+ end
128
+
129
+ @columns[:changed] << [name, new_schema, old_schema, change_description]
124
130
  end
125
131
 
126
132
  def delete_column(name, current_structure)
127
- @columns[:deleted] << [name, current_structure]
133
+ @columns[:deleted] << [name, current_structure, name]
128
134
  end
129
135
 
130
136
  def move_column(old_name, new_name, old_schema, new_schema)
131
137
  if new_schema == old_schema
132
- @columns[:renamed] << [old_name, new_name]
138
+ @columns[:renamed] << [old_name, new_name, old_name]
133
139
  @columns[:added].reject! { |a| a.first == new_name } # Don't add the column too
134
140
  else
135
141
  @possible_irreversible_migrations = true
136
- @columns[:transferred] << [old_name, new_name] # Still need to add the column, just transfer the data afterwards
142
+ @columns[:transferred] << [old_name, new_name, old_name] # Still need to add the column, just transfer the data afterwards
137
143
  delete_column(old_name, old_schema)
138
144
  end
139
145
  end
@@ -106,6 +106,10 @@ module Migrant
106
106
  def requires_migration?
107
107
  false # All added to base table
108
108
  end
109
+
110
+ def add_association(association)
111
+ parent_schema.add_association(association)
112
+ end
109
113
  end
110
114
 
111
115
  # Why does this class exist? Excellent question.
@@ -16,7 +16,7 @@ class Business < ActiveRecord::Base
16
16
  operating_days 0..6
17
17
  date_established :datetime
18
18
  next_sale (Time.now + 10.days)
19
- verified false
19
+ verified false, :default => false
20
20
  location :type => :string, :limit => 127
21
21
  awards ["Best business 2007", "Tastiest Chicken 2008"]
22
22
  managers :serialized
@@ -1,4 +1,6 @@
1
1
  class Customer < User
2
+ belongs_to :category
3
+
2
4
  structure do
3
5
  money_spent "$5.00"
4
6
  money_gifted "NOK 550.00"
@@ -13,7 +13,8 @@ class TestDataSchema < Test::Unit::TestCase
13
13
  should "generate a foreign key field for a belongs_to association" do
14
14
  assert_schema(Business, :user_id, :type => :integer)
15
15
  assert_schema(BusinessCategory, :business_id, :type => :integer)
16
- assert_schema(BusinessCategory, :category_id, :type => :integer)
16
+ assert_schema(BusinessCategory, :category_id, :type => :integer)
17
+ assert_schema(User, :category_id, :type => :integer)
17
18
  end
18
19
 
19
20
  should "generate foreign key fields for a *polymorphic* belongs_to association" do
@@ -31,7 +32,7 @@ class TestDataSchema < Test::Unit::TestCase
31
32
  end
32
33
 
33
34
  should "generate a smallint column when given a small range" do
34
- assert_schema(Business, :operating_days, :limit => 1, :type => :integer)
35
+ assert_schema(Business, :operating_days, :type => :integer)
35
36
  end
36
37
 
37
38
  should "generate a large integer (size 8) for any bignum types" do
@@ -230,6 +230,14 @@ class TestMigrationGenerator < Test::Unit::TestCase
230
230
  STDIN._mock_responses('M', 'incompatible_spot', 'N', 'Y')
231
231
  run_against_template('added_incompatible_spot_and_deleted_spots')
232
232
  end
233
+
234
+ should "update a column to include a new default" do
235
+ Business.structure do
236
+ verified true, :default => true
237
+ end
238
+
239
+ run_against_template('modified_verified')
240
+ end
233
241
  end
234
242
  end
235
243
 
@@ -6,15 +6,15 @@ class CreateBusinesses < ActiveRecord::Migration
6
6
  t.integer :owner_id
7
7
  t.string :name
8
8
  t.string :website
9
- t.text :address
9
+ t.text :address
10
10
  t.string :summary
11
11
  t.text :description
12
12
  t.string :landline
13
13
  t.string :mobile
14
- t.integer :operating_days, :limit=>1
14
+ t.integer :operating_days
15
15
  t.datetime :date_established
16
16
  t.datetime :next_sale
17
- t.boolean :verified
17
+ t.boolean :verified
18
18
  t.string :location, :limit=>127
19
19
  t.text :awards
20
20
  t.text :managers
@@ -4,7 +4,7 @@ class CreateReviews < ActiveRecord::Migration
4
4
  t.integer :business_id
5
5
  t.integer :user_id
6
6
  t.string :name
7
- t.integer :rating, :limit=>1
7
+ t.integer :rating
8
8
  t.text :body
9
9
  t.integer :views
10
10
  end
@@ -3,6 +3,7 @@ class CreateUsers < ActiveRecord::Migration
3
3
  create_table :users do |t|
4
4
  t.string :name
5
5
  t.string :email
6
+ t.integer :category_id
6
7
  t.string :encrypted_password, :limit=>48
7
8
  t.string :password_salt, :limit=>42
8
9
  t.decimal :money_spent, :precision=>10, :scale=>2
@@ -4,6 +4,6 @@ class ChangedBusinessesModifiedLandline < ActiveRecord::Migration
4
4
  end
5
5
 
6
6
  def self.down
7
- change_column :businesses, :landline, :string, :limit=>255
7
+ change_column :businesses, :landline, :string, :limit=>255, :default=>nil
8
8
  end
9
9
  end
@@ -0,0 +1,9 @@
1
+ class ChangedBusinessesModifiedVerifiedDefaultedToTrue < ActiveRecord::Migration
2
+ def self.up
3
+ change_column :businesses, :verified, :boolean, :default=>true
4
+ end
5
+
6
+ def self.down
7
+ change_column :businesses, :verified, :boolean, :limit=>nil, :default=>false
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migrant
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-05-23 00:00:00.000000000Z
12
+ date: 2011-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thoughtbot-shoulda
16
- requirement: &2152389600 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152389600
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: minitest
27
- requirement: &2152388420 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 1.6.0
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *2152388420
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.6.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: ansi
38
- requirement: &2152387000 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *2152387000
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: turn
49
- requirement: &2152385460 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *2152385460
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: sqlite3
60
- requirement: &2152384020 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *2152384020
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: simplecov
71
- requirement: &2152381760 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *2152381760
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: terminal-table
82
- requirement: &2152379720 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: '0'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *2152379720
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: term-ansicolor
93
- requirement: &2152378020 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ! '>='
@@ -98,10 +133,15 @@ dependencies:
98
133
  version: '0'
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *2152378020
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
102
142
  - !ruby/object:Gem::Dependency
103
143
  name: rake
104
- requirement: &2152376680 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
105
145
  none: false
106
146
  requirements:
107
147
  - - ! '>='
@@ -109,10 +149,15 @@ dependencies:
109
149
  version: 0.8.7
110
150
  type: :development
111
151
  prerelease: false
112
- version_requirements: *2152376680
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: 0.8.7
113
158
  - !ruby/object:Gem::Dependency
114
159
  name: simplecov
115
- requirement: &2152375460 !ruby/object:Gem::Requirement
160
+ requirement: !ruby/object:Gem::Requirement
116
161
  none: false
117
162
  requirements:
118
163
  - - ! '>='
@@ -120,10 +165,15 @@ dependencies:
120
165
  version: '0'
121
166
  type: :development
122
167
  prerelease: false
123
- version_requirements: *2152375460
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
124
174
  - !ruby/object:Gem::Dependency
125
175
  name: rails
126
- requirement: &2152374300 !ruby/object:Gem::Requirement
176
+ requirement: !ruby/object:Gem::Requirement
127
177
  none: false
128
178
  requirements:
129
179
  - - ! '>='
@@ -131,10 +181,15 @@ dependencies:
131
181
  version: 3.0.0
132
182
  type: :runtime
133
183
  prerelease: false
134
- version_requirements: *2152374300
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: 3.0.0
135
190
  - !ruby/object:Gem::Dependency
136
191
  name: faker
137
- requirement: &2152373160 !ruby/object:Gem::Requirement
192
+ requirement: !ruby/object:Gem::Requirement
138
193
  none: false
139
194
  requirements:
140
195
  - - ! '>='
@@ -142,10 +197,15 @@ dependencies:
142
197
  version: '0'
143
198
  type: :runtime
144
199
  prerelease: false
145
- version_requirements: *2152373160
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
146
206
  - !ruby/object:Gem::Dependency
147
207
  name: term-ansicolor
148
- requirement: &2152371600 !ruby/object:Gem::Requirement
208
+ requirement: !ruby/object:Gem::Requirement
149
209
  none: false
150
210
  requirements:
151
211
  - - ! '>='
@@ -153,7 +213,12 @@ dependencies:
153
213
  version: '0'
154
214
  type: :runtime
155
215
  prerelease: false
156
- version_requirements: *2152371600
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
157
222
  description: Easier schema management for Rails that complements your domain model.
158
223
  email: 101pascal@gmail.com
159
224
  executables: []
@@ -246,6 +311,7 @@ files:
246
311
  - test/verified_output/migrations/deleted_spots.rb
247
312
  - test/verified_output/migrations/estimated_value_notes.rb
248
313
  - test/verified_output/migrations/landline.rb
314
+ - test/verified_output/migrations/modified_verified.rb
249
315
  - test/verified_output/migrations/renamed_old_spots.rb
250
316
  homepage: http://github.com/pascalh1011/migrant
251
317
  licenses: []
@@ -267,7 +333,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
333
  version: '0'
268
334
  requirements: []
269
335
  rubyforge_project:
270
- rubygems_version: 1.8.10
336
+ rubygems_version: 1.8.23
271
337
  signing_key:
272
338
  specification_version: 3
273
339
  summary: All the fun of ActiveRecord without writing your migrations, and with a dash