mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-09-16 14:23:44 +00:00
Operator-run migration scripts for KV→Mongo and D1→trading_trades, plus a parity verifier and a rollback wiper. Pure local Node — no Worker code, no /__admin/* routes, no new Worker secrets. Complies with docs/architecture.md §10. Scripts - backfill-kv-to-mongo.js: paginates CF KV REST API per module, fetches values, $setOnInsert upsert into per-module Mongo collection. Resumes from .backfill-cursor-<module>.json on restart. Throttles 50 ops/sec. expiresAt derived from KV metadata.expiration (debugger #10). --dry-run and --module flags for incremental work. - backfill-d1-to-mongo.js: wrangler d1 execute --remote --json → parse → insertMany batches into trading_trades, preserving original integer id as legacy_id (code-reviewer #13). Pre-flight aborts if collection non-empty unless --force. - verify-mongo-parity.js: count parity ±1%, SHA256 value compare, expiresAt ±5min bucket. Full-scan when <10K docs, sqrt-sample capped at 500 otherwise (code-reviewer #21). Trading: full-scan on legacy_id/ts/user_id/symbol/qty. - wipe-mongo.js: rollback helper. deleteMany across all collections with readline confirm. --yes for CI. - lib/migration-helpers.js: shared sleep, sha256, checkpoint I/O, cfKvList/cfKvGet, MongoClient singleton, sample strategy. Surface updates - .env.deploy.example: CF account/token/namespace placeholders. - package.json: backfill:kv[:dry], backfill:d1[:dry], verify:mongo, wipe:mongo scripts. - check-secret-leaks.js: SECRETS array gains CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID for defense-in-depth. - .gitignore: .backfill-cursor-*.json excluded. Tests: 638 → 667 (+29 pure-logic tests for sha256, checkpoint round-trip, count-diff, sample-size, fetch-mocked CF REST). Lint clean. Operator-run sequence (after Phase 06 deploy): npm run backfill:kv:dry # preview npm run backfill:kv npm run backfill:d1:dry npm run backfill:d1 npm run verify:mongo # exit 0 = parity ok
43 lines
1.8 KiB
JSON
43 lines
1.8 KiB
JSON
{
|
|
"name": "miti99bot",
|
|
"version": "0.1.0",
|
|
"description": "Telegram bot with plug-n-play module system, deployed to Cloudflare Workers.",
|
|
"private": true,
|
|
"type": "module",
|
|
"engines": {
|
|
"node": ">=20.6"
|
|
},
|
|
"scripts": {
|
|
"dev": "wrangler dev",
|
|
"build": "npm run build:wordle-data && npm run build:semantle-words",
|
|
"build:wordle-data": "node scripts/build-wordle-data.js",
|
|
"build:semantle-words": "node scripts/build-semantle-words.js",
|
|
"scrape:loldle-data": "node scripts/scrape-loldle-data.js",
|
|
"fetch:ddragon-data": "node scripts/fetch-ddragon-data.js",
|
|
"deploy": "npm run build && wrangler deploy && npm run db:migrate && npm run register",
|
|
"db:migrate": "node scripts/migrate.js",
|
|
"register": "node --env-file-if-exists=.env.deploy scripts/register.js",
|
|
"register:dry": "node --env-file-if-exists=.env.deploy scripts/register.js --dry-run",
|
|
"backfill:kv": "node --env-file-if-exists=.env.deploy scripts/backfill-kv-to-mongo.js",
|
|
"backfill:kv:dry": "node --env-file-if-exists=.env.deploy scripts/backfill-kv-to-mongo.js --dry-run",
|
|
"backfill:d1": "node --env-file-if-exists=.env.deploy scripts/backfill-d1-to-mongo.js",
|
|
"backfill:d1:dry": "node --env-file-if-exists=.env.deploy scripts/backfill-d1-to-mongo.js --dry-run",
|
|
"verify:mongo": "node --env-file-if-exists=.env.deploy scripts/verify-mongo-parity.js",
|
|
"wipe:mongo": "node --env-file-if-exists=.env.deploy scripts/wipe-mongo.js",
|
|
"lint": "biome check . && eslint src && node scripts/check-secret-leaks.js",
|
|
"format": "biome format --write .",
|
|
"test": "vitest run"
|
|
},
|
|
"dependencies": {
|
|
"grammy": "^1.30.0",
|
|
"mongodb": "^6.21.0"
|
|
},
|
|
"devDependencies": {
|
|
"@biomejs/biome": "^1.9.0",
|
|
"eslint": "^10.2.0",
|
|
"eslint-plugin-jsdoc": "^62.9.0",
|
|
"vitest": "^4.1.4",
|
|
"wrangler": "^4.84.0"
|
|
}
|
|
}
|