Class: Webhookdb::Replicator::SchemaModification

Inherits:
Object
  • Object
show all
Defined in:
lib/webhookdb/replicator/schema_modification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchemaModification

Returns a new instance of SchemaModification.



16
17
18
19
20
# File 'lib/webhookdb/replicator/schema_modification.rb', line 16

def initialize
  @transaction_statements = []
  @nontransaction_statements = []
  @application_database_statements = []
end

Instance Attribute Details

#application_database_statementsArray<String> (readonly)

Each of these statements are executed in the application database, NOT whatever database the schema modification itself is executed against.

Returns:

  • (Array<String>)


14
15
16
# File 'lib/webhookdb/replicator/schema_modification.rb', line 14

def application_database_statements
  @application_database_statements
end

#nontransaction_statementsArray<String> (readonly)

Each of these statements must be executed one-at-a-time. An example would be creating indices concurrently in PG.

Returns:

  • (Array<String>)


10
11
12
# File 'lib/webhookdb/replicator/schema_modification.rb', line 10

def nontransaction_statements
  @nontransaction_statements
end

#transaction_statementsArray<String> (readonly)

All of these statements can be sent to the server at once.

Returns:

  • (Array<String>)


6
7
8
# File 'lib/webhookdb/replicator/schema_modification.rb', line 6

def transaction_statements
  @transaction_statements
end

Instance Method Details

#execute(db) ⇒ Object



28
29
30
31
32
# File 'lib/webhookdb/replicator/schema_modification.rb', line 28

def execute(db)
  db << stmt2str(@transaction_statements)
  @nontransaction_statements.each { |stmt| db << stmt }
  Webhookdb::Postgres::Model.db << stmt2str(@application_database_statements)
end

#noop?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/webhookdb/replicator/schema_modification.rb', line 22

def noop?
  return @transaction_statements.empty? &&
      @nontransaction_statements.empty? &&
      @application_database_statements.empty?
end

#to_sObject



39
40
41
# File 'lib/webhookdb/replicator/schema_modification.rb', line 39

def to_s
  return [stmt2str(@transaction_statements), stmt2str(@nontransaction_statements)].reject(&:blank?).join("\n")
end