From 8cf43a4d2dc5f5782a4de790bace81863bb93c0d Mon Sep 17 00:00:00 2001 From: Andrei Kaleshka Date: Wed, 1 May 2024 17:33:09 +0200 Subject: [PATCH] prepare code for multidb (#55) * prepare code for multidb * small refactor * fix --- lib/actual_db_schema.rb | 23 ++++++++++++++++++++++- lib/actual_db_schema/store.rb | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/actual_db_schema.rb b/lib/actual_db_schema.rb index 549b649..0ad70f5 100644 --- a/lib/actual_db_schema.rb +++ b/lib/actual_db_schema.rb @@ -29,7 +29,28 @@ class << self } def self.migrated_folder - Rails.root.join("tmp", "migrated").tap { |folder| FileUtils.mkdir_p(folder) } + migrated_folders.first + end + + def self.migrated_folders + return [default_migrated_folder] unless migrations_paths + + Array(migrations_paths).map do |path| + if path.end_with?("db/migrate") + default_migrated_folder + else + postfix = path.split("/").last + Rails.root.join("tmp", "migrated_#{postfix}") + end + end + end + + def self.default_migrated_folder + Rails.root.join("tmp", "migrated") + end + + def self.migrations_paths + ActiveRecord::Base.connection_db_config.migrations_paths end def self.migration_filename(fullpath) diff --git a/lib/actual_db_schema/store.rb b/lib/actual_db_schema/store.rb index 3cacb89..c32602d 100644 --- a/lib/actual_db_schema/store.rb +++ b/lib/actual_db_schema/store.rb @@ -9,6 +9,7 @@ class Store def write(filename) basename = File.basename(filename) + FileUtils.mkdir_p(folder) FileUtils.copy(filename, folder.join(basename)) record_metadata(filename) end