This repository has been archived by the owner on May 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_setup.py
51 lines (37 loc) · 2.1 KB
/
db_setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python2
# -*- coding: utf-8 -*-
#Copyright (C) 2015 Erik Söderberg
#See LICENSE for more information
import sqlite3
import sys
def initdb(loc="rocketleague.db"):
# print the connection string we will use to connect
print "Connecting to database: "+loc
conn = sqlite3.connect(loc)
conn.execute("PRAGMA foreign_keys = ON")
with conn:
#ID; FILENAME; NAME; MAP;
conn.execute("CREATE TABLE replays (id INTEGER PRIMARY KEY, filename text UNIQUE, name text, map text, date_time text);")
#ID(fk); TEAM; PLAYERCOUNT; GOALS; (information about a team in a match)
conn.execute("CREATE TABLE match_data (id integer REFERENCES replays ON DELETE CASCADE, team integer, playercount integer, goals integer, saves integer);")
#ID(fk);TEAM; PLAYERNAME; GOALS; SAVES; (information about a player in a match)
conn.execute("CREATE TABLE teams (id integer REFERENCES replays ON DELETE CASCADE, playername text, team integer, goals integer, saves integer,shots integer, assists integer, score integer);")
#ID(fk);TAGNAME;TIMESTAMP; (User created time tags for a match)
conn.execute("CREATE TABLE tags (id integer REFERENCES replays ON DELETE CASCADE, tagname text, timestamp integer);")
#ID(fk); NOTE; (Other notes that doesn't have a timestamp)
conn.execute("CREATE TABLE notes (id integer REFERENCES replays ON DELETE CASCADE, note text);")
#ID;NAME; (For grouping a set of replays together)
conn.execute("CREATE TABLE groups (g_id integer PRIMARY KEY, name text UNIQUE);")
#Many-to-Many relation
conn.execute("CREATE TABLE group_members (g_id integer REFERENCES groups ON DELETE CASCADE, id integer REFERENCES replays ON DELETE CASCADE, PRIMARY KEY (g_id,id));")
print "Success!"
if loc == ":memory:":
return conn
conn.close()
if __name__ == "__main__":
if len(sys.argv) == 1:
initdb()
if len(sys.argv) == 2 and sys.argv[1] == "test":
initdb()
import test_db
test_db.populate_test("rocketleague.db")