]> de.git.xonotic.org Git - xonotic/xonstatdb.git/blob - README.md
You know what? We don't need tables for the past!
[xonotic/xonstatdb.git] / README.md
1 This is the source for **xonstatdb**, the [Xonotic][xonotic] [Statistics database][xonstat].
2 All code herein is intended for the PostgreSQL database management server.
3
4 ----
5
6 To build, first create the user that will own all of the objects in the database.
7 You must run this as an administrator user in your cluster.
8 See your operating system's guidelines for how this is set up on your system.
9
10     create user xonstat with password 'xonstat';
11
12    *Note: please change this password*
13
14 Or from the commandline:
15
16     # su - postgres  (as root)
17     postgres$ createuser -P xonstat  (this will prompt you for the users password)
18
19 Next, create the database itself:
20
21     $ psql
22     postgres=#
23
24     CREATE DATABASE xonstatdb
25       WITH ENCODING='UTF8'
26         OWNER=xonstat
27         CONNECTION LIMIT=-1;
28
29     postgres=# \q
30
31 Next, as your regular system user, log into the newly created database
32 using the user account you just created.
33 Do this from the root directory of your project checkout.
34
35     $ psql -U xonstat xonstatdb
36
37 You might need to force postgres to not use ident, if you get an error
38 like *Peer authentication failed for user "xonstat"*:
39
40     $ psql -h localhost -U xonstat xonstatdb
41
42 Create the schema in which all of the xonstat tables will reside:
43
44     xonstatdb=>
45     
46     CREATE SCHEMA xonstat
47         AUTHORIZATION xonstat;
48
49 Create the pgplsql language, if it doesn't exist:
50
51     CREATE LANGUAGE plpgsql;
52
53 Now load the initial tables:
54
55     \i build/build_full.sql
56
57    *Note: You will see a lot of NOTICE messages. This is normal.*
58
59 And that's it!
60
61 Do note that there are a few maintenance scripts that can be used
62 once the database begins accumulating data. These can be found in 
63 the scripts subdirectory. A summary of what they do follows:
64
65   update\_elos.sql - will decrease player elo records by one point 
66                     day for every day after 30 days of inactivity
67                     until they hit the elo "floor" of 100. This 
68                     prevents inactive players from staying on the 
69                     leaderboard/ranks for too long.
70
71   update\_ranks.sql - will populate the player\_ranks table each day
72                      according to the elo values when it is run.
73
74 There is also a "merge players" function in the functions sub-
75 directory. This can be used to merge two players together into one
76 record in the presentation layer of XonStat. It can be run as follows:
77
78   select merge\_players(winner\_player\_id, loser\_player\_id);
79
80 The "winner" player ID is the account that remains active after the
81 transaction.
82
83 Enjoy!
84
85 [xonotic]: http://www.xonotic.org/
86 [xonstat]: http://stats.xonotic.org/
87
88 ----
89
90 Project is licensed GPLv3.