Class: PGTrunk::Operations::Sequences::ChangeSequence

Inherits:
Base show all
Defined in:
lib/pg_trunk/operations/sequences/change_sequence.rb

Instance Method Summary collapse

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



73
74
75
76
77
78
79
80
81
# File 'lib/pg_trunk/operations/sequences/change_sequence.rb', line 73

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

#owned_by(table, column, from: nil) ⇒ Object



63
64
65
66
67
# File 'lib/pg_trunk/operations/sequences/change_sequence.rb', line 63

def owned_by(table, column, from: nil)
  self.table = table
  self.column = column
  self.from_table, self.from_column = Array(from)
end

#to_sql(_version) ⇒ Object



69
70
71
# File 'lib/pg_trunk/operations/sequences/change_sequence.rb', line 69

def to_sql(_version)
  [*alter_sequence, *update_comment].join(" ")
end