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.
This commit is contained in:
parent
1a7d0b1b7e
commit
ff9407aba1
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user