added createSchema.sql, implemented Dockerfile
This commit is contained in:
parent
7a5596a4a8
commit
c67f869d4d
2 changed files with 43 additions and 0 deletions
|
|
@ -0,0 +1,4 @@
|
||||||
|
FROM postgres:15
|
||||||
|
|
||||||
|
RUN mkdir /docker-entrypoint-initdb.d
|
||||||
|
COPY createSchema.sql /docker-entrypoint-initdb.d
|
||||||
39
backend/db/createSchema.sql
Normal file
39
backend/db/createSchema.sql
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
CREATE TABLE "user" (
|
||||||
|
username VARCHAR(32) PRIMARY KEY
|
||||||
|
)
|
||||||
|
|
||||||
|
CREATE TABLE game (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
score INTEGER NOT NULL,
|
||||||
|
playtime TIME NOT NULL,
|
||||||
|
date DATE NOT NULL,
|
||||||
|
username VARCHAR(32) NOT NULL FOREIGN KEY REFERENCES "user"
|
||||||
|
)
|
||||||
|
|
||||||
|
CREATE VIEW user_data AS (
|
||||||
|
SELECT
|
||||||
|
username,
|
||||||
|
max(score) AS highscore,
|
||||||
|
sum(score) AS total_score,
|
||||||
|
sum(playtime) AS total_playtime,
|
||||||
|
avg(score) AS average_score,
|
||||||
|
count(*) AS games_played
|
||||||
|
FROM game
|
||||||
|
GROUP BY username
|
||||||
|
)
|
||||||
|
|
||||||
|
CREATE VIEW lb_highscore AS (
|
||||||
|
SELECT username, max(score) AS highscore FROM game GROUP BY username ORDER BY highscore DESC
|
||||||
|
)
|
||||||
|
|
||||||
|
CREATE VIEW lb_highscore AS (
|
||||||
|
SELECT username, sum(score) AS total_score, FROM game GROUP BY username ORDER BY total_score DESC
|
||||||
|
)
|
||||||
|
|
||||||
|
CREATE VIEW lb_total_playtime AS (
|
||||||
|
SELECT username, sum(playtime) AS total_playtime FROM game GROUP BY username ORDER BY total_playtime DESC
|
||||||
|
)
|
||||||
|
|
||||||
|
CREATE VIEW lb_average_score AS (
|
||||||
|
SELECT username, avg(score) AS average_score FROM game GROUP BY username ORDER BY average_score DESC
|
||||||
|
)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue