Sha256: 3c937bb2002fa076eb0c490952ada99f77e146694398a2b24960ef3cf5956dd0

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

require "tty-prompt"

namespace :remote_database do
  desc "Dumps a remote database to #{UffDbLoader.config.dumps_directory}"
  task dump: :environment do
    prompt = TTY::Prompt.new
    environment = prompt.select("Which environment should we get the dump from?", UffDbLoader.config.environments)
    UffDbLoader.ensure_valid_environment!(environment)
    UffDbLoader.dump_from(environment)
  end

  desc "Gets a dump from remote and loads it into the local database"
  task load: :environment do
    prompt = TTY::Prompt.new
    environment = prompt.select("Which environment should we get the dump from?", UffDbLoader.config.environments)
    UffDbLoader.ensure_valid_environment!(environment)
    result_file_path = UffDbLoader.dump_from(environment)

    puts "🤓 Reading from to #{result_file_path}"

    database_name = File.basename(result_file_path, ".*")
    ActiveRecord::Base.connection.execute("CREATE DATABASE #{database_name};")

    puts "🗂  Created database #{database_name}"

    command_successful = system(UffDbLoader.restore_command(database_name, result_file_path))
    raise "Command did not run succesful: #{UffDbLoader.restore_command(database_name, result_file_path)}" unless command_successful

    puts "✅ Succesfully loaded #{result_file_path} into #{database_name}"

    puts "💩 Because YAML is a wonderful format, you need to adapt your config file by hand."
    puts "🆗 Go to #{UffDbLoader.config.database_config_file} and change the development database value to: #{database_name}"
    puts "🧑🏾‍🏫 Don't forgot to restart the Rails server after changing the database config (`rails restart`)"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
uff_db_loader-1.0.1 lib/uff_db_loader/tasks/remote_database.rake
uff_db_loader-1.0.0 lib/uff_db_loader/tasks/remote_database.rake