Skip to content

Commit

Permalink
Bugfix to group by index without missing versions with same timestamp.
Browse files Browse the repository at this point in the history
  • Loading branch information
faustinoaq committed May 13, 2018
1 parent 3c60d8a commit 314847d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/micrate.cr
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ module Micrate
Dir.entries(migrations_dir)
.select { |name| File.file? File.join("db/migrations", name) }
.select { |name| /^\d+_.+\.sql$/ =~ name }
.map { |name| Migration.from_file(name) }
.sort
.map_with_index { |name, index| Migration.from_file(name, index) }
.index_by { |migration| migration.version }
end

Expand Down
4 changes: 2 additions & 2 deletions src/micrate/migration.cr
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ module Micrate
s.split("--")[0].strip.ends_with? ";"
end

def self.from_file(file_name)
def self.from_file(file_name, index = 0)
full_path = File.join(Micrate.migrations_dir, file_name)
version = file_name.split("_")[0].to_i64
version = file_name.split("_")[0].to_i64 + index
new(version, file_name, File.read(full_path))
end

Expand Down

0 comments on commit 314847d

Please sign in to comment.