Skip to content

Commit 2d35ff4

Browse files
committed
fix(driver-sql,cli): a unique index its rows violate is declared not appliable, per entry
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YRXQdFH1TrCyDQ5L1xDQRg
1 parent e5f194b commit 2d35ff4

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎packages/cli/src/utils/schema-migrate.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,8 +1564,9 @@ export async function bootSchemaStack(
15641564
+ 'has a database whose apply limit can be read.',
15651565
);
15661566
}
1567-
// A driver that declares nothing applies what the differ means it to.
1568-
return owner.driftApplyLimit ? owner.driftApplyLimit(entry.op.type) : null;
1567+
// The entry's own limit first (a unique index its rows violate, ADR-0120
1568+
// D4), then the driver's for its op type; neither, and it applies.
1569+
return entry.applyLimit ?? (owner.driftApplyLimit ? owner.driftApplyLimit(entry.op.type) : null);
15691570
},
15701571
managedTableCount,
15711572
kernel,

‎packages/drivers/driver-sql/src/schema-drift.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,18 @@ export interface ManagedDriftEntry extends SchemaDiffEntry {
404404
op: DriftOp;
405405
/** Human one-liner with an actionable hint. */
406406
message: string;
407+
/**
408+
* [ADR-0120 D4] Why the reporting driver's apply door will not perform THIS
409+
* entry on this database, read from its data when the entry was reported —
410+
* absent when nothing in the data stops it. The duplicate pre-flight sets it
411+
* on a unique index the existing rows already violate (the conflicting
412+
* groups are the reason): the apply refuses it however it is confirmed, so
413+
* `os migrate plan` / `apply` list the entry with this reason and never offer
414+
* `--allow-destructive` for it. The one structured form of that judgement;
415+
* ⛔ never re-derived from {@link message}. A limit of a whole op type on a
416+
* transport is the driver's own `driftApplyLimit`, not this.
417+
*/
418+
applyLimit?: string;
407419
}
408420

409421
/**

‎packages/drivers/driver-sql/src/sql-driver.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14190,6 +14190,10 @@ export class SqlDriver implements IDataDriver {
1419014190
const report = formatDuplicateGroups(duplicates);
1419114191
d.category = 'destructive';
1419214192
d.severity = 'error';
14193+
// The block, declared on the entry: `os migrate plan` / `apply` read it
14194+
// here and never offer `--allow-destructive` for an op the apply refuses
14195+
// on this data however it is confirmed.
14196+
d.applyLimit = `existing rows already violate the unique key: ${report}`;
1419314197
d.message = nullSafeKey
1419414198
? `${op.table}: cannot ${tighten ? 'tighten' : 'create'} '${op.indexName}' as ${signature} — existing rows ` +
1419514199
`already violate the NULL-safe unique constraint (duplicates the old index wrongly admitted: SQL ` +

0 commit comments

Comments
 (0)