class AcquiaToolbelt::CLI::Databases
Public Instance Methods
add()
click to toggle source
# File lib/acquia_toolbelt/cli/database.rb, line 33 def add if options[:subscription] subscription = options[:subscription] else subscription = AcquiaToolbelt::CLI::API.default_subscription end database = options[:database] add_database = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/dbs", 'POST', :db => "#{database}" if add_database['id'] ui.success "Database '#{database}' has been successfully created." else ui.fail AcquiaToolbelt::CLI::API.display_error(add_database) end end
backup()
click to toggle source
# File lib/acquia_toolbelt/cli/database.rb, line 165 def backup if options[:subscription] subscription = options[:subscription] else subscription = AcquiaToolbelt::CLI::API.default_subscription end database = options[:database] environment = options[:environment] create_backup = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs/#{database}/backups", 'POST' if create_backup["id"] ui.success "The backup for '#{database}' in #{environment} has been started." else ui.fail AcquiaToolbelt::CLI::API.display_error(create_backup) end end
copy()
click to toggle source
# File lib/acquia_toolbelt/cli/database.rb, line 60 def copy if options[:subscription] subscription = options[:subscription] else subscription = AcquiaToolbelt::CLI::API.default_subscription end database = options[:database] origin = options[:origin] target = options[:target] copy_database = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/dbs/#{database}/db-copy/#{origin}/#{target}", 'POST' if copy_database["id"] ui.success "Database '#{database}' has been copied from #{origin} to #{target}." else ui.fail AcquiaToolbelt::CLI::API.display_error(copy_database) end end
database_details(database)
click to toggle source
Internal: Build the database output.
Output the database information exposing all the available fields and data to the end user.
database - The name of the database you wish to fetch the information
about.
Returns the row of data for the database.
# File lib/acquia_toolbelt/cli/database.rb, line 14 def database_details(database) row_data = [] row_data << database['name'] row_data << database['username'] row_data << database['password'] row_data << database['host'] row_data << database['db_cluster'] row_data << database['instance_name'] row_data end
delete()
click to toggle source
# File lib/acquia_toolbelt/cli/database.rb, line 88 def delete if options[:subscription] subscription = options[:subscription] else subscription = AcquiaToolbelt::CLI::API.default_subscription end database = options[:database] delete_db = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/dbs/#{database}", 'DELETE' if delete_db['id'] ui.success "Database '#{database}' has been successfully deleted." else ui.fail AcquiaToolbelt::CLI::API.display_error(delete_database) end end
list()
click to toggle source
# File lib/acquia_toolbelt/cli/database.rb, line 111 def list if options[:subscription] subscription = options[:subscription] else subscription = AcquiaToolbelt::CLI::API.default_subscription end ui.say database = options[:database] environment = options[:environment] rows = [] headings = [ 'Name', 'Username', 'Password', 'Host', 'DB cluster', 'Instance name' ] # Output a single database where the name and environment are specified. if database && environment database = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs/#{database}" rows << database_details(database) # Only an environment was set so get all expanded data for the requested # environment. elsif environment databases = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs" databases.each do |db| rows << database_details(db) end # If no name or environment is passed, just throw back all the database # names - no in depth details. else # Only set the 'name' header as we don't need the rest of the headers. headings = ['Name'] databases = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/dbs" databases.each do |db| rows << [db['name']] end end ui.output_table('', headings, rows) end
list_backups()
click to toggle source
# File lib/acquia_toolbelt/cli/database.rb, line 188 def list_backups # Ensure we have an environment defined. if options[:environment].nil? ui.say "No value provided for required options '--environment'" return end if options[:subscription] subscription = options[:subscription] else subscription = AcquiaToolbelt::CLI::API.default_subscription end database = options[:database] environment = options[:environment] backups = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs/#{database}/backups" ui.say rows = [] headings = [ 'ID', 'Checksum', 'Type', 'Path', 'Start', 'Completed' ] backups.each do |backup| row_data = [] row_data << backup['id'] row_data << backup['checksum'] row_data << backup['type'] row_data << backup['path'] row_data << Time.at(backup['started'].to_i) row_data << Time.at(backup['completed'].to_i) rows << row_data end ui.output_table('', headings, rows) end
restore()
click to toggle source
# File lib/acquia_toolbelt/cli/database.rb, line 239 def restore # Ensure we have an environment defined. if options[:environment].nil? ui.say "No value provided for required options '--environment'" return end if options[:subscription] subscription = options[:subscription] else subscription = AcquiaToolbelt::CLI::API.default_subscription end database = options[:database] environment = options[:environment] database = options[:database] backup_id = options[:id] restore_db = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs/#{database}/backups/#{backup_id}/restore", 'POST' if restore_db['id'] ui.success "Database backup #{backup_id} has been restored to '#{database}' in #{environment}." else ui.fail AcquiaToolbelt::CLI::API.display_error(restore_db) end end