private function destroySecret($secret_id)
 {
     $table = new PassphraseSecret();
     queryfx($table->establishConnection('w'), 'DELETE FROM %T WHERE id = %d', $table->getTableName(), $secret_id);
 }
        if ($file) {
            $secret = $file;
            $type = PassphraseSSHPrivateKeyFileCredentialType::CREDENTIAL_TYPE;
        } else {
            $secret = $repository->getDetail('ssh-key');
            $type = PassphraseSSHPrivateKeyTextCredentialType::CREDENTIAL_TYPE;
        }
    }
    if (!$username || !$secret) {
        echo pht('...no credentials set.') . "\n";
        continue;
    }
    $map[$type][$username][$secret][] = $repository;
    echo pht('...will migrate.') . "\n";
}
$passphrase = new PassphraseSecret();
$passphrase->openTransaction();
$table->openTransaction();
foreach ($map as $credential_type => $credential_usernames) {
    $type = PassphraseCredentialType::getTypeByConstant($credential_type);
    foreach ($credential_usernames as $username => $credential_secrets) {
        foreach ($credential_secrets as $secret_plaintext => $repositories) {
            $callsigns = mpull($repositories, 'getCallsign');
            $signs = implode(', ', $callsigns);
            $name = pht('Migrated Repository Credential (%s)', id(new PhutilUTF8StringTruncator())->setMaximumGlyphs(128)->truncateString($signs));
            echo pht('Creating: %s...', $name) . "\n";
            $secret = id(new PassphraseSecret())->setSecretData($secret_plaintext)->save();
            $secret_id = $secret->getID();
            $credential = PassphraseCredential::initializeNewCredential($viewer)->setCredentialType($type->getCredentialType())->setProvidesType($type->getProvidesType())->setViewPolicy(PhabricatorPolicies::POLICY_ADMIN)->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN)->setName($name)->setUsername($username)->setSecretID($secret_id);
            $credential->setPHID($credential->generatePHID());
            queryfx($credential->establishConnection('w'), 'INSERT INTO %T (name, credentialType, providesType, viewPolicy,