From b1fb701fda9a2dd63cd376845a0498ed43390543 Mon Sep 17 00:00:00 2001 From: Jeremy Woertink Date: Tue, 30 Nov 2021 14:21:26 -0800 Subject: [PATCH] Cleaning up how migration classes are sorted. Migration version is not Int64. Fixes #768 (#769) --- src/avram/migrator/migration.cr | 6 +++--- src/avram/migrator/runner.cr | 10 +++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/avram/migrator/migration.cr b/src/avram/migrator/migration.cr index 4debf4305..79b66eafb 100644 --- a/src/avram/migrator/migration.cr +++ b/src/avram/migrator/migration.cr @@ -9,8 +9,8 @@ abstract class Avram::Migrator::Migration::V1 macro inherited Avram::Migrator::Runner.migrations << self - def version - get_version_from_filename + def version : Int64 + get_version_from_filename.to_i64 end macro get_version_from_filename @@ -19,7 +19,7 @@ abstract class Avram::Migrator::Migration::V1 end abstract def migrate - abstract def version + abstract def version : Int64 getter prepared_statements = [] of String diff --git a/src/avram/migrator/runner.cr b/src/avram/migrator/runner.cr index 74d9610d1..6e85f4fab 100644 --- a/src/avram/migrator/runner.cr +++ b/src/avram/migrator/runner.cr @@ -8,7 +8,7 @@ class Avram::Migrator::Runner extend LuckyTask::TextHelpers - @@migrations = [] of Avram::Migrator::Migration::V1.class + class_getter migrations = [] of Avram::Migrator::Migration::V1.class def initialize(@quiet : Bool = false) end @@ -33,10 +33,6 @@ class Avram::Migrator::Runner credentials.password end - def self.migrations - @@migrations - end - def self.credentials Avram.settings.database_to_migrate.credentials end @@ -166,7 +162,7 @@ class Avram::Migrator::Runner def rollback_to(last_version : Int64) self.class.setup_migration_tracking_tables subset = migrated_migrations.select do |mm| - mm.new.version.to_i64 > last_version + mm.new.version > last_version end subset.reverse.each &.new.down puts "Done rolling back to #{last_version}".colorize(:green) @@ -205,7 +201,7 @@ class Avram::Migrator::Runner end private def sorted_migrations - @@migrations.sort { |a, b| a.new.version <=> b.new.version } + self.class.migrations.sort_by(&.new.version) end private def prepare_for_migration