From b0e33bdcf00f5aace5c4e647e7660f95441c157a Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Thu, 26 Apr 2018 23:33:46 +0200 Subject: Replace AF83::SchemaCloner by a dump/sed/restore command. Refs #6833 --- app/models/referential_cloning.rb | 43 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/models/referential_cloning.rb b/app/models/referential_cloning.rb index 6e102a807..179091485 100644 --- a/app/models/referential_cloning.rb +++ b/app/models/referential_cloning.rb @@ -20,14 +20,51 @@ class ReferentialCloning < ApplicationModel def clone! report = Benchmark.measure do - AF83::SchemaCloner - .new(source_referential.slug, target_referential.slug) - .clone_schema + command = "#{dump_command} | #{sed_command} | #{restore_command}" + unless system command + raise "Copy of #{source_schema} to #{target_schema} failed" + end end target_referential.check_migration_count(report) clean end + def source_schema + source_referential.slug + end + + def target_schema + target_referential.slug + end + + def host + ActiveRecord::Base.connection_config[:host] + end + + def username + ActiveRecord::Base.connection_config[:username] + end + + def password + ActiveRecord::Base.connection_config[:password] + end + + def database + ActiveRecord::Base.connection_config[:database] + end + + def dump_command + "PGPASSWORD=#{password} pg_dump --host #{host} --username #{username} --schema=#{source_schema} #{database}" + end + + def sed_command + "sed -e 's@SCHEMA #{source_schema}@SCHEMA #{target_schema}@' -e 's@SET search_path = #{source_schema}@SET search_path = #{target_schema}@'" + end + + def restore_command + "PGPASSWORD=#{password} psql -q --host #{host} --username #{username} #{database}" + end + def clean CleanUp.new(referential: target_referential).clean end -- cgit v1.2.3