| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- const mysql = require('mysql2/promise')
- const DB = process.argv[2] || 'fs_tenant_cs1'
- const cfg = {
- host: 'cq-cdb-8fjmemkb.sql.tencentcdb.com',
- port: 27220,
- user: 'root',
- password: 'Ylrz_1q2w3e4r5t6y',
- database: DB,
- charset: 'utf8mb4',
- multipleStatements: true
- }
- const COLUMNS = [
- {
- name: 'message_dedup_enabled',
- sql: "ADD COLUMN message_dedup_enabled tinyint NOT NULL DEFAULT 1 COMMENT 'message dedup enabled' AFTER quality_multiturn_min_avg_score_percent"
- },
- {
- name: 'message_dedup_exact_window_size',
- sql: "ADD COLUMN message_dedup_exact_window_size int NOT NULL DEFAULT 5 COMMENT 'exact dedup window size' AFTER message_dedup_enabled"
- },
- {
- name: 'message_dedup_semantic_threshold',
- sql: "ADD COLUMN message_dedup_semantic_threshold decimal(4,2) NOT NULL DEFAULT 0.85 COMMENT 'semantic threshold' AFTER message_dedup_exact_window_size"
- },
- {
- name: 'message_dedup_window_duration_seconds',
- sql: "ADD COLUMN message_dedup_window_duration_seconds int NOT NULL DEFAULT 300 COMMENT 'dedup window seconds' AFTER message_dedup_semantic_threshold"
- }
- ]
- async function colExists(c, col) {
- const [r] = await c.query(
- 'SELECT COUNT(*) cnt FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=? AND COLUMN_NAME=?',
- ['lobster_execution_config', col]
- )
- return r[0].cnt > 0
- }
- async function tableExists(c) {
- const [r] = await c.query(
- "SELECT COUNT(*) cnt FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='lobster_execution_config'"
- )
- return r[0].cnt > 0
- }
- async function main() {
- const c = await mysql.createConnection(cfg)
- console.log('Patch lobster_execution_config message_dedup columns on', DB)
- if (!(await tableExists(c))) {
- console.error('Table lobster_execution_config not found')
- process.exit(1)
- }
- for (const col of COLUMNS) {
- if (await colExists(c, col.name)) {
- console.log(' skip', col.name, '(exists)')
- } else {
- await c.query(`ALTER TABLE lobster_execution_config ${col.sql}`)
- console.log(' added', col.name)
- }
- }
- const [cols] = await c.query(
- "SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='lobster_execution_config' AND COLUMN_NAME LIKE 'message_dedup%' ORDER BY ORDINAL_POSITION"
- )
- console.log('message_dedup columns:', cols.map(r => r.COLUMN_NAME).join(', '))
- await c.end()
- }
- main().catch(e => { console.error(e); process.exit(1) })
|