@prisma-next/cli 0.1.0-pr.59.3 → 0.1.0-pr.59.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +52 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/db-init.js +52 -0
- package/dist/commands/db-init.js.map +1 -1
- package/package.json +10 -10
package/dist/cli.js
CHANGED
|
@@ -1341,6 +1341,58 @@ function createDbInitCommand() {
|
|
|
1341
1341
|
throw errorMigrationPlanningFailed({ conflicts: plannerResult.conflicts });
|
|
1342
1342
|
}
|
|
1343
1343
|
const migrationPlan = plannerResult.plan;
|
|
1344
|
+
const existingMarker = await familyInstance.readMarker({ driver });
|
|
1345
|
+
if (existingMarker) {
|
|
1346
|
+
const markerMatchesDestination = existingMarker.coreHash === migrationPlan.destination.coreHash && (!migrationPlan.destination.profileHash || existingMarker.profileHash === migrationPlan.destination.profileHash);
|
|
1347
|
+
if (markerMatchesDestination) {
|
|
1348
|
+
const dbInitResult2 = {
|
|
1349
|
+
ok: true,
|
|
1350
|
+
mode: options.plan ? "plan" : "apply",
|
|
1351
|
+
plan: {
|
|
1352
|
+
targetId: migrationPlan.targetId,
|
|
1353
|
+
destination: migrationPlan.destination,
|
|
1354
|
+
operations: []
|
|
1355
|
+
},
|
|
1356
|
+
...options.plan ? {} : {
|
|
1357
|
+
execution: { operationsPlanned: 0, operationsExecuted: 0 },
|
|
1358
|
+
marker: {
|
|
1359
|
+
coreHash: existingMarker.coreHash,
|
|
1360
|
+
profileHash: existingMarker.profileHash
|
|
1361
|
+
}
|
|
1362
|
+
},
|
|
1363
|
+
summary: "Database already at target contract state",
|
|
1364
|
+
timings: { total: Date.now() - startTime }
|
|
1365
|
+
};
|
|
1366
|
+
return dbInitResult2;
|
|
1367
|
+
}
|
|
1368
|
+
const coreHashMismatch = existingMarker.coreHash !== migrationPlan.destination.coreHash;
|
|
1369
|
+
const profileHashMismatch = migrationPlan.destination.profileHash && existingMarker.profileHash !== migrationPlan.destination.profileHash;
|
|
1370
|
+
const mismatchParts = [];
|
|
1371
|
+
if (coreHashMismatch) {
|
|
1372
|
+
mismatchParts.push(
|
|
1373
|
+
`coreHash (marker: ${existingMarker.coreHash}, destination: ${migrationPlan.destination.coreHash})`
|
|
1374
|
+
);
|
|
1375
|
+
}
|
|
1376
|
+
if (profileHashMismatch) {
|
|
1377
|
+
mismatchParts.push(
|
|
1378
|
+
`profileHash (marker: ${existingMarker.profileHash}, destination: ${migrationPlan.destination.profileHash})`
|
|
1379
|
+
);
|
|
1380
|
+
}
|
|
1381
|
+
throw errorRuntime(
|
|
1382
|
+
`Existing contract marker does not match plan destination. Mismatch in ${mismatchParts.join(" and ")}.`,
|
|
1383
|
+
{
|
|
1384
|
+
why: "Database has an existing contract marker that does not match the target contract",
|
|
1385
|
+
fix: "Use `prisma-next db migrate` to migrate from the existing contract, or drop the database and re-run `db init`",
|
|
1386
|
+
meta: {
|
|
1387
|
+
code: "MARKER_ORIGIN_MISMATCH",
|
|
1388
|
+
markerCoreHash: existingMarker.coreHash,
|
|
1389
|
+
destinationCoreHash: migrationPlan.destination.coreHash,
|
|
1390
|
+
...existingMarker.profileHash ? { markerProfileHash: existingMarker.profileHash } : {},
|
|
1391
|
+
...migrationPlan.destination.profileHash ? { destinationProfileHash: migrationPlan.destination.profileHash } : {}
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
);
|
|
1395
|
+
}
|
|
1344
1396
|
if (options.plan) {
|
|
1345
1397
|
const dbInitResult2 = {
|
|
1346
1398
|
ok: true,
|