From ff9407aba1493f7c5a4b5dc0dbdc3a353f1625b3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 14 Sep 2019 20:35:59 +0200 Subject: [PATCH] Implement a storage update mechanism (for FileStorage) The idea is pretty simple: get the current database version and for each older version, do what needs to be done in order to get to the next version state. This will make schema changes transparent to the user in case they are needed. --- pyrogram/client/storage/file_storage.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pyrogram/client/storage/file_storage.py b/pyrogram/client/storage/file_storage.py index c44c78dd..d0d18ea1 100644 --- a/pyrogram/client/storage/file_storage.py +++ b/pyrogram/client/storage/file_storage.py @@ -67,6 +67,17 @@ class FileStorage(SQLiteStorage): # noinspection PyTypeChecker self.update_peers(peers.values()) + def update(self): + version = self.version() + + if version == 1: + with self.lock, self.conn: + self.conn.execute("DELETE FROM peers") + + version += 1 + + self.version(version) + def open(self): path = self.database file_exists = path.is_file() @@ -97,6 +108,8 @@ class FileStorage(SQLiteStorage): if not file_exists: self.create() + else: + self.update() with self.conn: try: # Python 3.6.0 (exactly this version) is bugged and won't successfully execute the vacuum