fix: links表加唯一索引(url),initDB幂等,防止Docker容器重复插入数据
This commit is contained in:
@@ -48,8 +48,11 @@ export async function initDB() {
|
|||||||
is_show TINYINT DEFAULT 1,
|
is_show TINYINT DEFAULT 1,
|
||||||
views INTEGER DEFAULT 0,
|
views INTEGER DEFAULT 0,
|
||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
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(`
|
await conn.query(`
|
||||||
CREATE TABLE IF NOT EXISTS settings (
|
CREATE TABLE IF NOT EXISTS settings (
|
||||||
id INTEGER PRIMARY KEY AUTO_INCREMENT,
|
id INTEGER PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
|||||||
Reference in New Issue
Block a user