Class: PgSync::SchemaSync
- Inherits:
-
Object
- Object
- PgSync::SchemaSync
- Includes:
- Utils
- Defined in:
- lib/pgsync/schema_sync.rb
Constant Summary
Constants included from Utils
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize(source:, destination:, tasks:, args:, opts:) ⇒ SchemaSync
constructor
A new instance of SchemaSync.
- #perform ⇒ Object
Methods included from Utils
#colorize, #confirm_tables_exist, #db_config_file, #deprecated, #escape, #first_schema, #friendly_name, #log, #monotonic_time, #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
#args ⇒ Object (readonly)
Returns the value of attribute args.
5 6 7 |
# File 'lib/pgsync/schema_sync.rb', line 5 def args @args end |
#opts ⇒ Object (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
#perform ⇒ Object
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 51 52 53 54 55 |
# 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 # generate commands before starting spinner # for better error output if pg_restore not found dump_command = dump_command() restore_command = restore_command() 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(dump_command, restore_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 |