From e1c3efd92a1d8567278e4b49b1b6a3f57582da4a Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 7 Apr 2024 11:51:28 +0200 Subject: [PATCH] Avoid issues when serializing during migration --- src/Internal/Driver/MysqlArray.php | 49 +++++++++++++-------------- src/Internal/Driver/PostgresArray.php | 42 +++++++++++------------ 2 files changed, 45 insertions(+), 46 deletions(-) diff --git a/src/Internal/Driver/MysqlArray.php b/src/Internal/Driver/MysqlArray.php index 135b387..9e50753 100644 --- a/src/Internal/Driver/MysqlArray.php +++ b/src/Internal/Driver/MysqlArray.php @@ -142,6 +142,30 @@ final class MysqlArray extends SqlArray ValueType::BOOL => new BoolInt, default => new Passthrough }; + /** @psalm-suppress InvalidArgument */ + parent::__construct( + $config, + $serializer, + $db, + "SELECT `value` FROM `{$config->table}` WHERE `key` = :index LIMIT 1", + " + REPLACE INTO `{$config->table}` + SET `key` = :index, `value` = :value + ", + " + DELETE FROM `{$config->table}` + WHERE `key` = :index + ", + " + SELECT count(`key`) as `count` FROM `{$config->table}` + ", + " + SELECT `key`, `value` FROM `{$config->table}` + ", + " + DELETE FROM `{$config->table}` + " + ); $db->query(" CREATE TABLE IF NOT EXISTS `{$config->table}` @@ -198,31 +222,6 @@ final class MysqlArray extends SqlArray $db->query("OPTIMIZE TABLE `{$config->table}`"); } } - - /** @psalm-suppress InvalidArgument */ - parent::__construct( - $config, - $serializer, - $db, - "SELECT `value` FROM `{$config->table}` WHERE `key` = :index LIMIT 1", - " - REPLACE INTO `{$config->table}` - SET `key` = :index, `value` = :value - ", - " - DELETE FROM `{$config->table}` - WHERE `key` = :index - ", - " - SELECT count(`key`) as `count` FROM `{$config->table}` - ", - " - SELECT `key`, `value` FROM `{$config->table}` - ", - " - DELETE FROM `{$config->table}` - " - ); } /** diff --git a/src/Internal/Driver/PostgresArray.php b/src/Internal/Driver/PostgresArray.php index 1dd8131..e9489e6 100644 --- a/src/Internal/Driver/PostgresArray.php +++ b/src/Internal/Driver/PostgresArray.php @@ -108,6 +108,27 @@ class PostgresArray extends SqlArray default => new Passthrough }; + /** @psalm-suppress InvalidArgument */ + parent::__construct( + $config, + $serializer, + $connection, + "SELECT value FROM \"bytea_{$config->table}\" WHERE key = :index", + " + INSERT INTO \"bytea_{$config->table}\" + (key,value) + VALUES (:index, :value) + ON CONFLICT (key) DO UPDATE SET value = :value + ", + " + DELETE FROM \"bytea_{$config->table}\" + WHERE key = :index + ", + "SELECT count(key) as count FROM \"bytea_{$config->table}\"", + "SELECT key, value FROM \"bytea_{$config->table}\"", + "DELETE FROM \"bytea_{$config->table}\"" + ); + $connection->query(" CREATE TABLE IF NOT EXISTS \"bytea_{$config->table}\" ( @@ -147,27 +168,6 @@ class PostgresArray extends SqlArray // @codeCoverageIgnoreEnd } } - - /** @psalm-suppress InvalidArgument */ - parent::__construct( - $config, - $serializer, - $connection, - "SELECT value FROM \"bytea_{$config->table}\" WHERE key = :index", - " - INSERT INTO \"bytea_{$config->table}\" - (key,value) - VALUES (:index, :value) - ON CONFLICT (key) DO UPDATE SET value = :value - ", - " - DELETE FROM \"bytea_{$config->table}\" - WHERE key = :index - ", - "SELECT count(key) as count FROM \"bytea_{$config->table}\"", - "SELECT key, value FROM \"bytea_{$config->table}\"", - "DELETE FROM \"bytea_{$config->table}\"" - ); } protected function importFromTable(string $fromTable): void