Class: Capistrano::DBSync::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/capistrano/db_sync/configuration.rb

Constant Summary collapse

DEFAULT_OPTIONS =
->(cap) do
  {
    # Hash mapping a table name to a query or nil in case no data is wanted for a table.
    # E.g.: {
    #   posts:    "SELECT * FROM posts    WHERE created_at > NOW() - interval '60 days'",
    #   comments: "SELECT * FROM comments WHERE created_at > NOW() - interval '30 days'",
    #   likes: nil
    # }
    data_selection: {},

    data_sync_confirmation: true, # Ask for user input confirmation

    local: {
      cleanup: false, # If the downloaded dump directory should be removed after restored

      pg_jobs: 1, # Number of jobs to run in parallel on pg_restore

      working_dir: Dir.tmpdir,
      env: ENV.fetch('RAILS_ENV', 'development'),
    },

    remote: {
      cleanup: true, # If the remote dump directory should be removed after downloaded

      working_dir: cap.fetch(:tmp_dir, "/tmp"),
      env: cap.fetch(:stage).to_s,
    },
  }
end

Instance Method Summary collapse

Constructor Details

#initialize(cap_instance = Capistrano.env) ⇒ Configuration

Returns a new instance of Configuration.



38
39
40
41
# File 'lib/capistrano/db_sync/configuration.rb', line 38

def initialize(cap_instance = Capistrano.env)
  @cap = cap_instance
  @options = load_options
end

Instance Method Details

#data_sync_confirmed?Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/capistrano/db_sync/configuration.rb', line 49

def data_sync_confirmed?
  skip = options[:data_sync_confirmation].to_s.downcase == "false"
  skip || prompt("Confirm replace local database with remote database?")
end

#load_optionsObject



43
44
45
46
47
# File 'lib/capistrano/db_sync/configuration.rb', line 43

def load_options
  user_options = cap.fetch(:db_sync_options)
  user_options = user_options.reject { |_, v| v.nil? }
  DEFAULT_OPTIONS.call(cap).deep_merge(user_options)
end