Skip to content

Commit e1c3efd

Browse files
committed
Avoid issues when serializing during migration
1 parent ee7a261 commit e1c3efd

File tree

2 files changed

+45
-46
lines changed

2 files changed

+45
-46
lines changed

src/Internal/Driver/MysqlArray.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,30 @@ public function __construct(DbArrayBuilder $config, Serializer $serializer)
142142
ValueType::BOOL => new BoolInt,
143143
default => new Passthrough
144144
};
145+
/** @psalm-suppress InvalidArgument */
146+
parent::__construct(
147+
$config,
148+
$serializer,
149+
$db,
150+
"SELECT `value` FROM `{$config->table}` WHERE `key` = :index LIMIT 1",
151+
"
152+
REPLACE INTO `{$config->table}`
153+
SET `key` = :index, `value` = :value
154+
",
155+
"
156+
DELETE FROM `{$config->table}`
157+
WHERE `key` = :index
158+
",
159+
"
160+
SELECT count(`key`) as `count` FROM `{$config->table}`
161+
",
162+
"
163+
SELECT `key`, `value` FROM `{$config->table}`
164+
",
165+
"
166+
DELETE FROM `{$config->table}`
167+
"
168+
);
145169

146170
$db->query("
147171
CREATE TABLE IF NOT EXISTS `{$config->table}`
@@ -198,31 +222,6 @@ public function __construct(DbArrayBuilder $config, Serializer $serializer)
198222
$db->query("OPTIMIZE TABLE `{$config->table}`");
199223
}
200224
}
201-
202-
/** @psalm-suppress InvalidArgument */
203-
parent::__construct(
204-
$config,
205-
$serializer,
206-
$db,
207-
"SELECT `value` FROM `{$config->table}` WHERE `key` = :index LIMIT 1",
208-
"
209-
REPLACE INTO `{$config->table}`
210-
SET `key` = :index, `value` = :value
211-
",
212-
"
213-
DELETE FROM `{$config->table}`
214-
WHERE `key` = :index
215-
",
216-
"
217-
SELECT count(`key`) as `count` FROM `{$config->table}`
218-
",
219-
"
220-
SELECT `key`, `value` FROM `{$config->table}`
221-
",
222-
"
223-
DELETE FROM `{$config->table}`
224-
"
225-
);
226225
}
227226

228227
/**

src/Internal/Driver/PostgresArray.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,27 @@ public function __construct(DbArrayBuilder $config, Serializer $serializer)
108108
default => new Passthrough
109109
};
110110

111+
/** @psalm-suppress InvalidArgument */
112+
parent::__construct(
113+
$config,
114+
$serializer,
115+
$connection,
116+
"SELECT value FROM \"bytea_{$config->table}\" WHERE key = :index",
117+
"
118+
INSERT INTO \"bytea_{$config->table}\"
119+
(key,value)
120+
VALUES (:index, :value)
121+
ON CONFLICT (key) DO UPDATE SET value = :value
122+
",
123+
"
124+
DELETE FROM \"bytea_{$config->table}\"
125+
WHERE key = :index
126+
",
127+
"SELECT count(key) as count FROM \"bytea_{$config->table}\"",
128+
"SELECT key, value FROM \"bytea_{$config->table}\"",
129+
"DELETE FROM \"bytea_{$config->table}\""
130+
);
131+
111132
$connection->query("
112133
CREATE TABLE IF NOT EXISTS \"bytea_{$config->table}\"
113134
(
@@ -147,27 +168,6 @@ public function __construct(DbArrayBuilder $config, Serializer $serializer)
147168
// @codeCoverageIgnoreEnd
148169
}
149170
}
150-
151-
/** @psalm-suppress InvalidArgument */
152-
parent::__construct(
153-
$config,
154-
$serializer,
155-
$connection,
156-
"SELECT value FROM \"bytea_{$config->table}\" WHERE key = :index",
157-
"
158-
INSERT INTO \"bytea_{$config->table}\"
159-
(key,value)
160-
VALUES (:index, :value)
161-
ON CONFLICT (key) DO UPDATE SET value = :value
162-
",
163-
"
164-
DELETE FROM \"bytea_{$config->table}\"
165-
WHERE key = :index
166-
",
167-
"SELECT count(key) as count FROM \"bytea_{$config->table}\"",
168-
"SELECT key, value FROM \"bytea_{$config->table}\"",
169-
"DELETE FROM \"bytea_{$config->table}\""
170-
);
171171
}
172172

173173
protected function importFromTable(string $fromTable): void

0 commit comments

Comments
 (0)