module Viewy

Viewy provides a means of interacting with views in a Postgres database in a way that allows the manipulation of views and their dependencies

Constants

VERSION

Public Class Methods

connection() click to toggle source

The connection used by viewy to manage views

@return [ActiveRecord::ConnectionAdapters::PostgreSQLAdapter] An ActiveRecord connection

to a Postgres Database
# File lib/viewy.rb, line 60
def self.connection
  ActiveRecord::Base.connection
end
materialized_view_names_in_dependency_order() click to toggle source

@return [Array<String>] the ordered names of the materialized views in the system in safe dependency order

# File lib/viewy.rb, line 52
def self.materialized_view_names_in_dependency_order
  Viewy::DependencyManagement::ViewSorter.new.sorted_materialized_views
end
refresh_all_dependency_information() click to toggle source

Calling this method will refresh the materialized view that stores the dependency information for other views in the system

@raise [ActiveRecord::StatementInvalidError] raised if a dependent view is somehow not refreshed correctly @return [PG::Result] the result of the refresh statement on the materialized view

# File lib/viewy.rb, line 27
def self.refresh_all_dependency_information
  view_refresher = Viewy::DependencyManagement::ViewRefresher.new(connection)
  view_refresher.refresh_materialized_view('materialized_view_dependencies')
  view_refresher.refresh_materialized_view('all_view_dependencies')
end
refresh_materialized_dependency_information() click to toggle source

Calling this method will refresh the materialized view that stores the dependency information for other materialized views in the system

@raise [ActiveRecord::StatementInvalidError] raised if a dependent view is somehow not refreshed correctly @return [PG::Result] the result of the refresh statement on the materialized view

# File lib/viewy.rb, line 17
def self.refresh_materialized_dependency_information
  view_refresher = Viewy::DependencyManagement::ViewRefresher.new(connection)
  view_refresher.refresh_materialized_view('materialized_view_dependencies')
end
view_names_in_dependency_order() click to toggle source

@return [Array<String>] the ordered names of all views in the system in safe dependency order

# File lib/viewy.rb, line 47
def self.view_names_in_dependency_order
  Viewy::DependencyManagement::ViewSorter.new.sorted_views
end
with_delayed_dependency_updates() { || ... } click to toggle source
# File lib/viewy.rb, line 33
  def self.with_delayed_dependency_updates
    connection.execute <<-SQL.squish!
      ALTER EVENT TRIGGER view_dependencies_update DISABLE;
    SQL

    yield

    connection.execute <<-SQL.squish!
      ALTER EVENT TRIGGER view_dependencies_update ENABLE ALWAYS;
    SQL
    Viewy.refresh_all_dependency_information
  end