chore(db)!: final database v1 structure

- clear_type preserved for R10 calculate
- best_30 -> bests for better flexibility
This commit is contained in:
283375 2023-06-21 16:28:44 +08:00
parent 73a0906633
commit 920e2bda98

View File

@ -9,6 +9,7 @@ class VersionSqls(TypedDict):
INIT_SQLS: Dict[int, VersionSqls] = { INIT_SQLS: Dict[int, VersionSqls] = {
1: { 1: {
"init": [ "init": [
# region CREATE
""" """
CREATE TABLE IF NOT EXISTS charts ( CREATE TABLE IF NOT EXISTS charts (
song_id TEXT NOT NULL, song_id TEXT NOT NULL,
@ -55,11 +56,12 @@ INIT_SQLS: Dict[int, VersionSqls] = {
song_id TEXT NOT NULL, song_id TEXT NOT NULL,
rating_class INTEGER NOT NULL, rating_class INTEGER NOT NULL,
score INTEGER NOT NULL, score INTEGER NOT NULL,
pure INTEGER NOT NULL, pure INTEGER,
far INTEGER NOT NULL, far INTEGER,
lost INTEGER NOT NULL, lost INTEGER,
time INTEGER NOT NULL, time INTEGER NOT NULL,
max_recall INTEGER, max_recall INTEGER,
clear_type INTEGER,
FOREIGN KEY (song_id, rating_class) REFERENCES charts(song_id, rating_class) ON UPDATE CASCADE ON DELETE NO ACTION FOREIGN KEY (song_id, rating_class) REFERENCES charts(song_id, rating_class) ON UPDATE CASCADE ON DELETE NO ACTION
) )
@ -98,7 +100,7 @@ INIT_SQLS: Dict[int, VersionSqls] = {
scores.rating_class scores.rating_class
""", """,
""" """
CREATE VIEW IF NOT EXISTS best_30 AS CREATE VIEW IF NOT EXISTS bests AS
SELECT SELECT
c.song_id, c.song_id,
c.rating_class, c.rating_class,
@ -110,14 +112,13 @@ INIT_SQLS: Dict[int, VersionSqls] = {
c.rating_class c.rating_class
ORDER BY ORDER BY
potential DESC potential DESC
LIMIT 30
""", """,
""" """
CREATE VIEW IF NOT EXISTS calculated_potential AS CREATE VIEW IF NOT EXISTS calculated_potential AS
SELECT SELECT
b30_avg AS b30 b30_avg AS b30
FROM FROM
(SELECT SUM(potential) AS b30_sum, AVG(potential) AS b30_avg, COUNT(*) AS b30_count FROM best_30) b30 ( SELECT AVG(potential) AS b30_avg FROM bests ORDER BY potential DESC LIMIT 30 )
""", """,
""" """
CREATE VIEW IF NOT EXISTS song_id_names AS CREATE VIEW IF NOT EXISTS song_id_names AS
@ -134,6 +135,12 @@ INIT_SQLS: Dict[int, VersionSqls] = {
WHERE name IS NOT NULL AND name <> '' WHERE name IS NOT NULL AND name <> ''
GROUP BY song_id, name GROUP BY song_id, name
""", """,
# endregion
# region INSERT
"""
INSERT INTO properties VALUES ('db_version', '1')
"""
# endregion
], ],
"update": [], "update": [],
} }