Avoid issues when serializing during migration

This commit is contained in:
Daniil Gentili 2024-04-07 11:51:28 +02:00
parent ee7a261a83
commit e1c3efd92a
2 changed files with 45 additions and 46 deletions

View File

@ -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}`
"
);
}
/**

View File

@ -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