Class: Masamune::Helpers::Postgres

Inherits:
Object
  • Object
show all
Includes:
Actions::Postgres, Actions::PostgresAdmin, Masamune::HasEnvironment
Defined in:
lib/masamune/helpers/postgres.rb

Instance Method Summary collapse

Methods included from Actions::PostgresAdmin

#postgres_admin

Methods included from Actions::Postgres

#create_postgres_database_if_not_exists, #load_postgres_schema, #load_postgres_setup_files, #postgres

Methods included from Transform::DefineSchema

#define_schema

Methods included from Transform::DefineTable

#define_table

Methods included from Masamune::HasEnvironment

#environment, #environment=

Constructor Details

#initialize(environment) ⇒ Postgres

Returns a new instance of Postgres.



32
33
34
35
# File 'lib/masamune/helpers/postgres.rb', line 32

def initialize(environment)
  self.environment = environment
  clear!
end

Instance Method Details

#clear!Object



37
38
39
# File 'lib/masamune/helpers/postgres.rb', line 37

def clear!
  @cache = {}
end

#database_exists?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/masamune/helpers/postgres.rb', line 41

def database_exists?
  @database_exists ||= postgres(exec: 'SELECT version();', fail_fast: false, max_retries: 0).success?
end

#table_exists?(table) ⇒ Boolean

Returns:

  • (Boolean)


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

def table_exists?(table)
  return unless database_exists?
  tables.include?(table)
end

#table_last_modified_at(table, options = {}) ⇒ Object



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

def table_last_modified_at(table, options = {})
  column = options[:last_modified_at]
  return unless column
  return unless table_exists?(table)
  update_table_last_modified_at(table, column)
  @cache[table]
end

#tablesObject



58
59
60
61
# File 'lib/masamune/helpers/postgres.rb', line 58

def tables
  update_tables
  @cache.keys
end