Class: Scenic::Adapters::Postgres

Inherits:
Object
  • Object
show all
Defined in:
lib/ext/scenic/adapters/postgres.rb

Overview

Features of Scenic not available in v1.7.0

Instance Method Summary collapse

Instance Method Details

#populated?(name) ⇒ boolean

True if supplied relation name is populated. Useful for checking the state of materialized views which may error if created ‘WITH NO DATA` and used before they are refreshed. True for all other relation types.

Parameters:

  • name

    The name of the relation

Returns:

  • (boolean)

Raises:

  • (MaterializedViewsNotSupportedError)

    if the version of Postgres in use does not support materialized views.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ext/scenic/adapters/postgres.rb', line 13

def populated?(name)
  raise_unless_materialized_views_supported

  schemaless_name = name.split(".").last

  sql = "SELECT relispopulated FROM pg_class WHERE relname = '#{schemaless_name}'"
  relations = execute(sql)

  if relations.count.positive?
    relations.first["relispopulated"].in?(["t", true])
  else
    false
  end
end