1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-22 22:51:11 +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:
Alexander Pankratov 2021-03-14 16:45:53 +03:00 committed by GitHub
commit e5ba4e93bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 10 deletions

View File

@ -133,13 +133,15 @@ class MysqlArray extends SqlArray
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("
DROP TABLE IF EXISTS `{$to}`;
REPLACE INTO `{$to}`
SELECT * FROM `{$from}`;
");
yield $this->db->query("
ALTER TABLE `{$from}` RENAME TO `{$to}`;
DROP TABLE `{$from}`;
");
}
}

View File

@ -180,14 +180,17 @@ class PostgresArray extends SqlArray
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("
DROP TABLE IF EXISTS \"{$to}\";
yield $this->db->query(/** @lang PostgreSQL */ "
INSERT INTO \"{$to}\" AS t
SELECT * FROM \"{$from}\" as f
ON CONFLICT DO UPDATE
SET t.value = f.value;
");
yield $this->db->query("
ALTER TABLE \"{$from}\" RENAME TO \"{$to}\";
DROP TABLE \"{$from}\";
");
}
}

View File

@ -45,7 +45,7 @@ class RedisArray extends DriverArray
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";
$to = "va:$to";
@ -53,8 +53,11 @@ class RedisArray extends DriverArray
$lenK = \strlen($from);
while (yield $request->advance()) {
$key = $request->getCurrent();
yield $this->db->rename($key, $to.\substr($key, $lenK));
$oldKey = $request->getCurrent();
$newKey = $to.\substr($oldKey, $lenK);
$value = yield $this->db->get($oldKey);
$this->db->set($newKey, $value);
$this->db->delete($oldKey);
}
}