class SqlView::Migration

Attributes

parent[R]

Public Class Methods

new(parent) click to toggle source
# File lib/sql_view.rb, line 62
def initialize(parent)
  @parent = parent
end

Public Instance Methods

down() click to toggle source
# File lib/sql_view.rb, line 84
    def down
      sql = <<-SQL
      DROP#{materialized_or_not}VIEW IF EXISTS #{parent.view_name};
    SQL
      execute(sql)
    end
execute(sql) click to toggle source
# File lib/sql_view.rb, line 91
def execute(sql)
  SqlView.log sql
  ActiveRecord::Base.connection.execute sql#.wp
end
refresh(concurrently: false) click to toggle source
# File lib/sql_view.rb, line 66
    def refresh(concurrently: false)
      concurrently_or_not = concurrently ? " CONCURRENTLY " : " "
      sql = <<-SQL
      REFRESH#{materialized_or_not}VIEW#{concurrently_or_not}#{parent.view_name};
      SQL
      execute(sql)
    end
up() click to toggle source
# File lib/sql_view.rb, line 74
    def up
      view_sql = parent.sql_view_options[:sql_or_proc].call
      raise "Please configure schema for #{parent} (association or SQL) for the view" if view_sql.to_s == ""
      sql = <<-SQL
      CREATE#{materialized_or_not}VIEW #{parent.view_name} AS
      #{view_sql.respond_to?(:to_sql) ? view_sql.to_sql : view_sql };
    SQL
      execute(sql)
    end

Private Instance Methods

materialized_or_not() click to toggle source
# File lib/sql_view.rb, line 98
def materialized_or_not
  parent.sql_view_options[:materialized] ? " MATERIALIZED " : " "
end