Skip to content

Commit ff9407a

Browse files
committed
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.
1 parent 1a7d0b1 commit ff9407a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pyrogram/client/storage/file_storage.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ def migrate_from_json(self, session_json: dict):
6767
# noinspection PyTypeChecker
6868
self.update_peers(peers.values())
6969

70+
def update(self):
71+
version = self.version()
72+
73+
if version == 1:
74+
with self.lock, self.conn:
75+
self.conn.execute("DELETE FROM peers")
76+
77+
version += 1
78+
79+
self.version(version)
80+
7081
def open(self):
7182
path = self.database
7283
file_exists = path.is_file()
@@ -97,6 +108,8 @@ def open(self):
97108

98109
if not file_exists:
99110
self.create()
111+
else:
112+
self.update()
100113

101114
with self.conn:
102115
try: # Python 3.6.0 (exactly this version) is bugged and won't successfully execute the vacuum

0 commit comments

Comments
 (0)