Permalink
Browse files

dump_schema_information: explicitly order inserts into schema_migrati…

…ons table

This change reduces churn in the db/development_structure.sql file when using :sql as
active_record.schema_format, and makes comparing diffs much easier.

Test ensures the output SQL-statements are lexically ordered by version.
  • Loading branch information...
rud committed Nov 1, 2011
1 parent 818bf1d commit ff9c2799c1a065fb132df64da6d19683c647b5b4
@@ -405,7 +405,7 @@ def structure_dump
def dump_schema_information #:nodoc:
sm_table = ActiveRecord::Migrator.schema_migrations_table_name
- migrated = select_values("SELECT version FROM #{sm_table}")
+ migrated = select_values("SELECT version FROM #{sm_table} ORDER BY version")
migrated.map { |v| "INSERT INTO #{sm_table} (version) VALUES ('#{v}');" }.join("\n\n")
end
@@ -1339,6 +1339,15 @@ def test_finds_migrations_from_two_directories
end
end
+ def test_dump_schema_information_outputs_lexically_ordered_versions
+ migration_path = MIGRATIONS_ROOT + '/valid_with_timestamps'
+ ActiveRecord::Migrator.run(:up, migration_path, 20100301010101)
+ ActiveRecord::Migrator.run(:up, migration_path, 20100201010101)
+
+ schema_info = ActiveRecord::Base.connection.dump_schema_information
+ assert_match schema_info, /20100201010101.*20100301010101/m

This comment has been minimized.

Show comment Hide comment
@vijaydev

vijaydev Oct 31, 2011

Member

The order of the arguments should be the other way around. Fixed in 1afe269

@vijaydev

vijaydev Oct 31, 2011

Member

The order of the arguments should be the other way around. Fixed in 1afe269

This comment has been minimized.

Show comment Hide comment
@rud

rud Oct 31, 2011

Contributor

Thank you for that fix!

@rud

rud Oct 31, 2011

Contributor

Thank you for that fix!

+ end
+
def test_finds_pending_migrations
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_2", 1)
migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/interleaved/pass_2").pending_migrations

0 comments on commit ff9c279

Please sign in to comment.