diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index b276aefb6..3e90e4111 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -198,7 +198,7 @@ class Daemon(AuthJSONRPCServer): self.connected_to_internet = True self.connection_status_code = None self.platform = None - self.current_db_revision = 6 + self.current_db_revision = 7 self.db_revision_file = conf.settings.get_db_revision_filename() self.session = None self._session_id = conf.settings.get_session_id() diff --git a/lbrynet/database/migrator/dbmigrator.py b/lbrynet/database/migrator/dbmigrator.py index e5f141f3a..a4057db38 100644 --- a/lbrynet/database/migrator/dbmigrator.py +++ b/lbrynet/database/migrator/dbmigrator.py @@ -6,22 +6,20 @@ def migrate_db(db_dir, start, end): while current < end: if current == 1: from lbrynet.database.migrator.migrate1to2 import do_migration - do_migration(db_dir) elif current == 2: from lbrynet.database.migrator.migrate2to3 import do_migration - do_migration(db_dir) elif current == 3: from lbrynet.database.migrator.migrate3to4 import do_migration - do_migration(db_dir) elif current == 4: from lbrynet.database.migrator.migrate4to5 import do_migration - do_migration(db_dir) elif current == 5: from lbrynet.database.migrator.migrate5to6 import do_migration - do_migration(db_dir) + elif current == 6: + from lbrynet.database.migrator.migrate6to7 import do_migration else: raise Exception("DB migration of version {} to {} is not available".format(current, current+1)) + do_migration(db_dir) current += 1 return None diff --git a/lbrynet/database/migrator/migrate6to7.py b/lbrynet/database/migrator/migrate6to7.py new file mode 100644 index 000000000..d1778a83e --- /dev/null +++ b/lbrynet/database/migrator/migrate6to7.py @@ -0,0 +1,31 @@ +import sqlite3 +import os +import logging +from lbrynet.database.storage import SQLiteStorage + +log = logging.getLogger(__name__) + + +def run_operation(db): + def _decorate(fn): + def _wrapper(*args): + cursor = db.cursor() + try: + result = fn(cursor, *args) + db.commit() + return result + except sqlite3.IntegrityError: + db.rollback() + raise + return _wrapper + return _decorate + + +def do_migration(db_dir): + db_path = os.path.join(db_dir, "lbrynet.sqlite") + connection = sqlite3.connect(db_path) + cursor = connection.cursor() + cursor.executescript("alter table blob add last_announced_time integer;") + cursor.execute("update blob set next_announce_time=0") + connection.commit() + connection.close() diff --git a/lbrynet/database/storage.py b/lbrynet/database/storage.py index a77a8dae8..88216475d 100644 --- a/lbrynet/database/storage.py +++ b/lbrynet/database/storage.py @@ -124,7 +124,8 @@ class SQLiteStorage(object): blob_length integer not null, next_announce_time integer not null, should_announce integer not null default 0, - status text not null + status text not null, + last_announced_time integer ); create table if not exists stream ( @@ -250,8 +251,8 @@ class SQLiteStorage(object): status = yield self.get_blob_status(blob_hash) if status is None: status = "pending" - yield self.db.runOperation("insert into blob values (?, ?, ?, ?, ?)", - (blob_hash, length, 0, 0, status)) + yield self.db.runOperation("insert into blob values (?, ?, ?, ?, ?, ?)", + (blob_hash, length, 0, 0, status, 0)) defer.returnValue(status) def should_announce(self, blob_hash):