Class: PgSync::SchemaSync

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/pgsync/schema_sync.rb

Constant Summary

Constants included from Utils

Utils::COLOR_CODES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#colorize, #confirm_tables_exist, #db_config_file, #deprecated, #escape, #first_schema, #friendly_name, #log, #output, #quote_ident, #quote_ident_full, #quote_string, #task_name, #warning

Constructor Details

#initialize(source:, destination:, tasks:, args:, opts:) ⇒ SchemaSync

Returns a new instance of SchemaSync.



7
8
9
10
11
12
13
# File 'lib/pgsync/schema_sync.rb', line 7

def initialize(source:, destination:, tasks:, args:, opts:)
  @source = source
  @destination = destination
  @tasks = tasks
  @args = args
  @opts = opts
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/pgsync/schema_sync.rb', line 5

def args
  @args
end

#optsObject (readonly)

Returns the value of attribute opts.



5
6
7
# File 'lib/pgsync/schema_sync.rb', line 5

def opts
  @opts
end

Instance Method Details

#performObject

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pgsync/schema_sync.rb', line 15

def perform
  if opts[:preserve]
    raise Error, "Cannot use --preserve with --schema-first or --schema-only"
  end

  show_spinner = output.tty? && !opts[:debug]

  if show_spinner
    spinner = TTY::Spinner.new(":spinner Syncing schema", format: :dots)
    spinner.auto_spin
  end

  create_schemas if specify_tables?

  # if spinner, capture lines to show on error
  lines = []
  success =
    run_command do |line|
      if show_spinner
        lines << line
      else
        log line
      end
    end

  if show_spinner
    if success
      spinner.success
    else
      spinner.error
      log lines.join
    end
  end

  raise Error, "Schema sync returned non-zero exit code" unless success
end