Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

When combining old integer migrations and new timestamp migrations, m…

…ake sure old integer migrations are all applied first

Previously, a simple sort was done on strings, which yielded
incorrect behavior as it sorts lexicographically instead of
numerically.  Switch to using a numeric sort so integer
migrations come before timestamp based migrations.
  • Loading branch information...
commit a6383daa4e419c9692d30bee2727b35c3e309bd2 1 parent 3b633ee
@jeremyevans authored
Showing with 4 additions and 2 deletions.
  1. +2 −0  CHANGELOG
  2. +2 −2 lib/sequel/extensions/migration.rb
View
2  CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD
+* When combining old integer migrations and new timestamp migrations, make sure old integer migrations are all applied first (jeremyevans)
+
* Support dynamic callbacks to customize regular association loading at query time (jeremyevans)
* Support cascading of eager loading with dynamic callbacks for both eager and eager_graph (jeremyevans)
View
4 lib/sequel/extensions/migration.rb
@@ -302,7 +302,7 @@ def self.migration(&block)
#
# Part of the +migration+ extension.
class Migrator
- MIGRATION_FILE_PATTERN = /\A\d+_.+\.rb\z/i.freeze
+ MIGRATION_FILE_PATTERN = /\A(\d+)_.+\.rb\z/i.freeze
MIGRATION_SPLITTER = '_'.freeze
MINIMUM_TIMESTAMP = 20000101
@@ -589,7 +589,7 @@ def get_migration_files
next unless MIGRATION_FILE_PATTERN.match(file)
files << File.join(directory, file)
end
- files.sort
+ files.sort_by{|f| MIGRATION_FILE_PATTERN.match(File.basename(f))[1].to_i}
end
# Returns tuples of migration, filename, and direction
Please sign in to comment.
Something went wrong with that request. Please try again.