Skip to content

Commit db64f54

Browse files
authored
Drop explicit transaction from store_node_tokens_as_encrypted_value (pterodactyl#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 pterodactyl#3229.
1 parent b0995f6 commit db64f54

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

database/migrations/2020_04_10_141024_store_node_tokens_as_encrypted_value.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,17 @@ public function up()
3333
$table->text('daemon_token')->change();
3434
});
3535

36-
DB::transaction(function () {
37-
/** @var \Illuminate\Contracts\Encryption\Encrypter $encrypter */
38-
$encrypter = Container::getInstance()->make(Encrypter::class);
36+
/** @var \Illuminate\Contracts\Encryption\Encrypter $encrypter */
37+
$encrypter = Container::getInstance()->make(Encrypter::class);
3938

40-
foreach (DB::select('SELECT id, daemon_token FROM nodes') as $datum) {
41-
DB::update('UPDATE nodes SET uuid = ?, daemon_token_id = ?, daemon_token = ? WHERE id = ?', [
42-
Uuid::uuid4()->toString(),
43-
substr($datum->daemon_token, 0, 16),
44-
$encrypter->encrypt(substr($datum->daemon_token, 16)),
45-
$datum->id,
46-
]);
47-
}
48-
});
39+
foreach (DB::select('SELECT id, daemon_token FROM nodes') as $datum) {
40+
DB::update('UPDATE nodes SET uuid = ?, daemon_token_id = ?, daemon_token = ? WHERE id = ?', [
41+
Uuid::uuid4()->toString(),
42+
substr($datum->daemon_token, 0, 16),
43+
$encrypter->encrypt(substr($datum->daemon_token, 16)),
44+
$datum->id,
45+
]);
46+
}
4947

5048
Schema::table('nodes', function (Blueprint $table) {
5149
$table->unique(['uuid']);

0 commit comments

Comments
 (0)