@@ -3,14 +3,14 @@ module Migrations
3
3
class Runner
4
4
include Exceptions
5
5
6
- VERSION_REGEXP = /^(\d {14} )/ . freeze
6
+ VERSION_REGEXP = /^(\d + )/ . freeze
7
7
8
8
class << self
9
9
10
10
def extract_and_validate_version_from ( migration_name )
11
11
version = migration_name . to_s . scan ( VERSION_REGEXP ) . flatten . first
12
12
unless version
13
- raise ArgumentError , 'migration version must be a 14 digits integer'
13
+ raise ArgumentError , 'migration name must start with an integer number e.g: 02_do_something.rb '
14
14
end
15
15
16
16
version . to_i
@@ -24,7 +24,7 @@ def initialize(files_path)
24
24
25
25
load_migrations
26
26
end
27
-
27
+
28
28
# @param from a valid migration name or version
29
29
# @param to a valid migration name or version
30
30
def run ( from : nil , to : nil )
@@ -40,13 +40,13 @@ def run(from: nil, to: nil)
40
40
41
41
def load_migrations
42
42
# Load files from files_path and create classes
43
- @migrations = Dir [ File . join ( File . expand_path ( files_path ) , '**' , '*.rb' ) ] . sort . map do |f_path |
44
- migration_name = File . basename ( f_path )
43
+ @migrations = Dir [ File . join ( File . expand_path ( files_path ) , '**' , '*.rb' ) ] . map do |file_path |
44
+ migration_name = File . basename ( file_path )
45
45
klass = Class . new ( Base )
46
- klass . class_eval ( File . read ( f_path ) , f_path )
46
+ klass . class_eval ( File . read ( file_path ) , file_path )
47
47
klass . freeze
48
48
klass . new migration_name
49
- end
49
+ end . sort_by { | migration | migration . version }
50
50
end
51
51
52
52
# Select migrations to run depending given a starting and an ending one
0 commit comments