mirror of
https://github.com/danog/MadelineProto.git
synced 2025-01-23 04:51:13 +01:00
Merge pull request #906 from danog/db_migration
Save old data after new session creation for same account.
This commit is contained in:
commit
e5ba4e93bd
@ -133,13 +133,15 @@ class MysqlArray extends SqlArray
|
|||||||
|
|
||||||
protected function renameTable(string $from, string $to): \Generator
|
protected function renameTable(string $from, string $to): \Generator
|
||||||
{
|
{
|
||||||
Logger::log("Renaming table {$from} to {$to}", Logger::WARNING);
|
Logger::log("Moving data from {$from} to {$to}", Logger::WARNING);
|
||||||
|
|
||||||
yield $this->db->query("
|
yield $this->db->query("
|
||||||
DROP TABLE IF EXISTS `{$to}`;
|
REPLACE INTO `{$to}`
|
||||||
|
SELECT * FROM `{$from}`;
|
||||||
");
|
");
|
||||||
|
|
||||||
yield $this->db->query("
|
yield $this->db->query("
|
||||||
ALTER TABLE `{$from}` RENAME TO `{$to}`;
|
DROP TABLE `{$from}`;
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,14 +180,17 @@ class PostgresArray extends SqlArray
|
|||||||
|
|
||||||
protected function renameTable(string $from, string $to): \Generator
|
protected function renameTable(string $from, string $to): \Generator
|
||||||
{
|
{
|
||||||
Logger::log("Renaming table {$from} to {$to}", Logger::WARNING);
|
Logger::log("Moving data from {$from} to {$to}", Logger::WARNING);
|
||||||
|
|
||||||
yield $this->db->query("
|
yield $this->db->query(/** @lang PostgreSQL */ "
|
||||||
DROP TABLE IF EXISTS \"{$to}\";
|
INSERT INTO \"{$to}\" AS t
|
||||||
|
SELECT * FROM \"{$from}\" as f
|
||||||
|
ON CONFLICT DO UPDATE
|
||||||
|
SET t.value = f.value;
|
||||||
");
|
");
|
||||||
|
|
||||||
yield $this->db->query("
|
yield $this->db->query("
|
||||||
ALTER TABLE \"{$from}\" RENAME TO \"{$to}\";
|
DROP TABLE \"{$from}\";
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ class RedisArray extends DriverArray
|
|||||||
|
|
||||||
protected function renameTable(string $from, string $to): \Generator
|
protected function renameTable(string $from, string $to): \Generator
|
||||||
{
|
{
|
||||||
Logger::log("Renaming table {$from} to {$to}", Logger::WARNING);
|
Logger::log("Moving data from {$from} to {$to}", Logger::WARNING);
|
||||||
$from = "va:$from";
|
$from = "va:$from";
|
||||||
$to = "va:$to";
|
$to = "va:$to";
|
||||||
|
|
||||||
@ -53,8 +53,11 @@ class RedisArray extends DriverArray
|
|||||||
|
|
||||||
$lenK = \strlen($from);
|
$lenK = \strlen($from);
|
||||||
while (yield $request->advance()) {
|
while (yield $request->advance()) {
|
||||||
$key = $request->getCurrent();
|
$oldKey = $request->getCurrent();
|
||||||
yield $this->db->rename($key, $to.\substr($key, $lenK));
|
$newKey = $to.\substr($oldKey, $lenK);
|
||||||
|
$value = yield $this->db->get($oldKey);
|
||||||
|
$this->db->set($newKey, $value);
|
||||||
|
$this->db->delete($oldKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user