Class: Mammoth::Sources::PostgresPublicationTable

Inherits:
Object
  • Object
show all
Defined in:
lib/mammoth/sources/postgres_publication_inspector.rb

Overview

Immutable replica-identity facts for one table in configured publications.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation_id:, schema_name:, table_name:, publishes_updates:, publishes_deletes:, replica_identity:, replica_identity_columns:, primary_key_usable:, replica_identity_index_usable:) ⇒ void



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mammoth/sources/postgres_publication_inspector.rb', line 13

def initialize(relation_id:, schema_name:, table_name:, publishes_updates:, publishes_deletes:,
               replica_identity:, replica_identity_columns:, primary_key_usable:,
               replica_identity_index_usable:)
  @relation_id = relation_id
  @schema_name = schema_name
  @table_name = table_name
  @publishes_updates = publishes_updates
  @publishes_deletes = publishes_deletes
  @replica_identity = replica_identity
  @replica_identity_columns = replica_identity_columns.freeze
  @primary_key_usable = primary_key_usable
  @replica_identity_index_usable = replica_identity_index_usable
  freeze
end

Instance Attribute Details

#primary_key_usableObject (readonly)

Returns the value of attribute primary_key_usable.



9
10
11
# File 'lib/mammoth/sources/postgres_publication_inspector.rb', line 9

def primary_key_usable
  @primary_key_usable
end

#publishes_deletesObject (readonly)

Returns the value of attribute publishes_deletes.



9
10
11
# File 'lib/mammoth/sources/postgres_publication_inspector.rb', line 9

def publishes_deletes
  @publishes_deletes
end

#publishes_updatesObject (readonly)

Returns the value of attribute publishes_updates.



9
10
11
# File 'lib/mammoth/sources/postgres_publication_inspector.rb', line 9

def publishes_updates
  @publishes_updates
end

#relation_idObject (readonly)

Returns the value of attribute relation_id.



9
10
11
# File 'lib/mammoth/sources/postgres_publication_inspector.rb', line 9

def relation_id
  @relation_id
end

#replica_identityObject (readonly)

Returns the value of attribute replica_identity.



9
10
11
# File 'lib/mammoth/sources/postgres_publication_inspector.rb', line 9

def replica_identity
  @replica_identity
end

#replica_identity_columnsObject (readonly)

Returns the value of attribute replica_identity_columns.



9
10
11
# File 'lib/mammoth/sources/postgres_publication_inspector.rb', line 9

def replica_identity_columns
  @replica_identity_columns
end

#replica_identity_index_usableObject (readonly)

Returns the value of attribute replica_identity_index_usable.



9
10
11
# File 'lib/mammoth/sources/postgres_publication_inspector.rb', line 9

def replica_identity_index_usable
  @replica_identity_index_usable
end

#schema_nameObject (readonly)

Returns the value of attribute schema_name.



9
10
11
# File 'lib/mammoth/sources/postgres_publication_inspector.rb', line 9

def schema_name
  @schema_name
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



9
10
11
# File 'lib/mammoth/sources/postgres_publication_inspector.rb', line 9

def table_name
  @table_name
end

Instance Method Details

#identity_actionsArray<String>

Publication actions that require old-row identity.

Returns:

  • (Array<String>)


38
39
40
41
42
43
44
# File 'lib/mammoth/sources/postgres_publication_inspector.rb', line 38

def identity_actions
  actions = [] # : Array[String]
  actions.tap do
    actions << "UPDATE" if publishes_updates
    actions << "DELETE" if publishes_deletes
  end
end

#identity_required?Boolean

Whether any configured publication requires replica identity.

Returns:

  • (Boolean)


49
50
51
# File 'lib/mammoth/sources/postgres_publication_inspector.rb', line 49

def identity_required?
  publishes_updates || publishes_deletes
end

#identity_usable?Boolean

Whether PostgreSQL can identify old rows for the published actions.

d uses a primary key, i uses a selected replica-identity index, and f logs the full old row. n provides no old-row identity.

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
68
# File 'lib/mammoth/sources/postgres_publication_inspector.rb', line 59

def identity_usable?
  return true unless identity_required?

  case replica_identity
  when "d" then primary_key_usable
  when "i" then replica_identity_index_usable
  when "f" then true
  else false
  end
end

#qualified_nameString

Schema-qualified table name for diagnostics.

Returns:

  • (String)


31
32
33
# File 'lib/mammoth/sources/postgres_publication_inspector.rb', line 31

def qualified_name
  "#{schema_name}.#{table_name}"
end