require('dotenv').config(); const mysql = require('mysql2/promise'); (async () => { const u = new URL(process.env.DATABASE_URL); const c = await mysql.createConnection({ host: u.hostname, port: Number(u.port), user: decodeURIComponent(u.username), password: decodeURIComponent(u.password), database: u.pathname.replace(/^\//, ''), }); // 保留 id 最小的, 删掉其余重名行 for (const t of ['Strategy', 'Indicator']) { const [r] = await c.query('DELETE FROM ' + t + ' WHERE id NOT IN (SELECT min_id FROM (SELECT MIN(id) AS min_id FROM ' + t + ' GROUP BY name) AS keep)'); console.log('[' + t + '] 删除 ' + r.affectedRows + ' 条重复行'); } await c.end(); })().catch(e=>{console.error(e);process.exit(1)});