Skip to content

Commit

Permalink
fix: migrations with unnecessarily big version numbers
Browse files Browse the repository at this point in the history
Can now apply migrations with names like "20180410163722228_create_users.sql"

Fixes #11
  • Loading branch information
vladfaust committed Jun 22, 2018
1 parent 9081f47 commit 1941074
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/migrate/migrator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ module Migrate
MIGRATION_FILE_REGEX = /(?<version>\d+)(_(?<name>\w+))?\.sql/

def initialize(
@db : DB::Database,
@logger : Logger? = nil,
@dir : String = File.join("db", "migrations"),
@table : String = "version",
@column : String = "version")
@db : DB::Database,
@logger : Logger? = nil,
@dir : String = File.join("db", "migrations"),
@table : String = "version",
@column : String = "version"
)
ensure_version_table_exist
end

Expand Down Expand Up @@ -118,7 +119,7 @@ module Migrate
end

applied_files = migrations.select do |filename|
applied_versions.includes?(MIGRATION_FILE_REGEX.match(filename).not_nil!["version"].to_i)
applied_versions.includes?(MIGRATION_FILE_REGEX.match(filename).not_nil!["version"].to_i64)
end

queries = applied_files.map do |file_path|
Expand Down Expand Up @@ -175,7 +176,7 @@ module Migrate
Dir.entries(@dir).select do |filename|
MIGRATION_FILE_REGEX.match(filename)
end.sort_by do |filename|
MIGRATION_FILE_REGEX.match(filename).not_nil!["version"].to_i
MIGRATION_FILE_REGEX.match(filename).not_nil!["version"].to_i64
end
end

Expand Down

0 comments on commit 1941074

Please sign in to comment.