Module: Masamune::Actions::Postgres

Extended by:
ActiveSupport::Concern
Includes:
PostgresAdmin, Transform::DefineSchema
Included in:
Transform, Helpers::Postgres, Tasks::PostgresThor
Defined in:
lib/masamune/actions/postgres.rb

Instance Method Summary collapse

Methods included from Transform::DefineSchema

#define_schema

Methods included from Transform::DefineTable

#define_table

Methods included from PostgresAdmin

#postgres_admin

Instance Method Details

#create_postgres_database_if_not_existsObject



44
45
46
47
48
# File 'lib/masamune/actions/postgres.rb', line 44

def create_postgres_database_if_not_exists
  return unless configuration.commands.postgres.key?(:database)
  return if postgres_helper.database_exists?
  postgres_admin(action: :create, database: configuration.commands.postgres[:database], safe: true)
end

#load_postgres_schemaObject



59
60
61
62
63
64
65
66
67
# File 'lib/masamune/actions/postgres.rb', line 59

def load_postgres_schema
  transform = define_schema(catalog, :postgres)
  postgres(file: transform.to_file, max_retries: 0)
rescue => e
  logger.error(e)
  logger.error('Could not load schema')
  logger.error("\n" + transform.to_s)
  exit
end

#load_postgres_setup_filesObject



50
51
52
53
54
55
56
57
# File 'lib/masamune/actions/postgres.rb', line 50

def load_postgres_setup_files
  return unless configuration.commands.postgres.key?(:setup_files)
  configuration.commands.postgres[:setup_files].each do |file|
    configuration.with_quiet do
      postgres(file: file, max_retries: 0)
    end
  end
end

#postgres(opts = {}, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/masamune/actions/postgres.rb', line 33

def postgres(opts = {}, &block)
  opts = opts.to_hash.symbolize_keys
  opts[:block] = block.to_proc if block_given?

  command = Masamune::Commands::Postgres.new(environment, opts)
  command = Masamune::Commands::RetryWithBackoff.new(command, configuration.commands.postgres.slice(:max_retries, :backoff).merge(opts))
  command = Masamune::Commands::Shell.new(command, opts)

  command.interactive? ? command.replace : command.execute
end