fix: links表加唯一索引(url),initDB幂等,防止Docker容器重复插入数据

This commit is contained in:
Agent
2026-07-14 17:42:46 +08:00
parent 7a8a124dcb
commit 534a922d8b
+4 -1
View File
@@ -48,8 +48,11 @@ export async function initDB() {
is_show TINYINT DEFAULT 1,
views INTEGER DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE,
UNIQUE KEY uk_link_url (url)
)`);
// 给已存在的 links 表补唯一索引(幂等)
try { await conn.query("ALTER TABLE links ADD UNIQUE KEY uk_link_url (url)"); } catch { /* 已存在则忽略 */ }
await conn.query(`
CREATE TABLE IF NOT EXISTS settings (
id INTEGER PRIMARY KEY AUTO_INCREMENT,