fix(db): repair legacy h5_intent_drafts stub schema on migrate
Memind CI / Test, build, and release guards (push) Successful in 4m12s

Drop tables created with intent_kind instead of layer/draft_type so ITL draft
inserts succeed after one-off migrate scripts.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-08-24 17:29:03 +08:00
parent 1e3a125f83
commit 4100062ba8
+29
View File
@@ -1138,6 +1138,35 @@ export async function migrateSchema(pool) {
CONSTRAINT fk_h5_user_feedback_user FOREIGN KEY (user_id) REFERENCES h5_users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
`);
// One-off migrate stub used intent_kind; ITL expects layer/draft_type/action_level/title.
if (await tableExists(pool, 'h5_intent_drafts') && !(await columnExists(pool, 'h5_intent_drafts', 'layer'))) {
await pool.query('DROP TABLE h5_intent_drafts');
}
await pool.query(`
CREATE TABLE IF NOT EXISTS h5_intent_drafts (
id CHAR(36) PRIMARY KEY,
user_id CHAR(36) NOT NULL,
layer ENUM('L0', 'L1', 'L2', 'L3', 'ambiguous') NOT NULL,
draft_type VARCHAR(64) NOT NULL,
action_level TINYINT UNSIGNED NOT NULL DEFAULT 1,
title VARCHAR(255) NOT NULL,
payload_json JSON NOT NULL,
card_text TEXT NOT NULL,
status ENUM('draft', 'confirmed', 'committed', 'cancelled', 'expired') NOT NULL DEFAULT 'draft',
source_channel VARCHAR(32) NOT NULL DEFAULT 'wechat',
source_message_id VARCHAR(128) NULL,
source_text TEXT NULL,
committed_ref_json JSON NULL,
event_log_json JSON NULL,
expires_at BIGINT NULL,
created_at BIGINT NOT NULL,
updated_at BIGINT NOT NULL,
KEY idx_intent_draft_user_status (user_id, status, created_at),
KEY idx_intent_draft_expires (status, expires_at),
CONSTRAINT fk_intent_draft_user FOREIGN KEY (user_id) REFERENCES h5_users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
`);
}
export async function initSchema(pool) {