Sha256: dac51762b8d09ead40bba7fcacc4a89c7501106f3a666a25a4899402f7a57fc5

Contents?: true

Size: 971 Bytes

Versions: 80

Compression:

Stored size: 971 Bytes

Contents

# frozen_string_literal: true

require 'avm/data/instance/unit'

module Avm
  module Stereotypes
    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
end

Version data entries

80 entries across 80 versions & 1 rubygems

Version Path
avm-tools-0.74.0 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.73.0 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.72.0 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.71.0 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.70.2 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.70.1 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.70.0 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.69.3 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.69.2 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.69.1 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.69.0 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.68.0 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.67.0 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.66.0 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.65.0 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.64.2 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.64.1 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.64.0 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.63.0 lib/avm/stereotypes/postgresql/instance/data_unit.rb
avm-tools-0.62.4 lib/avm/stereotypes/postgresql/instance/data_unit.rb