diff options
| author | Alban Peignier | 2018-04-26 23:33:46 +0200 |
|---|---|---|
| committer | Alban Peignier | 2018-04-26 23:33:46 +0200 |
| commit | 76deccbde320429ba5ac9a48862efdf97bdcf392 (patch) | |
| tree | ca5be067f1fa06b1b64cc02e96b2071df32c3c3f /app | |
| parent | 715917bf6503a06d7d7c130b8b007525dc52742e (diff) | |
| download | chouette-core-76deccbde320429ba5ac9a48862efdf97bdcf392.tar.bz2 | |
Replace AF83::SchemaCloner by a dump/sed/restore command. Refs #6833
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/referential_cloning.rb | 43 |
1 files changed, 40 insertions, 3 deletions
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 |
