From 39f4a388f51f4b2a450260fae401c37c4d6c874f Mon Sep 17 00:00:00 2001 From: vincent Date: Sun, 13 Jun 2021 09:28:12 +0200 Subject: [PATCH] allow directory nested data migration file paths nested data migration files are taken into account with data migrate but not when loading current schema --- lib/data_migrate/data_schema.rb | 5 ++++- lib/data_migrate/status_service.rb | 2 +- spec/db/5.0/{ => 2009}/20091231235959_some_name.rb | 0 spec/db/6.0/{ => 2009}/20091231235959_some_name.rb | 0 spec/db/data-6.0/{ => 2009}/20091231235959_some_name.rb | 0 spec/db/data/{ => 2009}/20091231235959_some_name.rb | 0 6 files changed, 5 insertions(+), 2 deletions(-) rename spec/db/5.0/{ => 2009}/20091231235959_some_name.rb (100%) rename spec/db/6.0/{ => 2009}/20091231235959_some_name.rb (100%) rename spec/db/data-6.0/{ => 2009}/20091231235959_some_name.rb (100%) rename spec/db/data/{ => 2009}/20091231235959_some_name.rb (100%) diff --git a/lib/data_migrate/data_schema.rb b/lib/data_migrate/data_schema.rb index 605fbfbc..01fc3a4e 100644 --- a/lib/data_migrate/data_schema.rb +++ b/lib/data_migrate/data_schema.rb @@ -31,7 +31,10 @@ def migrated def versions @versions ||= begin versions = [] - Dir.foreach(DataMigrate::DataMigrator.full_migrations_path) do |file| + migration_files = Dir.glob(File.join(DataMigrate::DataMigrator.full_migrations_path, + '**', + '*.rb')) + migration_files.each do |file| match_data = DataMigrate::DataMigrator.match(file) versions << match_data[1].to_i if match_data end diff --git a/lib/data_migrate/status_service.rb b/lib/data_migrate/status_service.rb index 920021f3..7599bfb5 100644 --- a/lib/data_migrate/status_service.rb +++ b/lib/data_migrate/status_service.rb @@ -52,7 +52,7 @@ def migration_list(db_list) def migration_files(db_list) file_list = [] - Dir.foreach(File.join(root_folder, DataMigrate.config.data_migrations_path)) do |file| + Dir.glob(File.join(root_folder, DataMigrate.config.data_migrations_path, '**', '*.rb')) do |file| # only files matching "20091231235959_some_name.rb" pattern if match_data = DataMigrate::DataMigrator.match(file) status = db_list.delete(match_data[1]) ? "up" : "down" diff --git a/spec/db/5.0/20091231235959_some_name.rb b/spec/db/5.0/2009/20091231235959_some_name.rb similarity index 100% rename from spec/db/5.0/20091231235959_some_name.rb rename to spec/db/5.0/2009/20091231235959_some_name.rb diff --git a/spec/db/6.0/20091231235959_some_name.rb b/spec/db/6.0/2009/20091231235959_some_name.rb similarity index 100% rename from spec/db/6.0/20091231235959_some_name.rb rename to spec/db/6.0/2009/20091231235959_some_name.rb diff --git a/spec/db/data-6.0/20091231235959_some_name.rb b/spec/db/data-6.0/2009/20091231235959_some_name.rb similarity index 100% rename from spec/db/data-6.0/20091231235959_some_name.rb rename to spec/db/data-6.0/2009/20091231235959_some_name.rb diff --git a/spec/db/data/20091231235959_some_name.rb b/spec/db/data/2009/20091231235959_some_name.rb similarity index 100% rename from spec/db/data/20091231235959_some_name.rb rename to spec/db/data/2009/20091231235959_some_name.rb