Module: Torque::PostgreSQL::Migration::CommandRecorder

Included in:
ActiveRecord::Migration::CommandRecorder
Defined in:
lib/torque/postgresql/migration/command_recorder.rb,
sig/torque/postgresql/migration/command_recorder.rbs

Instance Method Summary collapse

Instance Method Details

#add_composite_column(*args) {|arg0| ... } ⇒ Object

Records a column being added to a composite type

Parameters:

  • args (Object)

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (Object)


36
37
38
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 36

def add_composite_column(*args, &block)
  record(:add_composite_column, args, &block)
end

#change_composite_column(*args) {|arg0| ... } ⇒ Object

Records the type of a column being changed, which cannot be inverted because the previous type is unknown

Parameters:

  • args (Object)

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (Object)


62
63
64
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 62

def change_composite_column(*args, &block)
  record(:change_composite_column, args, &block)
end

#change_composite_type(*args) {|arg0| ... } ⇒ Object

Records changes to a composite type, which cannot be inverted for the same reason as change_table

Parameters:

  • args (Object)

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (Object)


31
32
33
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 31

def change_composite_type(*args, &block)
  record(:change_composite_type, args, &block)
end

#create_composite_type(*args) {|arg0| ... } ⇒ Object

Records the creation of a composite type

Parameters:

  • args (Object)

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (Object)


19
20
21
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 19

def create_composite_type(*args, &block)
  record(:create_composite_type, args, &block)
end

#create_schema(*args) {|arg0| ... } ⇒ Object

Records the creation of a schema

Parameters:

  • args (Object)

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (Object)


95
96
97
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 95

def create_schema(*args, &block)
  record(:create_schema, args, &block)
end

#invert_add_composite_column(args) {|arg0| ... } ⇒ inversion

Inverts a column being added to a composite type

Parameters:

  • args (Array[untyped])

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (inversion)


41
42
43
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 41

def invert_add_composite_column(args)
  [:remove_composite_column, args]
end

#invert_create_composite_type(args) {|arg0| ... } ⇒ inversion

Inverts the creation of a composite type

Parameters:

  • args (Array[untyped])

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (inversion)


24
25
26
27
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 24

def invert_create_composite_type(args)
  options = args.second.try(:slice, :schema) || {}
  [:drop_type, [args.first, options]]
end

#invert_create_schema(args) {|arg0| ... } ⇒ inversion

Inverts the creation of a schema

Parameters:

  • args (Array[untyped])

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (inversion)


100
101
102
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 100

def invert_create_schema(args)
  [:drop_schema, [args.first]]
end

#invert_remove_composite_column(args) {|arg0| ... } ⇒ inversion

Inverts a column being removed from a composite type, which is only possible when its type was informed

Parameters:

  • args (Array[untyped])

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (inversion)

Raises:

  • (ActiveRecord::IrreversibleMigration)


52
53
54
55
56
57
58
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 52

def invert_remove_composite_column(args)
  raise ActiveRecord::IrreversibleMigration, <<~MSG.squish if args.third.nil?
    remove_composite_column is only reversible if given a type.
  MSG

  [:add_composite_column, args]
end

#invert_rename_composite_column(args) {|arg0| ... } ⇒ inversion

Inverts a column of a composite type being renamed

Parameters:

  • args (Array[untyped])

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (inversion)


72
73
74
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 72

def invert_rename_composite_column(args)
  [:rename_composite_column, [args.first, args.third, args.second, *args[3..]]]
end

#invert_rename_type(args) {|arg0| ... } ⇒ inversion

Inverts the type rename operation

Parameters:

  • args (Array[untyped])

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (inversion)


14
15
16
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 14

def invert_rename_type(args)
  [:rename_type, args.reverse]
end

#invert_sync_inheritance_features(args) {|arg0| ... } ⇒ inversion

Inverts the spread of features by running it again while pruning, so the children converge back to whatever the parent looks like

Parameters:

  • args (Array[untyped])

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (inversion)


89
90
91
92
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 89

def invert_sync_inheritance_features(args)
  options = args.extract_options!.merge(prune: true)
  [:sync_inheritance_features, [*args, Hash.ruby2_keywords_hash(options)]]
end

#remove_composite_column(*args) {|arg0| ... } ⇒ Object

Records a column being removed from a composite type

Parameters:

  • args (Object)

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (Object)


46
47
48
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 46

def remove_composite_column(*args, &block)
  record(:remove_composite_column, args, &block)
end

#rename_composite_column(*args) {|arg0| ... } ⇒ Object

Records a column of a composite type being renamed

Parameters:

  • args (Object)

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (Object)


67
68
69
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 67

def rename_composite_column(*args, &block)
  record(:rename_composite_column, args, &block)
end

#rename_type(*args) {|arg0| ... } ⇒ Object

Records the rename operation for types

Parameters:

  • args (Object)

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (Object)


9
10
11
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 9

def rename_type(*args, &block)
  record(:rename_type, args, &block)
end

#sync_inheritance_features(*args) {|arg0| ... } ⇒ Object

Records the spread of features into inherited tables. While reverting, the pruning form goes to the front of the list, which is played back reversed, so the children are only pruned once everything else the migration did to their parents has been undone

Parameters:

  • args (Object)

Yields:

Yield Parameters:

  • arg0

Yield Returns:

  • (Object)

Returns:

  • (Object)


80
81
82
83
84
# File 'lib/torque/postgresql/migration/command_recorder.rb', line 80

def sync_inheritance_features(*args, &block)
  return record(:sync_inheritance_features, args, &block) unless reverting

  commands.unshift(inverse_of(:sync_inheritance_features, args, &block))
end