add last_announced_time to blob table

This commit is contained in:
Jack Robison 2018-03-27 14:58:29 -04:00
parent 267f50474b
commit 333d70860b
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
4 changed files with 39 additions and 9 deletions

View file

@ -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()

View file

@ -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

View file

@ -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()

View file

@ -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):