Sha256: f936a7e3a683ec21a6e094dfb5f3724432cab1a6e76ddf9385dd06533d504b00

Contents?: true

Size: 892 Bytes

Versions: 55

Compression:

Stored size: 892 Bytes

Contents

# frozen_string_literal: true

require 'avm/data/instance/unit'

module Avm
  module Postgresql
    class Instance
      class DataUnit < ::Avm::Data::Instance::Unit
        EXTENSION = '.pgdump.gz'

        before_load :clear_database

        def dump_command
          instance.dump_gzip_command
        end

        def load_command
          instance.psql_command.prepend(['gzip', '-d', '@ESC_|'])
        end

        private

        def clear_database
          info 'Clearing database (Dropping all tables)...'
          run_sql(drop_all_tables_sql).if_present { |v| run_sql(v) }
        end

        def drop_all_tables_sql
          "select 'drop table \"' || tablename || '\" cascade;' from pg_tables " \
            "where schemaname = 'public';"
        end

        def run_sql(sql)
          instance.psql_command_command(sql).execute!
        end
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
avm-tools-0.113.2 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.113.1 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.113.0 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.112.0 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.111.0 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.110.0 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.109.1 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.109.0 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.108.0 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.107.0 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.106.0 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.105.0 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.104.0 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.103.1 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.103.0 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.102.2 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.102.1 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.102.0 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.101.0 lib/avm/postgresql/instance/data_unit.rb
avm-tools-0.100.0 lib/avm/postgresql/instance/data_unit.rb