-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.sql
More file actions
129 lines (118 loc) · 5.84 KB
/
Copy pathschema.sql
File metadata and controls
129 lines (118 loc) · 5.84 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
hashed_password TEXT NOT NULL,
salt TEXT NOT NULL,
last_login_time INTEGER,
role INTEGER NOT NULL DEFAULT 0, -- 0: user, 1: premium, 2: developer
premium_expire_time INTEGER DEFAULT NULL
);
CREATE TABLE IF NOT EXISTS pending_registrations (
email TEXT PRIMARY KEY,
hashed_password TEXT NOT NULL,
salt TEXT NOT NULL,
verification_code TEXT NOT NULL,
expires_at INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS password_resets (
token TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
expires_at INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS decks (
key TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
deck_name TEXT NOT NULL,
series_id TEXT NOT NULL,
game_type TEXT NOT NULL DEFAULT 'ws', -- 遊戲種類 (ws, wsr)
cover_cards_id TEXT NOT NULL,
deck_data BLOB NOT NULL,
history BLOB NOT NULL,
tags TEXT NOT NULL DEFAULT '[]', -- Tags (存成 JSON 字串,例如 '["我的最愛", "賽場向"]')
updated_at INTEGER,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_decks_user_id ON decks(user_id);
CREATE TABLE IF NOT EXISTS afdian_orders (
id TEXT PRIMARY KEY NOT NULL,
user_id TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'pending', -- 'pending', 'completed', 'failed'
afdian_trade_no TEXT UNIQUE,
created_at INTEGER NOT NULL,
processed_at INTEGER,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS market_listings (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
series_id TEXT NOT NULL, -- 系列名
game_type TEXT NOT NULL DEFAULT 'ws', -- 遊戲種類 (ws, wsr)
cards_id TEXT NOT NULL, -- 聯動人卡號 (存成 JSON 字串)
climax_types TEXT NOT NULL, -- 潮種類 (存成 JSON 字串,例如 '["門", "枝"]')
tags TEXT NOT NULL DEFAULT '[]',-- Tags (存成 JSON 字串,例如 '["賽場向", "娛樂"]')
price INTEGER NOT NULL, -- 價格
shop_url TEXT NOT NULL, -- 賣場連結
deck_code TEXT, -- 卡組代碼
updated_at INTEGER NOT NULL, -- 建立/更新時間
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_listings_user_id ON market_listings(user_id);
CREATE INDEX IF NOT EXISTS idx_listings_updated_id ON market_listings(updated_at DESC, id DESC);
CREATE INDEX IF NOT EXISTS idx_listings_price_asc_id ON market_listings(price ASC, id ASC);
CREATE INDEX IF NOT EXISTS idx_listings_price_desc_id ON market_listings(price DESC, id DESC);
CREATE INDEX IF NOT EXISTS idx_listings_series_updated_id ON market_listings( series_id, updated_at DESC, id DESC);
CREATE INDEX IF NOT EXISTS idx_listings_series_price_asc_id ON market_listings( series_id, price ASC, id ASC);
CREATE INDEX IF NOT EXISTS idx_listings_series_price_desc_id ON market_listings( series_id, price DESC, id DESC);
CREATE TABLE IF NOT EXISTS decks_gallery (
key TEXT PRIMARY KEY,
series_id TEXT NOT NULL,
game_type TEXT NOT NULL DEFAULT 'ws', -- 遊戲種類 (ws, wsr)
user_id TEXT NOT NULL,
deck_name TEXT NOT NULL,
cover_cards_id TEXT NOT NULL,
climax_cards_id TEXT NOT NULL,
deck_data BLOB NOT NULL,
rating_avg REAL DEFAULT 0,
rating_count INTEGER DEFAULT 0,
rating_breakdown TEXT DEFAULT '[0,0,0,0,0]',
updated_at INTEGER,
tournament_type TEXT DEFAULT NULL, -- 比賽類型: 'shop'|'circuit'|'wgp'|'bcf'
participant_count TEXT DEFAULT NULL, -- 參賽人數: 'under10'|'10to20'|'20to30'|'over30'
placement TEXT DEFAULT NULL, -- 名次: 'top4'|'runner_up'|'champion'|'top16'|'top8'
article_link TEXT DEFAULT NULL, -- 文章連結
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_decks_gallery_user_id ON decks_gallery(user_id);
CREATE INDEX IF NOT EXISTS idx_decks_gallery_updated_id ON decks_gallery(updated_at DESC, key DESC);
CREATE INDEX IF NOT EXISTS idx_decks_gallery_updated_asc_id ON decks_gallery(updated_at ASC, key ASC);
CREATE INDEX IF NOT EXISTS idx_decks_gallery_series_updated_id ON decks_gallery(series_id, updated_at DESC, key DESC);
CREATE INDEX IF NOT EXISTS idx_decks_gallery_series_updated_asc_id ON decks_gallery(series_id, updated_at ASC, key ASC);
CREATE INDEX IF NOT EXISTS idx_decks_gallery_rating_desc ON decks_gallery(rating_avg DESC, updated_at DESC, key DESC);
CREATE INDEX IF NOT EXISTS idx_decks_gallery_rating_asc ON decks_gallery(rating_avg ASC, updated_at DESC, key DESC);
CREATE INDEX IF NOT EXISTS idx_decks_gallery_series_rating_desc ON decks_gallery(series_id, rating_avg DESC, updated_at DESC, key DESC);
CREATE INDEX IF NOT EXISTS idx_decks_gallery_series_rating_asc ON decks_gallery(series_id, rating_avg ASC, updated_at DESC, key DESC);
CREATE TABLE IF NOT EXISTS deck_ratings (
deck_key TEXT NOT NULL,
user_id TEXT NOT NULL,
rating INTEGER NOT NULL CHECK (rating BETWEEN 1 AND 5),
updated_at INTEGER NOT NULL,
PRIMARY KEY (deck_key, user_id),
FOREIGN KEY (deck_key) REFERENCES decks_gallery(key) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_deck_ratings_deck_key ON deck_ratings(deck_key);
CREATE INDEX IF NOT EXISTS idx_deck_ratings_user_id ON deck_ratings(user_id);
CREATE TABLE IF NOT EXISTS notices (
id TEXT PRIMARY KEY,
title TEXT NOT NULL,
content TEXT NOT NULL,
is_important INTEGER DEFAULT 0, -- 0: normal, 1: important
updated_at INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_notices_updated_at ON notices(updated_at DESC);
CREATE TABLE IF NOT EXISTS translation_reports (
id INTEGER PRIMARY KEY AUTOINCREMENT,
card_id TEXT NOT NULL,
reason TEXT NOT NULL
);