diff options
| author | Alban Peignier | 2018-04-26 23:33:46 +0200 | 
|---|---|---|
| committer | Johan Van Ryseghem | 2018-04-26 23:39:18 +0200 | 
| commit | b0e33bdcf00f5aace5c4e647e7660f95441c157a (patch) | |
| tree | c18f1c50513ac756f297779eb5a35faa9347e713 /app/models | |
| parent | 71435c4c221464dfc6cc0150e89393e3bcb74e5e (diff) | |
| download | chouette-core-b0e33bdcf00f5aace5c4e647e7660f95441c157a.tar.bz2 | |
Replace AF83::SchemaCloner by a dump/sed/restore command. Refs #6833
Diffstat (limited to 'app/models')
| -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 | 
