Files
ln-bi/scripts/migrate-asset-history.ts
T
shishengliang 3ef30215e0
ci/woodpecker/push/woodpecker Pipeline was successful
feat(assets): 每天23:55采集资产状态快照
2026-10-30 16:57:33 +08:00

14 lines
756 B
TypeScript

import { readFile } from 'node:fs/promises';
const migration = process.argv.includes('--daily') ? '20261030_asset_history_daily.sql' : '20261019_asset_history.sql';
const sql = await readFile(new URL(`../migrations/${migration}`, import.meta.url), 'utf8');
if (!process.argv.includes('--apply')) {
console.log(sql);
console.log('Review only. Pass --apply only after approving the configured database migration.');
} else {
const { default: pool } = await import('../src/server/db.js');
try {
for (const statement of sql.split(/;\s*(?:\n|$)/).filter(s => s.trim())) await pool.query(statement);
console.log('Asset history schema ready. Capture is still disabled unless ASSET_HISTORY_CAPTURE_ENABLED=1.');
} finally { await pool.end(); }
}