MCPcopy Create free account
hub / github.com/pyfa-org/Pyfa / upgrade

Function upgrade

eos/db/migrations/upgrade25.py:4205–4248  ·  view source on GitHub ↗
(saveddata_engine)

Source from the content-addressed store, hash-verified

4203
4204
4205def upgrade(saveddata_engine):
4206 # First we want to get a list of fittings that are completely fitted out with subsystems
4207 oldItems = [str(x) for x in conversion2.keys()]
4208
4209 # I can't figure out a way to get IN operator to work when supplying a list using a parameterized query. So I'm
4210 # doing it the shitty way by formatting the SQL string. Don't do this kids!
4211 fits = [x['fitID'] for x in saveddata_engine.execute(
4212 "SELECT fitID FROM modules WHERE itemID IN ({}) GROUP BY fitID HAVING COUNT(*) = 5".format(','.join(oldItems)))]
4213
4214 for fitID in fits:
4215 try:
4216 # Gather a list of the old subsystems and their record IDs
4217 modules = saveddata_engine.execute(
4218 "SELECT * FROM modules WHERE itemID IN ({}) AND fitID = ?".format(','.join(oldItems)), (fitID,))
4219
4220 oldModules = []
4221 for mod in modules:
4222 oldModules.append((mod['ID'], mod['itemID']))
4223
4224 # find the conversion in the Big Fucken Dictionary (BFD)
4225 newModules = conversion.get(frozenset([y[1] for y in oldModules]), None)
4226
4227 if newModules is None:
4228 # We don't have a conversion for this. I don't think this will ever happen, but who knows
4229 continue
4230
4231 # It doesn't actually matter which old module is replaced with which new module, so we don't have to worry
4232 # about module position or anything like that. Just do a straight up record UPDATE
4233 for i, old in enumerate(oldModules[:4]):
4234 saveddata_engine.execute("UPDATE modules SET itemID = ? WHERE ID = ?", (newModules[i], old[0]))
4235
4236 # And last but not least, delete the last subsystem
4237 saveddata_engine.execute("DELETE FROM modules WHERE ID = ?", (oldModules[4][0],))
4238 except (KeyboardInterrupt, SystemExit):
4239 raise
4240 except:
4241 # if something fails, fuck it, we tried. It'll default to the generic conversion below
4242 continue
4243
4244 for oldItem, newItem in conversion2.items():
4245 saveddata_engine.execute('UPDATE "modules" SET "itemID" = ? WHERE "itemID" = ?',
4246 (newItem, oldItem))
4247 saveddata_engine.execute('UPDATE "cargo" SET "itemID" = ? WHERE "itemID" = ?',
4248 (newItem, oldItem))

Callers

nothing calls this directly

Calls 4

itemsMethod · 0.80
keysMethod · 0.45
appendMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected