public this repo is viewable by everyone
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Add support for interleaving migrations by storing which migrations have 
run in the new schema_migrations table. Closes #11493 [jordi]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9244 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
technoweenie (author)
about 1 month ago
commit  8a5a9dcbf64843f064b6e8a0b9c6eea8f0b8536e
tree    27064d2d5ebccdd40bf5c4f43fcf5b2e3e7e57f3
parent  78c2d9fc223e7a9945aee65c838f7ce78e9ddb3e
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Add support for interleaving migrations by storing which migrations have run in the new schema_migrations table. Closes #11493 [jordi]
0
+
0
 * ActiveRecord::Base#sum defaults to 0 if no rows are returned. Closes #11550 [kamal]
0
 
0
 * Ensure that respond_to? considers dynamic finder methods. Closes #11538. [floehopper]
...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
 
 
 
 
 
 
248
249
250
 
 
 
 
 
 
 
 
251
252
253
254
255
 
 
 
256
257
258
259
260
261
 
 
 
 
 
 
 
 
 
 
 
 
262
263
264
...
232
233
234
 
 
 
 
 
 
 
 
 
 
 
 
 
235
236
237
238
239
240
241
 
 
242
243
244
245
246
247
248
249
250
 
 
 
 
251
252
253
254
 
 
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
0
@@ -232,33 +232,41 @@ module ActiveRecord
0
 
0
       # Should not be called normally, but this operation is non-destructive.
0
       # The migrations module handles this automatically.
0
- def initialize_schema_information(current_version=0)
0
- begin
0
- execute "CREATE TABLE #{quote_table_name(ActiveRecord::Migrator.schema_info_table_name)} (version #{type_to_sql(:string)})"
0
- execute "INSERT INTO #{quote_table_name(ActiveRecord::Migrator.schema_info_table_name)} (version) VALUES(#{current_version})"
0
- rescue ActiveRecord::StatementInvalid
0
- # Schema has been initialized, make sure version is a string
0
- version_column = columns(:schema_info).detect { |c| c.name == "version" }
0
-
0
- # can't just alter the table, since SQLite can't deal
0
- unless version_column.type == :string
0
- version = ActiveRecord::Migrator.current_version
0
- execute "DROP TABLE #{quote_table_name(ActiveRecord::Migrator.schema_info_table_name)}"
0
- initialize_schema_information(version)
0
+ def initialize_schema_migrations_table
0
+ sm_table = ActiveRecord::Migrator.schema_migrations_table_name
0
+
0
+ unless tables.detect { |t| t == sm_table }
0
+ create_table(sm_table, :id => false) do |schema_migrations_table|
0
+ schema_migrations_table.column :version, :string, :null => false
0
           end
0
- end
0
- end
0
+ add_index sm_table, :version, :unique => true,
0
+ :name => 'unique_schema_migrations'
0
+
0
+ # Backwards-compatibility: if we find schema_info, assume we've
0
+ # migrated up to that point:
0
+ si_table = Base.table_name_prefix + 'schema_info' + Base.table_name_suffix
0
+
0
+ if tables.detect { |t| t == si_table }
0
 
2
- def dump_schema_information #:nodoc:
0
- begin
0
- if (current_schema = ActiveRecord::Migrator.current_version) > 0
0
- return "INSERT INTO #{quote_table_name(ActiveRecord::Migrator.schema_info_table_name)} (version) VALUES (#{current_schema})"
0
+ old_version = select_value("SELECT version FROM #{quote_table_name(si_table)}").to_i
0
+ assume_migrated_upto_version(old_version)
0
+ drop_table(si_table)
0
           end
0
- rescue ActiveRecord::StatementInvalid
0
- # No Schema Info
0
         end
0
       end
0
 
0
+ def assume_migrated_upto_version(version)
0
+ sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)
0
+ migrated = select_values("SELECT version FROM #{sm_table}").map(&:to_i)
0
+ versions = Dir['db/migrate/[0-9]*_*.rb'].map do |filename|
0
+ filename.split('/').last.split('_').first.to_i
0
+ end
0
+
0
+ execute "INSERT INTO #{sm_table} (version) VALUES ('#{version}')" unless migrated.include?(version.to_i)
0
+ (versions - migrated).select { |v| v < version.to_i }.each do |v|
0
+ execute "INSERT INTO #{sm_table} (version) VALUES ('#{v}')"
0
+ end
0
+ end
0
 
0
       def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
0
         if native = native_database_types[type]
...
123
124
125
126
 
 
127
128
129
...
216
217
218
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
220
221
...
315
316
317
318
319
320
321
322
323
 
 
 
324
325
326
 
327
328
329
...
346
347
348
349
350
 
 
351
352
353
354
 
 
355
356
357
...
362
363
364
365
 
366
367
368
...
383
384
385
386
 
387
388
389
390
391
392
 
 
393
394
395
396
397
398
399
400
401
402
403
404
 
 
 
 
 
 
 
 
 
 
 
405
406
407
...
412
413
414
415
 
416
417
418
...
433
434
435
436
 
 
 
 
 
 
 
437
438
439
440
441
442
 
 
 
443
444
445
 
 
 
446
447
448
449
450
451
...
123
124
125
 
126
127
128
129
130
...
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
...
331
332
333
 
 
 
 
 
 
334
335
336
337
338
 
339
340
341
342
...
359
360
361
 
 
362
363
364
365
366
 
367
368
369
370
371
...
376
377
378
 
379
380
381
382
...
397
398
399
 
400
401
402
403
404
 
 
405
406
407
408
 
 
 
409
410
411
412
413
 
 
414
415
416
417
418
419
420
421
422
423
424
425
426
427
...
432
433
434
 
435
436
437
438
...
453
454
455
 
456
457
458
459
460
461
462
463
464
465
 
 
 
466
467
468
469
 
 
470
471
472
473
 
 
474
475
476
0
@@ -123,7 +123,8 @@ module ActiveRecord
0
   #
0
   # To run migrations against the currently configured database, use
0
   # <tt>rake db:migrate</tt>. This will update the database by running all of the
0
- # pending migrations, creating the <tt>schema_info</tt> table if missing.
0
+ # pending migrations, creating the <tt>schema_migrations</tt> table
0
+ # (see "About the schema_migrations table" section below) if missing.
0
   #
0
   # To roll the database back to a previous migration version, use
0
   # <tt>rake db:migrate VERSION=X</tt> where <tt>X</tt> is the version to which
0
@@ -216,6 +217,21 @@ module ActiveRecord
0
   #
0
   # The phrase "Updating salaries..." would then be printed, along with the
0
   # benchmark for the block when the block completes.
0
+ #
0
+ # == About the schema_migrations table
0
+ #
0
+ # Rails versions 2.0 and prior used to create a table called
0
+ # <tt>schema_info</tt> when using migrations. This table contained the
0
+ # version of the schema as of the last applied migration.
0
+ #
0
+ # Starting with Rails 2.1, the <tt>schema_info</tt> table is
0
+ # (automatically) replaced by the <tt>schema_migrations</tt> table, which
0
+ # contains the version numbers of all the migrations applied.
0
+ #
0
+ # As a result, it is now possible to add migration files that are numbered
0
+ # lower than the current schema version: when migrating up, those
0
+ # never-applied "interleaved" migrations will be automatically applied, and
0
+ # when migrating down, never-applied "interleaved" migrations will be skipped.
0
   class Migration
0
     @@verbose = true
0
     cattr_accessor :verbose
0
@@ -315,15 +331,12 @@ module ActiveRecord
0
     class << self
0
       def migrate(migrations_path, target_version = nil)
0
         case
0
- when target_version.nil?, current_version < target_version
0
- up(migrations_path, target_version)
0
- when current_version > target_version
0
- down(migrations_path, target_version)
0
- when current_version == target_version
0
- return # You're on the right version
0
+ when target_version.nil? then up(migrations_path, target_version)
0
+ when current_version > target_version then down(migrations_path, target_version)
0
+ else up(migrations_path, target_version)
0
         end
0
       end
0
-
0
+
0
       def rollback(migrations_path, steps=1)
0
         migrator = self.new(:down, migrations_path)
0
         start_index = migrator.migrations.index(migrator.current_migration)
0
@@ -346,12 +359,13 @@ module ActiveRecord
0
         self.new(direction, migrations_path, target_version).run
0
       end
0
 
0
- def schema_info_table_name
0
- Base.table_name_prefix + "schema_info" + Base.table_name_suffix
0
+ def schema_migrations_table_name
0
+ Base.table_name_prefix + 'schema_migrations' + Base.table_name_suffix
0
       end
0
 
0
       def current_version
0
- Base.connection.select_value("SELECT version FROM #{schema_info_table_name}").to_i
0
+ Base.connection.select_values(
0
+ "SELECT version FROM #{schema_migrations_table_name}").map(&:to_i).max || 0
0
       end
0
 
0
       def proper_table_name(name)
0
@@ -362,7 +376,7 @@ module ActiveRecord
0
 
0
     def initialize(direction, migrations_path, target_version = nil)
0
       raise StandardError.new("This database does not yet support migrations") unless Base.connection.supports_migrations?
0
- Base.connection.initialize_schema_information
0
+ Base.connection.initialize_schema_migrations_table
0
       @direction, @migrations_path, @target_version = direction, migrations_path, target_version
0
     end
0
 
0
@@ -383,25 +397,31 @@ module ActiveRecord
0
     def migrate
0
       current = migrations.detect { |m| m.version == current_version }
0
       target = migrations.detect { |m| m.version == @target_version }
0
-
0
+
0
       if target.nil? && !@target_version.nil? && @target_version > 0
0
         raise UnknownMigrationVersionError.new(@target_version)
0
       end
0
       
0
- start = migrations.index(current) || 0
0
- finish = migrations.index(target) || migrations.size - 1
0
+ start = up? ? 0 : (migrations.index(current) || 0)
0
+ finish = migrations.index(target) || migrations.size - 1
0
       runnable = migrations[start..finish]
0
       
0
- # skip the current migration if we're heading upwards
0
- runnable.shift if up? && runnable.first == current
0
-
0
       # skip the last migration if we're headed down, but not ALL the way down
0
       runnable.pop if down? && !target.nil?
0
       
0
       runnable.each do |migration|
0
         Base.logger.info "Migrating to #{migration} (#{migration.version})"
0
- migration.migrate(@direction)
0
- set_schema_version_after_migrating(migration)
0
+
0
+ # On our way up, we skip migrating the ones we've already migrated
0
+ # On our way down, we skip reverting the ones we've never migrated
0
+ next if up? && migrated.include?(migration.version.to_i)
0
+
0
+ if down? && !migrated.include?(migration.version.to_i)
0
+ migration.announce 'never migrated, skipping'; migration.write
0
+ else
0
+ migration.migrate(@direction)
0
+ record_version_state_after_migrating(migration.version)
0
+ end
0
       end
0
     end
0
 
0
@@ -412,7 +432,7 @@ module ActiveRecord
0
         migrations = files.inject([]) do |klasses, file|
0
           version, name = file.scan(/([0-9]+)_([_a-z0-9]*).rb/).first
0
           
0
- raise IllegalMigrationNameError.new(f) unless version
0
+ raise IllegalMigrationNameError.new(file) unless version
0
           version = version.to_i
0
           
0
           if klasses.detect { |m| m.version == version }
0
@@ -433,19 +453,24 @@ module ActiveRecord
0
     end
0
 
0
     def pending_migrations
0
- migrations.select { |m| m.version > current_version }
0
+ already_migrated = migrated
0
+ migrations.reject { |m| already_migrated.include?(m.version.to_i) }
0
+ end
0
+
0
+ def migrated
0
+ sm_table = self.class.schema_migrations_table_name
0
+ Base.connection.select_values("SELECT version FROM #{sm_table}").map(&:to_i).sort
0
     end
0
 
0
     private
0
- def set_schema_version_after_migrating(migration)
0
- version = migration.version
0
-
0
+ def record_version_state_after_migrating(version)
0
+ sm_table = self.class.schema_migrations_table_name
0
+
0
         if down?
0
- after = migrations[migrations.index(migration) + 1]
0
- version = after ? after.version : 0
0
+ Base.connection.update("DELETE FROM #{sm_table} WHERE version = '#{version}'")
0
+ else
0
+ Base.connection.insert("INSERT INTO #{sm_table} (version) VALUES ('#{version}')")
0
         end
0
-
0
- Base.connection.update("UPDATE #{self.class.schema_info_table_name} SET version = #{version}")
0
       end
0
 
0
       def up?
...
34
35
36
37
 
38
39
 
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
 
 
55
56
57
...
34
35
36
 
37
38
 
39
40
41
42
43
44
 
 
 
 
 
 
 
 
 
 
45
46
47
48
49
50
0
@@ -34,24 +34,17 @@ module ActiveRecord
0
     # #add_index, etc.).
0
     #
0
     # The +info+ hash is optional, and if given is used to define metadata
0
- # about the current schema (like the schema's version):
0
+ # about the current schema (currently, only the schema's version):
0
     #
0
- # ActiveRecord::Schema.define(:version => 15) do
0
+ # ActiveRecord::Schema.define(:version => 20380119000001) do
0
     # ...
0
     # end
0
     def self.define(info={}, &block)
0
       instance_eval(&block)
0
 
0
- unless info.empty?
0
- initialize_schema_information
0
- cols = columns('schema_info')
0
-
0
- info = info.map do |k,v|
0
- v = Base.connection.quote(v, cols.detect { |c| c.name == k.to_s })
0
- "#{k} = #{v}"
0
- end
0
-
0
- Base.connection.update "UPDATE #{Migrator.schema_info_table_name} SET #{info.join(", ")}"
0
+ unless info[:version].blank?
0
+ initialize_schema_migrations_table
0
+ assume_migrated_upto_version info[:version]
0
       end
0
     end
0
   end
...
30
31
32
33
 
34
35
36
37
 
38
39
40
...
59
60
61
62
 
63
64
65
...
30
31
32
 
33
34
35
36
 
37
38
39
40
...
59
60
61
 
62
63
64
65
0
@@ -30,11 +30,11 @@ module ActiveRecord
0
       def initialize(connection)
0
         @connection = connection
0
         @types = @connection.native_database_types
0
- @info = @connection.select_one("SELECT * FROM schema_info") rescue nil
0
+ @version = Migrator::current_version rescue nil
0
       end
0
 
0
       def header(stream)
0
- define_params = @info ? ":version => #{@info['version']}" : ""
0
+ define_params = @version ? ":version => #{@version}" : ""
0
 
0
         stream.puts <<HEADER
0
 # This file is auto-generated from the current state of the database. Instead of editing this file,
0
@@ -59,7 +59,7 @@ HEADER
0
 
0
       def tables(stream)
0
         @connection.tables.sort.each do |tbl|
0
- next if ["schema_info", ignore_tables].flatten.any? do |ignored|
0
+ next if ['schema_migrations', ignore_tables].flatten.any? do |ignored|
0
             case ignored
0
             when String; tbl == ignored
0
             when Regexp; tbl =~ ignored
...
25
26
27
28
29
 
 
30
31
32
...
25
26
27
 
 
28
29
30
31
32
0
@@ -25,8 +25,8 @@ if ActiveRecord::Base.connection.supports_migrations?
0
       end
0
 
0
       assert_nothing_raised { @connection.select_all "SELECT * FROM fruits" }
0
- assert_nothing_raised { @connection.select_all "SELECT * FROM schema_info" }
0
- assert_equal 7, @connection.select_one("SELECT version FROM schema_info")['version'].to_i
0
+ assert_nothing_raised { @connection.select_all "SELECT * FROM schema_migrations" }
0
+ assert_equal 7, ActiveRecord::Migrator::current_version
0
     end
0
   end
0
 
...
7
8
9
 
10
11
12
...
34
35
36
37
38
 
 
39
40
41
...
779
780
781
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
782
783
784
...
817
818
819
820
 
821
822
823
 
824
825
826
 
827
828
829
 
830
831
832
...
839
840
841
842
 
843
844
845
846
 
847
848
849
850
 
851
852
853
...
7
8
9
10
11
12
13
...
35
36
37
 
 
38
39
40
41
42
...
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
...
851
852
853
 
854
855
856
 
857
858
859
 
860
861
862
 
863
864
865
866
...
873
874
875
 
876
877
878
879
 
880
881
882
883
 
884
885
886
887
0
@@ -7,6 +7,7 @@ require 'models/topic'
0
 require MIGRATIONS_ROOT + "/valid/1_people_have_last_names"
0
 require MIGRATIONS_ROOT + "/valid/2_we_need_reminders"
0
 require MIGRATIONS_ROOT + "/decimal/1_give_me_big_numbers"
0
+require MIGRATIONS_ROOT + "/interleaved/pass_3/2_i_raise_on_down"
0
 
0
 if ActiveRecord::Base.connection.supports_migrations?
0
   class BigNumber < ActiveRecord::Base; end
0
@@ -34,8 +35,8 @@ if ActiveRecord::Base.connection.supports_migrations?
0
     end
0
 
0
     def teardown
0
- ActiveRecord::Base.connection.initialize_schema_information
0
- ActiveRecord::Base.connection.update "UPDATE #{ActiveRecord::Migrator.schema_info_table_name} SET version = 0"
0
+ ActiveRecord::Base.connection.initialize_schema_migrations_table
0
+ ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}"
0
 
0
       %w(reminders people_reminders prefix_reminders_suffix).each do |table|
0
         Reminder.connection.drop_table(table) rescue nil
0
@@ -779,6 +780,39 @@ if ActiveRecord::Base.connection.supports_migrations?
0
       assert !Reminder.table_exists?
0
     end
0
 
0
+ def test_finds_migrations
0
+ migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").migrations
0
+ [['1', 'people_have_last_names'],
0
+ ['2', 'we_need_reminders'],
0
+ ['3', 'innocent_jointable']].each_with_index do |pair, i|
0
+ migrations[i].version == pair.first
0
+ migrations[1].name == pair.last
0
+ end
0
+ end
0
+
0
+ def test_finds_pending_migrations
0
+ ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_2", 1)
0
+ migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/interleaved/pass_2").pending_migrations
0
+ assert_equal 1, migrations.size
0
+ migrations[0].version == '3'
0
+ migrations[0].name == 'innocent_jointable'
0
+ end
0
+
0
+ def test_migrator_interleaved_migrations
0
+ ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_1")
0
+
0
+ assert_nothing_raised do
0
+ ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_2")
0
+ end
0
+
0
+ Person.reset_column_information
0
+ assert Person.column_methods_hash.include?(:last_name)
0
+
0
+ assert_nothing_raised do
0
+ ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/interleaved/pass_3")
0
+ end
0
+ end
0
+
0
     def test_migrator_verbosity
0
       ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
0
       assert PeopleHaveLastNames.message_count > 0
0
@@ -817,16 +851,16 @@ if ActiveRecord::Base.connection.supports_migrations?
0
       assert_equal(3, ActiveRecord::Migrator.current_version)
0
       
0
       ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
0
- assert_equal(2, ActiveRecord::Migrator.current_version)
0
+ assert_equal(2, ActiveRecord::Migrator.current_version)
0
       
0
       ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
0
- assert_equal(1, ActiveRecord::Migrator.current_version)
0
+ assert_equal(1, ActiveRecord::Migrator.current_version)
0
       
0
       ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
0
- assert_equal(0, ActiveRecord::Migrator.current_version)
0
+ assert_equal(0, ActiveRecord::Migrator.current_version)
0
       
0
       ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
0
- assert_equal(0, ActiveRecord::Migrator.current_version)
0
+ assert_equal(0, ActiveRecord::Migrator.current_version)
0
     end
0
     
0
     def test_migrator_run
0
@@ -839,15 +873,15 @@ if ActiveRecord::Base.connection.supports_migrations?
0
       assert_equal(0, ActiveRecord::Migrator.current_version)
0
     end
0
 
0
- def test_schema_info_table_name
0
+ def test_schema_migrations_table_name
0
       ActiveRecord::Base.table_name_prefix = "prefix_"
0
       ActiveRecord::Base.table_name_suffix = "_suffix"
0
       Reminder.reset_table_name
0
- assert_equal "prefix_schema_info_suffix", ActiveRecord::Migrator.schema_info_table_name
0
+ assert_equal "prefix_schema_migrations_suffix", ActiveRecord::Migrator.schema_migrations_table_name
0
       ActiveRecord::Base.table_name_prefix = ""
0
       ActiveRecord::Base.table_name_suffix = ""
0
       Reminder.reset_table_name
0
- assert_equal "schema_info", ActiveRecord::Migrator.schema_info_table_name
0
+ assert_equal "schema_migrations", ActiveRecord::Migrator.schema_migrations_table_name
0
     ensure
0
       ActiveRecord::Base.table_name_prefix = ""
0
       ActiveRecord::Base.table_name_suffix = ""
...
16
17
18
19
 
20
21
22
...
81
82
83
84
 
85
86
87
...
92
93
94
95
 
96
97
98
...
16
17
18
 
19
20
21
22
...
81
82
83
 
84
85
86
87
...
92
93
94
 
95
96
97
98
0
@@ -16,7 +16,7 @@ if ActiveRecord::Base.connection.respond_to?(:tables)
0
       output = standard_dump
0
       assert_match %r{create_table "accounts"}, output
0
       assert_match %r{create_table "authors"}, output
0
- assert_no_match %r{create_table "schema_info"}, output
0
+ assert_no_match %r{create_table "schema_migrations"}, output
0
     end
0
 
0
     def test_schema_dump_excludes_sqlite_sequence
0
@@ -81,7 +81,7 @@ if ActiveRecord::Base.connection.respond_to?(:tables)
0
       output = stream.string
0
       assert_no_match %r{create_table "accounts"}, output
0
       assert_match %r{create_table "authors"}, output
0
- assert_no_match %r{create_table "schema_info"}, output
0
+ assert_no_match %r{create_table "schema_migrations"}, output
0
     end
0
 
0
     def test_schema_dump_with_regexp_ignored_table
0
@@ -92,7 +92,7 @@ if ActiveRecord::Base.connection.respond_to?(:tables)
0
       output = stream.string
0
       assert_no_match %r{create_table "accounts"}, output
0
       assert_match %r{create_table "authors"}, output
0
- assert_no_match %r{create_table "schema_info"}, output
0
+ assert_no_match %r{create_table "schema_migrations"}, output
0
     end
0
 
0
     def test_schema_dump_illegal_ignored_table_value
...
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
0
@@ -0,0 +1,12 @@
0
+class InnocentJointable < ActiveRecord::Migration
0
+ def self.up
0
+ create_table("people_reminders", :id => false) do |t|
0
+ t.column :reminder_id, :integer
0
+ t.column :person_id, :integer
0
+ end
0
+ end
0
+
0
+ def self.down
0
+ drop_table "people_reminders"
0
+ end
0
+end
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
0
@@ -0,0 +1,9 @@
0
+class PeopleHaveLastNames < ActiveRecord::Migration
0
+ def self.up
0
+ add_column "people", "last_name", :string
0
+ end
0
+
0
+ def self.down
0
+ remove_column "people", "last_name"
0
+ end
0
+end
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
0
@@ -0,0 +1,12 @@
0
+class InnocentJointable < ActiveRecord::Migration
0
+ def self.up
0
+ create_table("people_reminders", :id => false) do |t|
0
+ t.column :reminder_id, :integer
0
+ t.column :person_id, :integer
0
+ end
0
+ end
0
+
0
+ def self.down
0
+ drop_table "people_reminders"
0
+ end
0
+end
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
0
@@ -0,0 +1,9 @@
0
+class PeopleHaveLastNames < ActiveRecord::Migration
0
+ def self.up
0
+ add_column "people", "last_name", :string
0
+ end
0
+
0
+ def self.down
0
+ remove_column "people", "last_name"
0
+ end
0
+end
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
0
@@ -0,0 +1,8 @@
0
+class IRaiseOnDown < ActiveRecord::Migration
0
+ def self.up
0
+ end
0
+
0
+ def self.down
0
+ raise
0
+ end
0
+end
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
0
@@ -0,0 +1,12 @@
0
+class InnocentJointable < ActiveRecord::Migration
0
+ def self.up
0
+ create_table("people_reminders", :id => false) do |t|
0
+ t.column :reminder_id, :integer
0
+ t.column :person_id, :integer
0
+ end
0
+ end
0
+
0
+ def self.down
0
+ drop_table "people_reminders"
0
+ end
0
+end
0
\ No newline at end of file
...
31
32
33
34
 
35
...
31
32
33
 
34
35
0
@@ -31,5 +31,5 @@ DROP TABLE legacy_things
0
 DROP TABLE numeric_data
0
 DROP TABLE mixed_case_monkeys
0
 DROP TABLE minimalistics
0
-DROP TABLE schema_info
0
+DROP TABLE schema_migrations
0
 go

Comments