Class: PGTrunk::Operations::MaterializedViews::ChangeMaterializedView

Inherits:
Base show all
Defined in:
lib/pg_trunk/operations/materialized_views/change_materialized_view.rb

Instance Method Summary collapse

Methods inherited from Base

#column

Methods included from PGTrunk::Operation::SQLHelpers

#quote

Methods included from PGTrunk::Operation::RubyHelpers

#dump, #to_a, #to_opts, #to_ruby

Methods included from PGTrunk::Operation::Inversion

#invert!, #irreversible!

Methods included from PGTrunk::Operation::Validations

#error_messages

Methods included from PGTrunk::Operation::Attributes

#attributes, #initialize

Instance Method Details

#invertObject



91
92
93
94
95
96
97
98
99
# File 'lib/pg_trunk/operations/materialized_views/change_materialized_view.rb', line 91

def invert
  irreversible!("if_exists: true") if if_exists
  undefined = inversion.select { |_, v| v.nil? }.keys.join(", ").presence
  raise IrreversibleMigration.new(self, nil, <<~MSG.squish) if undefined
    Undefined values to revert #{undefined}.
  MSG

  self.class.new(name: name, **inversion) if inversion.any?
end

#rename_column(name, to:) ⇒ Object

A method to be called in a block



73
74
75
# File 'lib/pg_trunk/operations/materialized_views/change_materialized_view.rb', line 73

def rename_column(name, to:)
  columns << Column.new(name: name, new_name: to)
end

#to_sql(_version) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/pg_trunk/operations/materialized_views/change_materialized_view.rb', line 82

def to_sql(_version)
  [
    *change_columns,
    *rename_columns,
    *cluster_view,
    *update_comment,
  ].join(" ")
end