lbry-sdk/lbrynet/extras/daemon/migrator/dbmigrator.py

47 lines
1.6 KiB
Python
Raw Normal View History

import logging
log = logging.getLogger(__name__)
2019-01-21 21:55:50 +01:00
def migrate_db(conf, start, end):
current = start
while current < end:
if current == 1:
2018-11-04 20:16:46 +01:00
from .migrate1to2 import do_migration
2017-05-10 17:30:36 +02:00
elif current == 2:
2018-11-04 20:16:46 +01:00
from .migrate2to3 import do_migration
elif current == 3:
2018-11-04 20:16:46 +01:00
from .migrate3to4 import do_migration
elif current == 4:
2018-11-04 20:16:46 +01:00
from .migrate4to5 import do_migration
elif current == 5:
2018-11-04 20:16:46 +01:00
from .migrate5to6 import do_migration
2018-03-27 20:58:29 +02:00
elif current == 6:
2018-11-04 20:16:46 +01:00
from .migrate6to7 import do_migration
elif current == 7:
2018-11-04 20:16:46 +01:00
from .migrate7to8 import do_migration
elif current == 8:
2018-11-04 20:16:46 +01:00
from .migrate8to9 import do_migration
2019-05-07 06:32:23 +02:00
elif current == 9:
from .migrate9to10 import do_migration
else:
raise Exception("DB migration of version {} to {} is not available".format(current,
current+1))
2019-01-21 21:55:50 +01:00
do_migration(conf)
current += 1
log.info("successfully migrated the database from revision %i to %i", current - 1, current)
return None
def run_migration_script():
import sys
log_format = "(%(asctime)s)[%(filename)s:%(lineno)s] %(funcName)s(): %(message)s"
logging.basicConfig(level=logging.DEBUG, format=log_format, filename="migrator.log")
sys.stdout = open("migrator.out.log", 'w')
sys.stderr = open("migrator.err.log", 'w')
migrate_db(sys.argv[1], int(sys.argv[2]), int(sys.argv[3]))
2016-11-28 20:23:10 +01:00
if __name__ == "__main__":
run_migration_script()