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)


236
237
238
# File 'lib/pg_easy_replicate/cli.rb', line 236

def self.exit_on_failure?
  true
end

Instance Method Details

#apply_ddl_changeObject



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/pg_easy_replicate/cli.rb', line 195

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



81
82
83
# File 'lib/pg_easy_replicate/cli.rb', line 81

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



176
177
178
179
180
181
182
183
# File 'lib/pg_easy_replicate/cli.rb', line 176

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

#start_syncObject



115
116
117
# File 'lib/pg_easy_replicate/cli.rb', line 115

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

#statsObject



158
159
160
161
162
163
164
# File 'lib/pg_easy_replicate/cli.rb', line 158

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

#stop_syncObject



125
126
127
# File 'lib/pg_easy_replicate/cli.rb', line 125

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

#switchoverObject



144
145
146
147
148
149
150
# File 'lib/pg_easy_replicate/cli.rb', line 144

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



232
233
234
# File 'lib/pg_easy_replicate/cli.rb', line 232

def version
  puts PgEasyReplicate::VERSION
end