add last_announced_time to blob table
This commit is contained in:
parent
267f50474b
commit
333d70860b
4 changed files with 39 additions and 9 deletions
|
@ -198,7 +198,7 @@ class Daemon(AuthJSONRPCServer):
|
||||||
self.connected_to_internet = True
|
self.connected_to_internet = True
|
||||||
self.connection_status_code = None
|
self.connection_status_code = None
|
||||||
self.platform = 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.db_revision_file = conf.settings.get_db_revision_filename()
|
||||||
self.session = None
|
self.session = None
|
||||||
self._session_id = conf.settings.get_session_id()
|
self._session_id = conf.settings.get_session_id()
|
||||||
|
|
|
@ -6,22 +6,20 @@ def migrate_db(db_dir, start, end):
|
||||||
while current < end:
|
while current < end:
|
||||||
if current == 1:
|
if current == 1:
|
||||||
from lbrynet.database.migrator.migrate1to2 import do_migration
|
from lbrynet.database.migrator.migrate1to2 import do_migration
|
||||||
do_migration(db_dir)
|
|
||||||
elif current == 2:
|
elif current == 2:
|
||||||
from lbrynet.database.migrator.migrate2to3 import do_migration
|
from lbrynet.database.migrator.migrate2to3 import do_migration
|
||||||
do_migration(db_dir)
|
|
||||||
elif current == 3:
|
elif current == 3:
|
||||||
from lbrynet.database.migrator.migrate3to4 import do_migration
|
from lbrynet.database.migrator.migrate3to4 import do_migration
|
||||||
do_migration(db_dir)
|
|
||||||
elif current == 4:
|
elif current == 4:
|
||||||
from lbrynet.database.migrator.migrate4to5 import do_migration
|
from lbrynet.database.migrator.migrate4to5 import do_migration
|
||||||
do_migration(db_dir)
|
|
||||||
elif current == 5:
|
elif current == 5:
|
||||||
from lbrynet.database.migrator.migrate5to6 import do_migration
|
from lbrynet.database.migrator.migrate5to6 import do_migration
|
||||||
do_migration(db_dir)
|
elif current == 6:
|
||||||
|
from lbrynet.database.migrator.migrate6to7 import do_migration
|
||||||
else:
|
else:
|
||||||
raise Exception("DB migration of version {} to {} is not available".format(current,
|
raise Exception("DB migration of version {} to {} is not available".format(current,
|
||||||
current+1))
|
current+1))
|
||||||
|
do_migration(db_dir)
|
||||||
current += 1
|
current += 1
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
31
lbrynet/database/migrator/migrate6to7.py
Normal file
31
lbrynet/database/migrator/migrate6to7.py
Normal 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()
|
|
@ -124,7 +124,8 @@ class SQLiteStorage(object):
|
||||||
blob_length integer not null,
|
blob_length integer not null,
|
||||||
next_announce_time integer not null,
|
next_announce_time integer not null,
|
||||||
should_announce integer not null default 0,
|
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 (
|
create table if not exists stream (
|
||||||
|
@ -250,8 +251,8 @@ class SQLiteStorage(object):
|
||||||
status = yield self.get_blob_status(blob_hash)
|
status = yield self.get_blob_status(blob_hash)
|
||||||
if status is None:
|
if status is None:
|
||||||
status = "pending"
|
status = "pending"
|
||||||
yield self.db.runOperation("insert into blob values (?, ?, ?, ?, ?)",
|
yield self.db.runOperation("insert into blob values (?, ?, ?, ?, ?, ?)",
|
||||||
(blob_hash, length, 0, 0, status))
|
(blob_hash, length, 0, 0, status, 0))
|
||||||
defer.returnValue(status)
|
defer.returnValue(status)
|
||||||
|
|
||||||
def should_announce(self, blob_hash):
|
def should_announce(self, blob_hash):
|
||||||
|
|
Loading…
Add table
Reference in a new issue