Class: PgEasyReplicate::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/pg_easy_replicate/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


271
272
273
# File 'lib/pg_easy_replicate/cli.rb', line 271

def self.exit_on_failure?
  true
end

Instance Method Details

#apply_ddl_changeObject



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/pg_easy_replicate/cli.rb', line 230

def apply_ddl_change
  if options[:id]
    PgEasyReplicate::DDLManager.apply_ddl_change(
      group_name: options[:group_name],
      id: options[:id],
    )
    puts "DDL change with ID #{options[:id]} applied successfully."
  else
    changes =
      PgEasyReplicate::DDLManager.list_ddl_changes(
        group_name: options[:group_name],
      )
    if changes.empty?
      puts "No pending DDL changes to apply."
      return
    end

    puts "The following DDL changes will be applied:"
    changes.each do |change|
      puts "ID: #{change[:id]}, Type: #{change[:object_type]}, Command: #{change[:ddl_command]}"
    end
    puts ""
    print("Do you want to apply all these changes? (y/n): ")
    confirmation = $stdin.gets.chomp.downcase

    if confirmation == "y"
      PgEasyReplicate::DDLManager.apply_all_ddl_changes(
        group_name: options[:group_name],
      )
      puts "All pending DDL changes applied successfully."
    else
      puts "Operation cancelled."
    end
  end
end

#bootstrapObject



64
65
66
# File 'lib/pg_easy_replicate/cli.rb', line 64

def bootstrap
  PgEasyReplicate.bootstrap(options)
end

#cleanupObject



86
87
88
# File 'lib/pg_easy_replicate/cli.rb', line 86

def cleanup
  PgEasyReplicate.cleanup(options)
end

#config_checkObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pg_easy_replicate/cli.rb', line 33

def config_check
  PgEasyReplicate.assert_config(
    special_user_role: options[:special_user_role],
    copy_schema: options[:copy_schema],
    tables: options[:tables],
    exclude_tables: options[:exclude_tables],
    schema_name: options[:schema_name],
  )

  puts "✅ Config is looking good."
end

#list_ddl_changesObject



211
212
213
214
215
216
217
218
# File 'lib/pg_easy_replicate/cli.rb', line 211

def list_ddl_changes
  changes =
    PgEasyReplicate::DDLManager.list_ddl_changes(
      group_name: options[:group_name],
      limit: options[:limit],
    )
  puts JSON.pretty_generate(changes)
end

#notifyObject



192
193
194
195
196
197
198
199
# File 'lib/pg_easy_replicate/cli.rb', line 192

def notify
  PgEasyReplicate::Stats.notify(
    options[:group_name],
    options[:url],
    options[:frequency],
    options[:timeout],
  )
end

#start_syncObject



120
121
122
# File 'lib/pg_easy_replicate/cli.rb', line 120

def start_sync
  PgEasyReplicate::Orchestrate.start_sync(options)
end

#statsObject



163
164
165
166
167
168
169
# File 'lib/pg_easy_replicate/cli.rb', line 163

def stats
  if options[:watch]
    PgEasyReplicate::Stats.follow(options[:group_name])
  else
    PgEasyReplicate::Stats.print(options[:group_name])
  end
end

#stop_syncObject



130
131
132
# File 'lib/pg_easy_replicate/cli.rb', line 130

def stop_sync
  PgEasyReplicate::Orchestrate.stop_sync(group_name: options[:group_name])
end

#switchoverObject



149
150
151
152
153
154
155
# File 'lib/pg_easy_replicate/cli.rb', line 149

def switchover
  PgEasyReplicate::Orchestrate.switchover(
    group_name: options[:group_name],
    lag_delta_size: options[:lag_delta_size],
    skip_vacuum_analyze: options[:skip_vacuum_analyze],
  )
end

#versionObject



267
268
269
# File 'lib/pg_easy_replicate/cli.rb', line 267

def version
  puts PgEasyReplicate::VERSION
end