summaryrefslogtreecommitdiff
path: root/qutebrowser/misc
diff options
context:
space:
mode:
authorlufte <javier@lufte.net>2021-06-27 16:20:28 -0300
committerlufte <javier@lufte.net>2021-06-27 16:20:28 -0300
commit779fcb13ec7fd90ff8422640e40babe87de97c99 (patch)
tree7aaf8d8ea5c7f16f5d534fe5c60a90106dbddc53 /qutebrowser/misc
parentd806c2f22408a6cd2eeaddfc8c708f742319aaaa (diff)
downloadqutebrowser-779fcb13ec7fd90ff8422640e40babe87de97c99.tar.gz
qutebrowser-779fcb13ec7fd90ff8422640e40babe87de97c99.zip
Upgrade user_version after migrations have run
Diffstat (limited to 'qutebrowser/misc')
-rw-r--r--qutebrowser/misc/sql.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/qutebrowser/misc/sql.py b/qutebrowser/misc/sql.py
index 40ebc0368..300315411 100644
--- a/qutebrowser/misc/sql.py
+++ b/qutebrowser/misc/sql.py
@@ -254,22 +254,6 @@ class Database:
"Database is too new for this qutebrowser version (database version "
f"{self._user_version}, but {self._USER_VERSION.major}.x is supported)")
- if self.user_version_changed():
- log.sql.debug(f"Migrating from version {self._user_version} "
- f"to {self._USER_VERSION}")
- # Note we're *not* updating _user_version here. We still want
- # user_version_changed() to return True, as other modules (such as
- # history.py) use it to create the initial table structure.
- self.query(f'PRAGMA user_version = {_USER_VERSION.to_int()}').run()
-
- # Enable write-ahead-logging and reduce disk write frequency
- # see https://sqlite.org/pragma.html and issues #2930 and #3507
- #
- # We might already have done this (without a migration) in earlier versions,
- # but as those are idempotent, let's make sure we run them once again.
- self.query("PRAGMA journal_mode=WAL").run()
- self.query("PRAGMA synchronous=NORMAL").run()
-
def qSqlDatabase(self):
database = QSqlDatabase.database(self._path, open=True)
if not database.isValid():
@@ -287,6 +271,24 @@ class Database:
"""Whether the version stored in the database differs from the current one."""
return self._user_version != self._USER_VERSION
+ def upgrade_user_version(self):
+ """Upgrades the user version to the latest version.
+
+ This method should be called once all required operations to migrate from one
+ version to another have been run.
+ """
+ log.sql.debug(f"Migrating from version {self._user_version} "
+ f"to {self._USER_VERSION}")
+ self.query(f'PRAGMA user_version = {self._USER_VERSION.to_int()}').run()
+ self._user_version = self._USER_VERSION
+ # Enable write-ahead-logging and reduce disk write frequency
+ # see https://sqlite.org/pragma.html and issues #2930 and #3507
+ #
+ # We might already have done this (without a migration) in earlier versions,
+ # but as those are idempotent, let's make sure we run them once again.
+ self.query("PRAGMA journal_mode=WAL").run()
+ self.query("PRAGMA synchronous=NORMAL").run()
+
def close(self):
"""Close the SQL connection."""
database = self.qSqlDatabase()