fix: close competition cutover integrity gaps
This commit is contained in:
1 parent
7ea2002975
commit
683d602d63
57 files changed
+4805
-1582
No files matched your search
@@ -15,6 +15,7 @@ export interface CompetitionDomainCliOptions {
|
||||
dryRun: boolean;
|
||||
help: boolean;
|
||||
limit?: number;
|
||||
afterMatchId?: string;
|
||||
nodeEnv: string;
|
||||
}
|
||||
|
||||
@@ -60,6 +61,7 @@ export function parseCliOptions(argv: string[]): CompetitionDomainCliOptions {
|
||||
let dryRun = true;
|
||||
let help = false;
|
||||
let limit: number | undefined;
|
||||
let afterMatchId: string | undefined;
|
||||
let nodeEnv = process.env.NODE_ENV ?? 'dev';
|
||||
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
@@ -95,6 +97,15 @@ export function parseCliOptions(argv: string[]): CompetitionDomainCliOptions {
|
||||
limit = positiveInteger(argument.slice('--limit='.length), '--limit');
|
||||
continue;
|
||||
}
|
||||
if (argument === '--after') {
|
||||
afterMatchId = matchObjectId(argv[index + 1]);
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (argument.startsWith('--after=')) {
|
||||
afterMatchId = matchObjectId(argument.slice('--after='.length));
|
||||
continue;
|
||||
}
|
||||
if (argument === '--help' || argument === '-h') {
|
||||
help = true;
|
||||
continue;
|
||||
@@ -105,7 +116,7 @@ export function parseCliOptions(argv: string[]): CompetitionDomainCliOptions {
|
||||
if (!['dev', 'staging', 'prod'].includes(nodeEnv)) {
|
||||
throw new Error('--env must be dev, staging, or prod.');
|
||||
}
|
||||
return { dryRun, help, limit, nodeEnv };
|
||||
return { dryRun, help, limit, afterMatchId, nodeEnv };
|
||||
}
|
||||
|
||||
function positiveInteger(value: string | undefined, label: string): number {
|
||||
@@ -116,6 +127,15 @@ function positiveInteger(value: string | undefined, label: string): number {
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function matchObjectId(value: string | undefined): string {
|
||||
if (!value || !/^[a-f\d]{24}$/i.test(value)) {
|
||||
throw new Error(
|
||||
'--after requires a 24-character hexadecimal Match ObjectId.',
|
||||
);
|
||||
}
|
||||
return value.toLowerCase();
|
||||
}
|
||||
|
||||
function printHelp(): void {
|
||||
process.stdout.write(`Usage:
|
||||
pnpm --silent --filter api competition:migrate
|
||||
@@ -125,7 +145,8 @@ Options:
|
||||
--dry-run Plan and report without writes. Default.
|
||||
--apply Apply one transaction per Match.
|
||||
--env <env> dev | staging | prod. Default: NODE_ENV or dev.
|
||||
--limit <n> Scan at most n Matches in deterministic _id order.
|
||||
--limit <n> Scan at most n Matches. Apply resumes from a durable checkpoint.
|
||||
--after <id> Override the checkpoint with a Match ObjectId cursor.
|
||||
|
||||
The JSON report is written to stdout; the concise human summary is written to stderr.
|
||||
`);
|
||||
@@ -153,6 +174,7 @@ async function main(): Promise<void> {
|
||||
{
|
||||
dryRun: options.dryRun,
|
||||
limit: options.limit,
|
||||
afterMatchId: options.afterMatchId,
|
||||
startSession: options.dryRun
|
||||
? undefined
|
||||
: async () => connection.startSession(),
|
||||
@@ -164,11 +186,15 @@ async function main(): Promise<void> {
|
||||
`db=${resolveMongoDbName(options.nodeEnv)} scanned=${summary.scanned} ` +
|
||||
`ready=${summary.ready} applied=${summary.applied} ` +
|
||||
`alreadyApplied=${summary.alreadyApplied} quarantined=${summary.quarantined} ` +
|
||||
`failed=${summary.failed} unclassified=${summary.unclassified}\n`,
|
||||
`failed=${summary.failed} unclassified=${summary.unclassified} ` +
|
||||
`indexPreflight=${result.indexPreflight.status} ` +
|
||||
`resume=${result.resume.checkpointAfterMatchId ?? 'none'} ` +
|
||||
`completed=${result.resume.completed}\n`,
|
||||
);
|
||||
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
||||
|
||||
if (summary.failed > 0) process.exitCode = 1;
|
||||
if (result.indexPreflight.status === 'blocked') process.exitCode = 1;
|
||||
else if (summary.failed > 0) process.exitCode = 1;
|
||||
else if (summary.quarantined > 0) process.exitCode = 2;
|
||||
} finally {
|
||||
await app.close().catch((error: unknown) => {
|
||||
|
||||
Reference in new issue
Block a user