Skip to content

Commit

Permalink
Avoid issues when serializing during migration
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Apr 7, 2024
1 parent ee7a261 commit e1c3efd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 46 deletions.
49 changes: 24 additions & 25 deletions src/Internal/Driver/MysqlArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,30 @@ public function __construct(DbArrayBuilder $config, Serializer $serializer)
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}`
Expand Down Expand Up @@ -198,31 +222,6 @@ public function __construct(DbArrayBuilder $config, Serializer $serializer)
$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}`
"
);
}

/**
Expand Down
42 changes: 21 additions & 21 deletions src/Internal/Driver/PostgresArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ public function __construct(DbArrayBuilder $config, Serializer $serializer)
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}\"
(
Expand Down Expand Up @@ -147,27 +168,6 @@ public function __construct(DbArrayBuilder $config, Serializer $serializer)
// @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
Expand Down

0 comments on commit e1c3efd

Please sign in to comment.