<commit_before>require "heroku/client/heroku_postgresql"
require "heroku/client/heroku_postgresql_backups"
require "heroku/command/base"
require "heroku/helpers/heroku_postgresql"

class Heroku::Command::Pg < Heroku::Command::Base
  # pg:copy SOURCE TARGET
  #
  # Copy all data from source database to target. At least one of
  # these must be a Heroku Postgres database.
  def copy
    source_db = shift_argument
    target_db = shift_argument

    validate_arguments!

    source = resolve_db_or_url(source_db)
    target = resolve_db_or_url(target_db)

    if source.url == target.url
      abort("Cannot copy database to itself")
    end

    attachment = target.attachment || source.attachment

    message = "WARNING: Destructive Action"
    message << "\nThis command will remove all data from #{target.name}"
    message << "\nData from #{source.name} will then be transferred to #{target.name}"
    message << "\nThis command will affect the app: #{attachment.app}"

    if confirm_command(attachment.app, message)
      xfer = hpg_client(attachment).pg_copy(source.name, source.url,
                                            target.name, target.url)
      poll_transfer('copy', xfer[:uuid])
    end
  end

  # pg:backups [subcommand]
  #
  # Interact with built-in backups. Without a subcommand, it lists all
  # available backups. The subcommands available are:
  #
  #  info BACKUP_ID                 # get information about a specific backup
  #  capture DATABASE               # capture a new backup
  #  restore [[BACKUP_ID] DATABASE] # restore a backup (default latest) to a database (default DATABASE_URL)
  #  public-url BACKUP_ID           # get secret but publicly accessible URL for BACKUP_ID to download it
  #    -q, --quiet                  #   Hide expiration message (for use in scripts)
  #  cancel [BACKUP_ID]             # cancel an in-progress backup or restore (default newest)
  #  delete BACKUP_ID               # delete an existing backup
  #  schedule DATABASE              # schedule nightly backups for given database
  #    --at '<hour>:00 <timezone>'  #   at a specific (24h clock) hour in the given timezone<commit_msg>Use better target name for confirmation<commit_after>require "heroku/client/heroku_postgresql"
require "heroku/client/heroku_postgresql_backups"
require "heroku/command/base"
require "heroku/helpers/heroku_postgresql"

class Heroku::Command::Pg < Heroku::Command::Base
  # pg:copy SOURCE TARGET
  #
  # Copy all data from source database to target. At least one of
  # these must be a Heroku Postgres database.
  def copy
    source_db = shift_argument
    target_db = shift_argument

    validate_arguments!

    source = resolve_db_or_url(source_db)
    target = resolve_db_or_url(target_db)

    if source.url == target.url
      abort("Cannot copy database to itself")
    end

    attachment = target.attachment || source.attachment

    if target.attachment.nil?
      target_url = URI.parse(target.url)
      confirm_with = target_url.path[1..-1]
      confirm_with = target_url.host if confirm_with.empty?
      affected = target.name.downcase
    else
      confirm_with = target.attachment.app
      affected = "the app #{target.attachment.app}"
    end

    message = "WARNING: Destructive Action"
    message << "\nThis command will remove all data from #{target.name}"
    message << "\nData from #{source.name} will then be transferred to #{target.name}"
    message << "\nThis command will affect #{affected}"

    if confirm_command(confirm_with, message)
      xfer = hpg_client(attachment).pg_copy(source.name, source.url,
                                            target.name, target.url)
      poll_transfer('copy', xfer[:uuid])
    end
  end

  # pg:backups [subcommand]
  #
  # Interact with built-in backups. Without a subcommand, it lists all
  # available backups. The subcommands available are:
  #
  #  info BACKUP_ID                 # get information about a specific backup
  #  capture DATABASE               # capture a new backup
  #  restore [[BACKUP_ID] DATABASE] # restore a backup (default latest) to a database (default DATABASE_URL)
  #  public-url BACKUP_ID           # get secret but publicly accessible URL for BACKUP_ID to download it
  #    -q, --quiet                  #   Hide expiration message (for use in scripts)
  #  cancel [BACKUP_ID]             # cancel an in-progress backup or restore (default newest)
  #  delete BACKUP_ID               # delete an existing backup
  #  schedule DATABASE              # schedule nightly backups for given database
  #    --at '<hour>:00 <timezone>'  #   at a specific (24h clock) hour in the given timezone
{'fraction_non_alphanumeric': 0.08370895041854476, 'fraction_numerical': 0.0021463833440652502, 'mean_word_length': 2.8480594549958713, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4310665', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1315, 'n_words': 428}