DB migration is triggered by number of upgrade files found, rather than number in config.py. This allows us to remove the db version variable in config.py and not worry about it.

This commit is contained in:
blitzmann
2015-07-02 19:35:53 -04:00
parent 646f3afd27
commit 87e5929cb1
3 changed files with 13 additions and 16 deletions

View File

@@ -19,10 +19,6 @@ expansionName = "Carnyx"
expansionVersion = "1.0"
evemonMinVersion = "4081"
# Database version (int ONLY)
# Increment every time we need to flag for user database upgrade/modification
dbversion = 7
pyfaPath = None
savePath = None
staticPath = None

View File

@@ -1,32 +1,36 @@
import config
import shutil
import time
import os
def getVersion(db):
cursor = db.execute('PRAGMA user_version')
return cursor.fetchone()[0]
def update(saveddata_engine):
currversion = getVersion(saveddata_engine)
dbVersion = getVersion(saveddata_engine)
if currversion == config.dbversion:
files = os.listdir(os.path.join(os.path.dirname(__file__), "migrations"))
appVersion = len([f for f in files if f.startswith("upgrade")])
if dbVersion == appVersion:
return
if currversion < config.dbversion:
if dbVersion < appVersion:
# Automatically backup database
toFile = "%s/saveddata_migration_%d-%d_%s.db"%(
config.savePath,
currversion,
config.dbversion,
dbVersion,
appVersion,
time.strftime("%Y%m%d_%H%M%S"))
shutil.copyfile(config.saveDB, toFile)
for version in xrange(currversion, config.dbversion):
for version in xrange(dbVersion, appVersion):
module = __import__('eos.db.migrations.upgrade%d'%(version+1), fromlist=True)
upgrade = getattr(module, "upgrade", False)
if upgrade:
upgrade(saveddata_engine)
# when all is said and done, set version to current
saveddata_engine.execute('PRAGMA user_version = %d'%config.dbversion)
saveddata_engine.execute('PRAGMA user_version = %d'%appVersion)

View File

@@ -1,13 +1,10 @@
"""
Migration 4
Migration 8
- Converts modules based on Proteus Module Tiericide
- Converts modules based on Carnyx Module Tiericide
Some modules have been unpublished (and unpublished module attributes are removed
from database), which causes pyfa to crash. We therefore replace these
modules with their new replacements
Based on http://community.eveonline.com/news/patch-notes/patch-notes-for-proteus/
and output of itemDiff.py
"""