Files
memind/scripts/reset-tang-subscribe-morning-103.mjs
T
john b09b269199 chore(infra): migrate 103 production host IP to 180.159.29.143
Update scripts, docs, nginx configs, and release-gate safety checks after the Studio server public IP changed from 58.38.22.103.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-11 12:28:19 +08:00

66 lines
2.3 KiB
JavaScript

#!/usr/bin/env node
import { execSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
const HOST = 'john@180.159.29.143';
const REMOTE_ROOT = '/Users/john/Project/Memind';
const NODE103 = '/opt/homebrew/opt/node@24/bin/node';
const TANG = 'a70ff537-8908-486e-9b6c-042e07cc25db';
const remoteScript = `
import path from 'node:path';
import mysql from 'mysql2/promise';
process.loadEnvFile(path.join('${REMOTE_ROOT}', '.env'));
const pool = mysql.createPool({ uri: process.env.DATABASE_URL, connectionLimit: 2 });
const appId = process.env.H5_WECHAT_MP_APP_ID ?? process.env.WECHAT_MP_APP_ID;
const now = Date.now();
const [items] = await pool.query(
\`SELECT id FROM h5_schedule_items
WHERE user_id = ? AND deleted_at IS NULL
AND JSON_UNQUOTE(JSON_EXTRACT(metadata_json, '$.source')) = 'subscribe_morning_reminder'\`,
['${TANG}'],
);
const itemIds = items.map((row) => row.id);
if (itemIds.length) {
await pool.query(
\`DELETE FROM h5_schedule_reminders WHERE user_id = ? AND item_id IN (\${itemIds.map(() => '?').join(',')})\`,
['${TANG}', ...itemIds],
);
await pool.query(
\`UPDATE h5_schedule_items SET status = 'cancelled', deleted_at = ?, updated_at = ?
WHERE user_id = ? AND id IN (\${itemIds.map(() => '?').join(',')})\`,
[now, now, '${TANG}', ...itemIds],
);
}
const [ident] = await pool.query(
'SELECT openid FROM h5_user_wechat_identities WHERE user_id = ? AND app_id = ? LIMIT 1',
['${TANG}', appId],
);
const openid = ident?.[0]?.openid;
if (openid) {
await pool.query(
'DELETE FROM h5_wechat_subscribe_morning_pending WHERE app_id = ? AND openid = ?',
[appId, openid],
);
}
console.log(JSON.stringify({
ok: true,
clearedItems: itemIds.length,
clearedPending: Boolean(openid),
}, null, 2));
await pool.end();
`.trim();
const local = path.join(root, '.tmp-reset-tang-morning.mjs');
fs.writeFileSync(local, remoteScript);
execSync(`scp -q ${local} ${HOST}:${REMOTE_ROOT}/.tmp-reset-tang-morning.mjs`, { stdio: 'inherit' });
execSync(`ssh -o BatchMode=yes ${HOST} 'cd ${REMOTE_ROOT} && ${NODE103} .tmp-reset-tang-morning.mjs && rm -f .tmp-reset-tang-morning.mjs'`, { stdio: 'inherit' });
fs.unlinkSync(local);