Drop explicit transaction from store_node_tokens_as_encrypted_value (#3280)

Migrations are executed in transactions anyway, and creating a savepoint can cause
spurious failures on databases that don't support transactional DDL (like
MySQL and MariaDB) when it attempts to commit a savepoint that was silently
not created because there wasn't an active transaction after some DDL was
executed.

While a better solution might involve splitting this migration into several so each
one is only DDL or only data manipulation, I don't think that can be done very
easily while maintaining compatibility with existing deployments.

Fixes #3229.
This commit is contained in:
Peter Marheine 2021-04-21 13:37:11 +10:00 committed by GitHub
parent b0995f6458
commit db64f54010
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -33,19 +33,17 @@ class StoreNodeTokensAsEncryptedValue extends Migration
$table->text('daemon_token')->change(); $table->text('daemon_token')->change();
}); });
DB::transaction(function () { /** @var \Illuminate\Contracts\Encryption\Encrypter $encrypter */
/** @var \Illuminate\Contracts\Encryption\Encrypter $encrypter */ $encrypter = Container::getInstance()->make(Encrypter::class);
$encrypter = Container::getInstance()->make(Encrypter::class);
foreach (DB::select('SELECT id, daemon_token FROM nodes') as $datum) { foreach (DB::select('SELECT id, daemon_token FROM nodes') as $datum) {
DB::update('UPDATE nodes SET uuid = ?, daemon_token_id = ?, daemon_token = ? WHERE id = ?', [ DB::update('UPDATE nodes SET uuid = ?, daemon_token_id = ?, daemon_token = ? WHERE id = ?', [
Uuid::uuid4()->toString(), Uuid::uuid4()->toString(),
substr($datum->daemon_token, 0, 16), substr($datum->daemon_token, 0, 16),
$encrypter->encrypt(substr($datum->daemon_token, 16)), $encrypter->encrypt(substr($datum->daemon_token, 16)),
$datum->id, $datum->id,
]); ]);
} }
});
Schema::table('nodes', function (Blueprint $table) { Schema::table('nodes', function (Blueprint $table) {
$table->unique(['uuid']); $table->unique(['uuid']);