Skip to content

Commit 20ca132

Browse files
committed
Migrate to new schema when needed
1 parent 137f0c8 commit 20ca132

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

eos/db/migration.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
def update(saveddata_engine):
44
checkPriceFailures(saveddata_engine)
5+
checkApiDefaultChar(saveddata_engine)
6+
57

68
def checkPriceFailures(saveddata_engine):
79
# Check if we have 'failed' column
@@ -18,3 +20,22 @@ def checkPriceFailures(saveddata_engine):
1820
except sqlalchemy.exc.DatabaseError:
1921
pass
2022

23+
24+
def checkApiDefaultChar(saveddata_engine):
25+
try:
26+
saveddata_engine.execute("SELECT * FROM characters LIMIT 1")
27+
# If table doesn't exist, it means we're doing everything from scratch
28+
# and sqlalchemy will process everything as needed
29+
except sqlalchemy.exc.DatabaseError:
30+
pass
31+
# If not, we're running on top of existing DB
32+
else:
33+
# Check that we have columns
34+
try:
35+
saveddata_engine.execute("SELECT defaultChar, chars FROM characters LIMIT 1")
36+
# If we don't, create them
37+
# This is ugly as hell, but we can't use proper migrate packages as it
38+
# will require us to rebuild skeletons, including mac
39+
except sqlalchemy.exc.DatabaseError:
40+
saveddata_engine.execute("ALTER TABLE characters ADD COLUMN defaultChar INTEGER;")
41+
saveddata_engine.execute("ALTER TABLE characters ADD COLUMN chars VARCHAR;")

0 commit comments

Comments
 (0)