Add migrator for the new peer table

This commit is contained in:
Miroslav Kovar 2019-11-23 20:51:03 +01:00 committed by Jack Robison
parent c832f8ffbb
commit 6bff298d1e
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
3 changed files with 24 additions and 1 deletions

View file

@ -50,7 +50,7 @@ class DatabaseComponent(Component):
@staticmethod
def get_current_db_revision():
return 13
return 14
@property
def revision_filename(self):

View file

@ -33,6 +33,8 @@ def migrate_db(conf, start, end):
from .migrate11to12 import do_migration
elif current == 12:
from .migrate12to13 import do_migration
elif current == 13:
from .migrate13to14 import do_migration
else:
raise Exception(f"DB migration of version {current} to {current+1} is not available")
try:

View file

@ -0,0 +1,21 @@
import os
import sqlite3
def do_migration(conf):
db_path = os.path.join(conf.data_dir, "lbrynet.sqlite")
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.executescript("""
create table if not exists peer (
node_id char(96) not null primary key,
address text not null,
udp_port integer not null,
tcp_port integer,
unique (address, udp_port)
);
""")
connection.commit()
connection.close()