aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/migrations
diff options
context:
space:
mode:
authorGravatar Momo <[email protected]>2018-06-23 23:13:03 +0000
committerGravatar Momo <[email protected]>2018-06-23 23:13:03 +0000
commit3c1348a959937bb1e6ee3fabe9892136e5b13167 (patch)
treeba9172b2b0a6d3fdbab69d19dc1fa93053c04a93 /pysite/migrations
parent[API] Check for DB-nuking empty data in users POST (diff)
parent[Jams/Teams] Hopefully optimize jam team list (diff)
Merge branch 'momo/optimize-teams-list' into 'master'
Optimize team lists and better relations See merge request python-discord/projects/site!10
Diffstat (limited to 'pysite/migrations')
-rw-r--r--pysite/migrations/tables/code_jam_teams/__init__.py0
-rw-r--r--pysite/migrations/tables/code_jam_teams/v1.py13
-rw-r--r--pysite/migrations/tables/code_jams/v2.py10
3 files changed, 23 insertions, 0 deletions
diff --git a/pysite/migrations/tables/code_jam_teams/__init__.py b/pysite/migrations/tables/code_jam_teams/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/pysite/migrations/tables/code_jam_teams/__init__.py
diff --git a/pysite/migrations/tables/code_jam_teams/v1.py b/pysite/migrations/tables/code_jam_teams/v1.py
new file mode 100644
index 00000000..165d3100
--- /dev/null
+++ b/pysite/migrations/tables/code_jam_teams/v1.py
@@ -0,0 +1,13 @@
+def run(db, table, table_obj):
+ """
+ Associate the ID of each team's code jam (team -> jam)
+ """
+
+ for document in db.get_all(table):
+ if "jam" not in document:
+ # find the code jam containing this team
+ for jam in db.get_all("code_jams"):
+ if document["id"] in jam["teams"]:
+ document["jam"] = jam["number"]
+ db.insert(table, document, conflict="update", durability="soft")
+ db.sync(table)
diff --git a/pysite/migrations/tables/code_jams/v2.py b/pysite/migrations/tables/code_jams/v2.py
new file mode 100644
index 00000000..df4752c8
--- /dev/null
+++ b/pysite/migrations/tables/code_jams/v2.py
@@ -0,0 +1,10 @@
+def run(db, table, table_obj):
+ """
+ Clean list of teams from teams that do not exist anymore.
+ """
+ for document in db.get_all(table):
+ for team_id in document["teams"]:
+ if db.get("code_jam_teams", team_id) is None:
+ document["teams"].remove(team_id)
+ db.insert(table, document, conflict="update", durability="soft")
+ db.sync(table)