refactor: consolidate database migrations into baseline
This commit is contained in:
1 parent
8794686c3a
commit
11a56cf44e
7 files changed
+15
-37
No files matched your search
@@ -17,9 +17,12 @@ CREATE TABLE rooms (
|
||||
password_hash text,
|
||||
-- 接管房间时加 1;落盘以它为条件,因此过期的 owner 无法写入。
|
||||
term bigint NOT NULL DEFAULT 0,
|
||||
play_mode text NOT NULL DEFAULT 'sequential' CHECK (play_mode IN ('sequential', 'random')),
|
||||
play_mode text NOT NULL DEFAULT 'sequential' CHECK (play_mode IN ('sequential', 'random', 'rotation')),
|
||||
entry_seq bigint NOT NULL DEFAULT 0,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
-- 第一次生成 API Key 时创建,此后重置 Key、修改密码都不换。
|
||||
bot_member_id uuid REFERENCES members,
|
||||
CHECK (bot_member_id IS NULL OR kind = 'persistent')
|
||||
);
|
||||
|
||||
CREATE TABLE room_entries (
|
||||
@@ -42,6 +45,9 @@ CREATE TABLE room_entries (
|
||||
likes integer NOT NULL,
|
||||
added_at timestamptz NOT NULL,
|
||||
started_at timestamptz CHECK ((slot = 'current') = (started_at IS NOT NULL)),
|
||||
page_url text NOT NULL,
|
||||
-- 条目的轮次在入队时定下,轮流播放时点赞数相同的歌按它排列。
|
||||
round bigint NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (room_id, entry_id)
|
||||
);
|
||||
|
||||
@@ -68,12 +74,12 @@ CREATE TABLE tracks (
|
||||
duration_ms bigint NOT NULL,
|
||||
gain double precision NOT NULL,
|
||||
lyric text,
|
||||
kuwo_id text NOT NULL,
|
||||
media_key text,
|
||||
media_size bigint,
|
||||
prepared_at timestamptz NOT NULL DEFAULT now(),
|
||||
-- 临时房间的播放记录随房间删除,所以不从 plays 计算。
|
||||
last_played_at timestamptz,
|
||||
page_url text NOT NULL,
|
||||
PRIMARY KEY (source, track_id)
|
||||
);
|
||||
|
||||
@@ -98,3 +104,9 @@ CREATE TABLE credentials (
|
||||
value text NOT NULL,
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
-- 至多一行;没有这一行时品牌名是默认的 Alisten。
|
||||
CREATE TABLE site (
|
||||
id boolean PRIMARY KEY DEFAULT true CHECK (id),
|
||||
brand_name text NOT NULL
|
||||
);
|
||||
@@ -1,5 +0,0 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE room_entries ADD COLUMN page_url text NOT NULL DEFAULT '';
|
||||
ALTER TABLE room_entries ALTER COLUMN page_url DROP DEFAULT;
|
||||
ALTER TABLE tracks ADD COLUMN page_url text NOT NULL DEFAULT '';
|
||||
ALTER TABLE tracks ALTER COLUMN page_url DROP DEFAULT;
|
||||
@@ -1,2 +0,0 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE tracks DROP COLUMN kuwo_id;
|
||||
@@ -1,11 +0,0 @@
|
||||
-- +goose Up
|
||||
-- 第一次生成 API Key 时创建,此后重置 Key、修改密码都不换。
|
||||
ALTER TABLE rooms
|
||||
ADD COLUMN bot_member_id uuid REFERENCES members,
|
||||
ADD CHECK (bot_member_id IS NULL OR kind = 'persistent');
|
||||
|
||||
-- 凭证只存哈希的唯一例外:API Key 要能随时给进过房间的成员和管理员查看。Key 就是 bot 成员的票据,票据作废时明文随之删除。
|
||||
CREATE TABLE room_api_keys (
|
||||
token_hash bytea PRIMARY KEY REFERENCES room_tickets ON DELETE CASCADE,
|
||||
key text NOT NULL
|
||||
);
|
||||
@@ -1,6 +0,0 @@
|
||||
-- +goose Up
|
||||
-- 条目的轮次在入队时定下,轮流播放时点赞数相同的歌按它排列;已有的条目都算第 0 轮。
|
||||
ALTER TABLE room_entries ADD COLUMN round bigint NOT NULL DEFAULT 0;
|
||||
ALTER TABLE rooms
|
||||
DROP CONSTRAINT rooms_play_mode_check,
|
||||
ADD CONSTRAINT rooms_play_mode_check CHECK (play_mode IN ('sequential', 'random', 'rotation'));
|
||||
@@ -1,4 +0,0 @@
|
||||
-- +goose Up
|
||||
-- 已有的 Key 都给进过房间的成员看过,一起作废;bot 成员留给重新生成的 Key。
|
||||
DROP TABLE room_api_keys;
|
||||
DELETE FROM room_tickets t USING rooms r WHERE t.room_id = r.id AND t.member_id = r.bot_member_id;
|
||||
@@ -1,6 +0,0 @@
|
||||
-- +goose Up
|
||||
-- 至多一行;没有这一行时品牌名是默认的 Alisten。
|
||||
CREATE TABLE site (
|
||||
id boolean PRIMARY KEY DEFAULT true CHECK (id),
|
||||
brand_name text NOT NULL
|
||||
);
|
||||
Reference in new issue
Block a user