@prisma/migrate 6.4.1 → 6.5.0-dev.10

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.
Files changed (106) hide show
  1. package/dist/CLI.js +3 -4
  2. package/dist/Migrate.js +6 -7
  3. package/dist/SchemaEngine.js +6 -7
  4. package/dist/bin.js +116 -146
  5. package/dist/{chunk-WOOPRG54.js → chunk-255BRND3.js} +7 -14
  6. package/dist/{chunk-75EIHNAH.js → chunk-2NMFKGXM.js} +5 -6
  7. package/dist/chunk-3WC4XD74.js +98 -0
  8. package/dist/chunk-4EV2RVXY.js +226 -0
  9. package/dist/{chunk-YWWOSXMY.js → chunk-4JQIX6O7.js} +7 -15
  10. package/dist/{chunk-J77IRNPE.js → chunk-5VDXAE53.js} +45 -31
  11. package/dist/{chunk-M5YNQ2NP.js → chunk-6DFJIBJX.js} +5 -12
  12. package/dist/{chunk-SGCF5OHF.js → chunk-7CQBDP4H.js} +6 -13
  13. package/dist/{chunk-7IT2ZO3D.js → chunk-AHJ2N6BJ.js} +3 -9
  14. package/dist/chunk-CTPONE6G.js +65 -0
  15. package/dist/{chunk-DUCG3NRP.js → chunk-D74DU52C.js} +633 -806
  16. package/dist/{chunk-UVNSK22K.js → chunk-DDHPSYC4.js} +122 -130
  17. package/dist/{chunk-CUDKD32S.js → chunk-DIAO4W7O.js} +11 -17
  18. package/dist/{chunk-XJQP3B4W.js → chunk-DJMFXNR4.js} +7 -15
  19. package/dist/{chunk-YD7GG4WS.js → chunk-FRTPDRF2.js} +66 -74
  20. package/dist/chunk-HIFVDK2U.js +96 -0
  21. package/dist/chunk-I4EY55DC.js +195 -0
  22. package/dist/{chunk-WLJHGKMK.js → chunk-IHDN3L3R.js} +7 -8
  23. package/dist/chunk-J5FHVALZ.js +230 -0
  24. package/dist/{chunk-INC2OACE.js → chunk-JFKDSUIE.js} +3 -9
  25. package/dist/{chunk-V7DE6JTG.js → chunk-JZ75RIMZ.js} +3 -9
  26. package/dist/{chunk-AAATUOV6.js → chunk-L6KOIJJ5.js} +53 -59
  27. package/dist/{chunk-GN5BY5N2.js → chunk-LGYRZ6CV.js} +4 -10
  28. package/dist/chunk-LVLRGTYH.js +148 -0
  29. package/dist/{chunk-CQQQ436N.js → chunk-MATFO4ZW.js} +186 -200
  30. package/dist/{chunk-WZT5FFN4.js → chunk-NB4NJGMY.js} +634 -807
  31. package/dist/{chunk-IFCV5MY4.js → chunk-OCQGHQED.js} +5 -11
  32. package/dist/chunk-ORL3LJOT.js +470 -0
  33. package/dist/chunk-PSYS5XVH.js +335 -0
  34. package/dist/{chunk-Q7ACZDDT.js → chunk-QOPTDDIH.js} +5 -12
  35. package/dist/chunk-QTAIWPLH.js +78 -0
  36. package/dist/{chunk-35LAJN5S.js → chunk-RP2N6UXA.js} +23 -29
  37. package/dist/chunk-RQFGRXJI.js +174 -0
  38. package/dist/{chunk-QBK5XTJE.js → chunk-RR6BKMNO.js} +3 -9
  39. package/dist/{chunk-ILJRJJ3S.js → chunk-RTGQXNX6.js} +3 -9
  40. package/dist/chunk-SKRR5WT4.js +76 -0
  41. package/dist/chunk-TM3ETZES.js +153 -0
  42. package/dist/{chunk-KPUNMK5W.js → chunk-TWPTG4XS.js} +5 -12
  43. package/dist/{chunk-6QFE3AWR.js → chunk-UP6FVCDK.js} +6 -13
  44. package/dist/{chunk-YKUZUAXA.js → chunk-V3ZMNXZC.js} +16 -23
  45. package/dist/chunk-WLPX3672.js +365 -0
  46. package/dist/chunk-WNH2ACJS.js +122 -0
  47. package/dist/{chunk-X6XGFLEF.js → chunk-YZVZCC3I.js} +25 -30
  48. package/dist/commands/DbCommand.js +3 -4
  49. package/dist/commands/DbDrop.js +9 -9
  50. package/dist/commands/DbExecute.js +7 -8
  51. package/dist/commands/DbPull.js +18 -19
  52. package/dist/commands/DbPush.js +12 -13
  53. package/dist/commands/DbSeed.js +4 -5
  54. package/dist/commands/MigrateCommand.js +3 -4
  55. package/dist/commands/MigrateDeploy.js +13 -14
  56. package/dist/commands/MigrateDev.js +17 -18
  57. package/dist/commands/MigrateDiff.js +8 -9
  58. package/dist/commands/MigrateReset.js +15 -16
  59. package/dist/commands/MigrateResolve.js +11 -12
  60. package/dist/commands/MigrateStatus.js +11 -12
  61. package/dist/index.js +60 -77
  62. package/dist/migrate/src/commands/MigrateDev.d.ts +1 -1
  63. package/dist/{multipart-parser-73VM3J4A.js → multipart-parser-NDLECNMN.js} +527 -561
  64. package/dist/utils/byline.js +5 -6
  65. package/dist/utils/captureStdout.js +2 -3
  66. package/dist/utils/countModelsAndTypes.js +2 -3
  67. package/dist/utils/ensureDatabaseExists.js +8 -9
  68. package/dist/utils/errors.js +8 -9
  69. package/dist/utils/flagErrors.js +5 -5
  70. package/dist/utils/getDatabaseVersionSafe.js +6 -7
  71. package/dist/utils/getSchemaPathAndPrint.js +4 -5
  72. package/dist/utils/handleEvaluateDataloss.js +3 -4
  73. package/dist/utils/introspectSql.js +6 -6
  74. package/dist/utils/isSchemaEmpty.js +2 -3
  75. package/dist/utils/printDatasource.js +3 -4
  76. package/dist/utils/printDatasources.js +3 -4
  77. package/dist/utils/printFiles.js +5 -6
  78. package/dist/utils/printIntrospectedSchema.js +2 -3
  79. package/dist/utils/printMigrationId.js +4 -5
  80. package/dist/utils/promptForMigrationName.js +2 -3
  81. package/dist/utils/removeSchemaFiles.js +2 -3
  82. package/dist/utils/replaceOrAddDatasource.js +2 -3
  83. package/dist/utils/replaceOrAddDatasource.test.js +7 -8
  84. package/dist/utils/saveSchemaFiles.js +2 -3
  85. package/dist/utils/seed.js +6 -7
  86. package/dist/utils/setupMSSQL.js +13 -13
  87. package/dist/utils/setupMongo.js +3 -3
  88. package/dist/utils/spinner.js +2 -3
  89. package/dist/utils/unixSocket.js +2 -3
  90. package/dist/views/handleViewsIO.js +2 -3
  91. package/package.json +7 -7
  92. package/dist/chunk-26XQQ4AG.js +0 -386
  93. package/dist/chunk-2RSEPJFX.js +0 -165
  94. package/dist/chunk-4B2LXK4R.js +0 -207
  95. package/dist/chunk-4UJBOCZJ.js +0 -130
  96. package/dist/chunk-5HZLCY6X.js +0 -161
  97. package/dist/chunk-6TE2RIPN.js +0 -80
  98. package/dist/chunk-7S3Q4MCN.js +0 -480
  99. package/dist/chunk-AOX7CJAS.js +0 -234
  100. package/dist/chunk-FF3526PX.js +0 -279
  101. package/dist/chunk-FUSFURVP.js +0 -86
  102. package/dist/chunk-GCTCQLOF.js +0 -365
  103. package/dist/chunk-K44VNAFW.js +0 -189
  104. package/dist/chunk-O4BT6W33.js +0 -104
  105. package/dist/chunk-TKAGMA5K.js +0 -72
  106. package/dist/chunk-U374EXYQ.js +0 -106
@@ -0,0 +1,335 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var chunk_PSYS5XVH_exports = {};
30
+ __export(chunk_PSYS5XVH_exports, {
31
+ MigrateDev: () => MigrateDev
32
+ });
33
+ module.exports = __toCommonJS(chunk_PSYS5XVH_exports);
34
+ var import_chunk_OCQGHQED = require("./chunk-OCQGHQED.js");
35
+ var import_chunk_7CQBDP4H = require("./chunk-7CQBDP4H.js");
36
+ var import_chunk_V3ZMNXZC = require("./chunk-V3ZMNXZC.js");
37
+ var import_chunk_255BRND3 = require("./chunk-255BRND3.js");
38
+ var import_chunk_UP6FVCDK = require("./chunk-UP6FVCDK.js");
39
+ var import_chunk_DDHPSYC4 = require("./chunk-DDHPSYC4.js");
40
+ var import_chunk_3WC4XD74 = require("./chunk-3WC4XD74.js");
41
+ var import_chunk_6DFJIBJX = require("./chunk-6DFJIBJX.js");
42
+ var import_chunk_QOPTDDIH = require("./chunk-QOPTDDIH.js");
43
+ var import_chunk_DJMFXNR4 = require("./chunk-DJMFXNR4.js");
44
+ var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
45
+ var import_debug = __toESM(require("@prisma/debug"));
46
+ var import_internals = require("@prisma/internals");
47
+ var import_prompts = __toESM(require("prompts"));
48
+ var debug = (0, import_debug.default)("prisma:migrate:dev");
49
+ var _MigrateDev = class _MigrateDev2 {
50
+ static new() {
51
+ return new _MigrateDev2();
52
+ }
53
+ async parse(argv, config) {
54
+ const args = (0, import_internals.arg)(argv, {
55
+ "--help": Boolean,
56
+ "-h": "--help",
57
+ "--name": String,
58
+ "-n": "--name",
59
+ // '--force': Boolean,
60
+ // '-f': '--force',
61
+ "--create-only": Boolean,
62
+ "--schema": String,
63
+ "--config": String,
64
+ "--skip-generate": Boolean,
65
+ "--skip-seed": Boolean,
66
+ "--telemetry-information": String,
67
+ "--allow-reset": Boolean
68
+ });
69
+ if ((0, import_internals.isError)(args)) {
70
+ return this.help(args.message);
71
+ }
72
+ await (0, import_internals.checkUnsupportedDataProxy)("migrate dev", args, config.schema, true);
73
+ if (args["--help"]) {
74
+ return this.help();
75
+ }
76
+ await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true, config });
77
+ const { schemaPath, schemas } = await (0, import_chunk_6DFJIBJX.getSchemaPathAndPrint)(args["--schema"], config.schema);
78
+ const datasourceInfo = await (0, import_chunk_DJMFXNR4.getDatasourceInfo)({ schemaPath });
79
+ (0, import_chunk_QOPTDDIH.printDatasource)({ datasourceInfo });
80
+ process.stdout.write("\n");
81
+ (0, import_internals.validate)({
82
+ schemas
83
+ });
84
+ await (0, import_internals.getConfig)({
85
+ datamodel: schemas,
86
+ ignoreEnvVarErrors: false
87
+ });
88
+ const wasDbCreated = await (0, import_chunk_DJMFXNR4.ensureDatabaseExists)("create", schemaPath);
89
+ if (wasDbCreated) {
90
+ process.stdout.write(wasDbCreated + "\n\n");
91
+ }
92
+ const migrate = new import_chunk_DDHPSYC4.Migrate(schemaPath);
93
+ let devDiagnostic;
94
+ try {
95
+ devDiagnostic = await migrate.devDiagnostic();
96
+ debug({ devDiagnostic: JSON.stringify(devDiagnostic, null, 2) });
97
+ } catch (e) {
98
+ migrate.stop();
99
+ throw e;
100
+ }
101
+ const migrationIdsApplied = [];
102
+ if (devDiagnostic.action.tag === "reset") {
103
+ this.logResetReason({
104
+ datasourceInfo,
105
+ reason: devDiagnostic.action.reason
106
+ });
107
+ if (!args["--allow-reset"]) {
108
+ process.stdout.write(
109
+ `
110
+ You may use --allow-reset to drop the database. ${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)("All data will be lost."))}
111
+ `
112
+ );
113
+ migrate.stop();
114
+ process.exit(130);
115
+ }
116
+ process.stdout.write("\nReceived --allow-reset, dropping the database. All data is lost.\n\n");
117
+ try {
118
+ await migrate.reset();
119
+ } catch (e) {
120
+ migrate.stop();
121
+ throw e;
122
+ }
123
+ }
124
+ try {
125
+ const { appliedMigrationNames } = await migrate.applyMigrations();
126
+ migrationIdsApplied.push(...appliedMigrationNames);
127
+ if (appliedMigrationNames.length > 0) {
128
+ process.stdout.write(
129
+ `
130
+ The following migration(s) have been applied:
131
+
132
+ ${(0, import_chunk_255BRND3.printFilesFromMigrationIds)(
133
+ "migrations",
134
+ appliedMigrationNames,
135
+ {
136
+ "migration.sql": ""
137
+ }
138
+ )}
139
+ `
140
+ );
141
+ }
142
+ } catch (e) {
143
+ migrate.stop();
144
+ throw e;
145
+ }
146
+ let evaluateDataLossResult;
147
+ try {
148
+ evaluateDataLossResult = await migrate.evaluateDataLoss();
149
+ debug({ evaluateDataLossResult });
150
+ } catch (e) {
151
+ migrate.stop();
152
+ throw e;
153
+ }
154
+ const unexecutableStepsError = (0, import_chunk_7CQBDP4H.handleUnexecutableSteps)(
155
+ evaluateDataLossResult.unexecutableSteps,
156
+ args["--create-only"]
157
+ );
158
+ if (unexecutableStepsError) {
159
+ migrate.stop();
160
+ throw new Error(unexecutableStepsError);
161
+ }
162
+ if (evaluateDataLossResult.warnings && evaluateDataLossResult.warnings.length > 0) {
163
+ if (!(0, import_internals.canPrompt)()) {
164
+ migrate.stop();
165
+ throw new import_chunk_3WC4XD74.MigrateDevEnvNonInteractiveError();
166
+ }
167
+ process.stdout.write((0, import_chunk_SKRR5WT4.bold)(`
168
+ \u26A0\uFE0F Warnings for the current datasource:
169
+
170
+ `));
171
+ for (const warning of evaluateDataLossResult.warnings) {
172
+ process.stdout.write(` \u2022 ${warning.message}
173
+ `);
174
+ }
175
+ process.stdout.write("\n");
176
+ if (!args["--force"]) {
177
+ const message = args["--create-only"] ? "Are you sure you want to create this migration?" : "Are you sure you want to create and apply this migration?";
178
+ const confirmation = await (0, import_prompts.default)({
179
+ type: "confirm",
180
+ name: "value",
181
+ message
182
+ });
183
+ if (!confirmation.value) {
184
+ process.stdout.write("Migration cancelled.\n");
185
+ migrate.stop();
186
+ process.exit(130);
187
+ }
188
+ }
189
+ }
190
+ let migrationName = void 0;
191
+ if (evaluateDataLossResult.migrationSteps > 0 || args["--create-only"]) {
192
+ const getMigrationNameResult = await (0, import_chunk_OCQGHQED.getMigrationName)(args["--name"]);
193
+ if (getMigrationNameResult.userCancelled) {
194
+ process.stdout.write(getMigrationNameResult.userCancelled + "\n");
195
+ migrate.stop();
196
+ process.exit(130);
197
+ } else {
198
+ migrationName = getMigrationNameResult.name;
199
+ }
200
+ }
201
+ let migrationIds;
202
+ try {
203
+ const createMigrationResult = await migrate.createMigration({
204
+ migrationsDirectoryPath: migrate.migrationsDirectoryPath,
205
+ migrationName: migrationName || "",
206
+ draft: args["--create-only"] ? true : false,
207
+ schema: (0, import_internals.toSchemasContainer)((await migrate.getPrismaSchema()).schemas)
208
+ });
209
+ debug({ createMigrationResult });
210
+ if (args["--create-only"]) {
211
+ migrate.stop();
212
+ return `Prisma Migrate created the following migration without applying it ${(0, import_chunk_UP6FVCDK.printMigrationId)(
213
+ createMigrationResult.generatedMigrationName
214
+ )}
215
+
216
+ You can now edit it and apply it by running ${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExecutor)("prisma migrate dev"))}.`;
217
+ }
218
+ const { appliedMigrationNames } = await migrate.applyMigrations();
219
+ migrationIds = appliedMigrationNames;
220
+ } finally {
221
+ migrate.stop();
222
+ }
223
+ migrationIdsApplied.length > 0 && process.stdout.write("\n");
224
+ if (migrationIds.length === 0) {
225
+ if (migrationIdsApplied.length > 0) {
226
+ process.stdout.write(`${(0, import_chunk_SKRR5WT4.green)("Your database is now in sync with your schema.")}
227
+ `);
228
+ } else {
229
+ process.stdout.write(`Already in sync, no schema change or pending migration was found.
230
+ `);
231
+ }
232
+ } else {
233
+ process.stdout.write(
234
+ `
235
+ The following migration(s) have been created and applied from new schema changes:
236
+
237
+ ${(0, import_chunk_255BRND3.printFilesFromMigrationIds)(
238
+ "migrations",
239
+ migrationIds,
240
+ {
241
+ "migration.sql": ""
242
+ }
243
+ )}
244
+
245
+ ${(0, import_chunk_SKRR5WT4.green)("Your database is now in sync with your schema.")}
246
+ `
247
+ );
248
+ }
249
+ if (!process.env.PRISMA_MIGRATE_SKIP_GENERATE && !args["--skip-generate"]) {
250
+ await migrate.tryToRunGenerate(datasourceInfo);
251
+ process.stdout.write("\n");
252
+ }
253
+ if ((wasDbCreated || devDiagnostic.action.tag === "reset") && !process.env.PRISMA_MIGRATE_SKIP_SEED && !args["--skip-seed"]) {
254
+ try {
255
+ const seedCommandFromPkgJson = await (0, import_chunk_V3ZMNXZC.getSeedCommandFromPackageJson)(process.cwd());
256
+ if (seedCommandFromPkgJson) {
257
+ process.stdout.write("\n");
258
+ const successfulSeeding = await (0, import_chunk_V3ZMNXZC.executeSeedCommand)({ commandFromConfig: seedCommandFromPkgJson });
259
+ if (successfulSeeding) {
260
+ process.stdout.write(`
261
+ ${process.platform === "win32" ? "" : "\u{1F331} "}The seed command has been executed.
262
+ `);
263
+ } else {
264
+ process.exit(1);
265
+ }
266
+ } else {
267
+ const { schemaPath: schemaPath2 } = await (0, import_internals.getSchemaWithPath)(args["--schema"], config.schema);
268
+ await (0, import_chunk_V3ZMNXZC.verifySeedConfigAndReturnMessage)(schemaPath2);
269
+ }
270
+ } catch (e) {
271
+ console.error(e);
272
+ }
273
+ }
274
+ return "";
275
+ }
276
+ logResetReason({ datasourceInfo, reason }) {
277
+ process.stdout.write(reason + "\n");
278
+ let message;
279
+ if (["PostgreSQL", "SQL Server"].includes(datasourceInfo.prettyProvider)) {
280
+ if (datasourceInfo.schemas?.length) {
281
+ message = `We need to reset the following schemas: "${datasourceInfo.schemas.join(", ")}"`;
282
+ } else if (datasourceInfo.schema) {
283
+ message = `We need to reset the "${datasourceInfo.schema}" schema`;
284
+ } else {
285
+ message = `We need to reset the database schema`;
286
+ }
287
+ } else {
288
+ message = `We need to reset the ${datasourceInfo.prettyProvider} database "${datasourceInfo.dbName}"`;
289
+ }
290
+ if (datasourceInfo.dbLocation) {
291
+ message += ` at "${datasourceInfo.dbLocation}"`;
292
+ }
293
+ process.stdout.write(`${message}
294
+ `);
295
+ }
296
+ help(error) {
297
+ if (error) {
298
+ return new import_internals.HelpError(`
299
+ ${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
300
+ ${_MigrateDev2.help}`);
301
+ }
302
+ return _MigrateDev2.help;
303
+ }
304
+ };
305
+ _MigrateDev.help = (0, import_internals.format)(`
306
+ ${process.platform === "win32" ? "" : "\u{1F3CB}\uFE0F "}Create a migration from changes in Prisma schema, apply it to the database, trigger generators (e.g. Prisma Client)
307
+
308
+ ${(0, import_chunk_SKRR5WT4.bold)("Usage")}
309
+
310
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate dev [options]
311
+
312
+ ${(0, import_chunk_SKRR5WT4.bold)("Options")}
313
+
314
+ -h, --help Display this help message
315
+ --config Custom path to your Prisma config file
316
+ --schema Custom path to your Prisma schema
317
+ -n, --name Name the migration
318
+ --create-only Create a new migration but do not apply it
319
+ The migration will be empty if there are no changes in Prisma schema
320
+ --skip-generate Skip triggering generators (e.g. Prisma Client)
321
+ --skip-seed Skip triggering seed
322
+ --allow-reset Allow resetting the database on incompatible schema change (accept data loss)
323
+
324
+ ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
325
+
326
+ Create a migration from changes in Prisma schema, apply it to the database, trigger generators (e.g. Prisma Client)
327
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate dev
328
+
329
+ Specify a schema
330
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate dev --schema=./schema.prisma
331
+
332
+ Create a migration without applying it
333
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate dev --create-only
334
+ `);
335
+ var MigrateDev = _MigrateDev;
@@ -16,14 +16,12 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_Q7ACZDDT_exports = {};
20
- __export(chunk_Q7ACZDDT_exports, {
21
- init_printDatasource: () => init_printDatasource,
19
+ var chunk_QOPTDDIH_exports = {};
20
+ __export(chunk_QOPTDDIH_exports, {
22
21
  printDatasource: () => printDatasource
23
22
  });
24
- module.exports = __toCommonJS(chunk_Q7ACZDDT_exports);
25
- var import_chunk_6TE2RIPN = require("./chunk-6TE2RIPN.js");
26
- var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
23
+ module.exports = __toCommonJS(chunk_QOPTDDIH_exports);
24
+ var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
27
25
  function printDatasource({ datasourceInfo }) {
28
26
  if (!datasourceInfo.name || !datasourceInfo.prettyProvider) return;
29
27
  let message = `Datasource "${datasourceInfo.name}": ${datasourceInfo.prettyProvider} database`;
@@ -38,10 +36,5 @@ function printDatasource({ datasourceInfo }) {
38
36
  if (datasourceInfo.dbLocation) {
39
37
  message += ` at "${datasourceInfo.dbLocation}"`;
40
38
  }
41
- process.stdout.write((0, import_chunk_6TE2RIPN.dim)(message) + "\n");
39
+ process.stdout.write((0, import_chunk_SKRR5WT4.dim)(message) + "\n");
42
40
  }
43
- var init_printDatasource = (0, import_chunk_WWAWV7DQ.__esm)({
44
- "src/utils/printDatasource.ts"() {
45
- (0, import_chunk_6TE2RIPN.init_colors)();
46
- }
47
- });
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var chunk_QTAIWPLH_exports = {};
20
+ __export(chunk_QTAIWPLH_exports, {
21
+ CLI: () => CLI
22
+ });
23
+ module.exports = __toCommonJS(chunk_QTAIWPLH_exports);
24
+ var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
25
+ var import_internals = require("@prisma/internals");
26
+ var _CLI = class _CLI2 {
27
+ constructor(cmds) {
28
+ this.cmds = cmds;
29
+ }
30
+ static new(cmds) {
31
+ return new _CLI2(cmds);
32
+ }
33
+ async parse(argv, config) {
34
+ const args = (0, import_internals.arg)(argv, {
35
+ "--help": Boolean,
36
+ "-h": "--help",
37
+ "--config": String,
38
+ "--json": Boolean,
39
+ // for -v
40
+ "--experimental": Boolean,
41
+ "--preview-feature": Boolean,
42
+ "--early-access": Boolean,
43
+ "--telemetry-information": String
44
+ });
45
+ if ((0, import_internals.isError)(args)) {
46
+ return this.help(args.message);
47
+ }
48
+ if (args._.length === 0 || args["--help"]) {
49
+ return this.help();
50
+ }
51
+ const cmdName = args._[0];
52
+ const cmd = this.cmds[cmdName];
53
+ if (cmd) {
54
+ let argsForCmd;
55
+ if (args["--experimental"]) {
56
+ argsForCmd = [...args._.slice(1), `--experimental=${args["--experimental"]}`];
57
+ } else if (args["--preview-feature"]) {
58
+ argsForCmd = [...args._.slice(1), `--preview-feature=${args["--preview-feature"]}`];
59
+ } else if (args["--early-access"]) {
60
+ argsForCmd = [...args._.slice(1), `--early-access=${args["--early-access"]}`];
61
+ } else {
62
+ argsForCmd = args._.slice(1);
63
+ }
64
+ return cmd.parse(argsForCmd, config);
65
+ }
66
+ return (0, import_internals.unknownCommand)(this.help(), args._[0]);
67
+ }
68
+ help(error) {
69
+ if (error) {
70
+ return new import_internals.HelpError(`
71
+ ${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
72
+ ${_CLI2.help}`);
73
+ }
74
+ return _CLI2.help;
75
+ }
76
+ };
77
+ _CLI.help = (0, import_internals.format)(`This is the internal CLI for @prisma/migrate`);
78
+ var CLI = _CLI;
@@ -16,46 +16,40 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_35LAJN5S_exports = {};
20
- __export(chunk_35LAJN5S_exports, {
21
- init_printDatasources: () => init_printDatasources,
19
+ var chunk_RP2N6UXA_exports = {};
20
+ __export(chunk_RP2N6UXA_exports, {
22
21
  printDatamodelObject: () => printDatamodelObject,
23
22
  printDatasources: () => printDatasources
24
23
  });
25
- module.exports = __toCommonJS(chunk_35LAJN5S_exports);
24
+ module.exports = __toCommonJS(chunk_RP2N6UXA_exports);
26
25
  var import_chunk_LKTTJWFT = require("./chunk-LKTTJWFT.js");
27
26
  var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
27
+ var import_indent_string = (0, import_chunk_WWAWV7DQ.__toESM)((0, import_chunk_LKTTJWFT.require_indent_string)());
28
28
  function printDatasources(internalDatasources) {
29
29
  return internalDatasources.map((d) => String(new InternalDataSourceClass(d))).join("\n\n");
30
30
  }
31
+ var tab = 2;
32
+ var InternalDataSourceClass = class {
33
+ constructor(dataSource) {
34
+ this.dataSource = dataSource;
35
+ }
36
+ toString() {
37
+ const { dataSource } = this;
38
+ const obj = {
39
+ provider: dataSource.provider,
40
+ url: dataSource.url
41
+ };
42
+ if (dataSource.config && typeof dataSource.config === "object") {
43
+ Object.assign(obj, dataSource.config);
44
+ }
45
+ return `datasource ${dataSource.name} {
46
+ ${(0, import_indent_string.default)(printDatamodelObject(obj), tab)}
47
+ }`;
48
+ }
49
+ };
31
50
  function printDatamodelObject(obj) {
32
51
  const maxLength = Object.keys(obj).reduce((max, curr) => Math.max(max, curr.length), 0);
33
52
  return Object.entries(obj).map(
34
53
  ([key, value]) => `${key.padEnd(maxLength)} = ${typeof value === "object" && value && value.value ? JSON.stringify(value.value) : JSON.stringify(value)}`
35
54
  ).join("\n");
36
55
  }
37
- var import_indent_string, tab, InternalDataSourceClass;
38
- var init_printDatasources = (0, import_chunk_WWAWV7DQ.__esm)({
39
- "src/utils/printDatasources.ts"() {
40
- import_indent_string = (0, import_chunk_WWAWV7DQ.__toESM)((0, import_chunk_LKTTJWFT.require_indent_string)());
41
- tab = 2;
42
- InternalDataSourceClass = class {
43
- constructor(dataSource) {
44
- this.dataSource = dataSource;
45
- }
46
- toString() {
47
- const { dataSource } = this;
48
- const obj = {
49
- provider: dataSource.provider,
50
- url: dataSource.url
51
- };
52
- if (dataSource.config && typeof dataSource.config === "object") {
53
- Object.assign(obj, dataSource.config);
54
- }
55
- return `datasource ${dataSource.name} {
56
- ${(0, import_indent_string.default)(printDatamodelObject(obj), tab)}
57
- }`;
58
- }
59
- };
60
- }
61
- });
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var chunk_RQFGRXJI_exports = {};
30
+ __export(chunk_RQFGRXJI_exports, {
31
+ MigrateReset: () => MigrateReset
32
+ });
33
+ module.exports = __toCommonJS(chunk_RQFGRXJI_exports);
34
+ var import_chunk_V3ZMNXZC = require("./chunk-V3ZMNXZC.js");
35
+ var import_chunk_255BRND3 = require("./chunk-255BRND3.js");
36
+ var import_chunk_DDHPSYC4 = require("./chunk-DDHPSYC4.js");
37
+ var import_chunk_3WC4XD74 = require("./chunk-3WC4XD74.js");
38
+ var import_chunk_6DFJIBJX = require("./chunk-6DFJIBJX.js");
39
+ var import_chunk_QOPTDDIH = require("./chunk-QOPTDDIH.js");
40
+ var import_chunk_DJMFXNR4 = require("./chunk-DJMFXNR4.js");
41
+ var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
42
+ var import_internals = require("@prisma/internals");
43
+ var import_prompts = __toESM(require("prompts"));
44
+ var _MigrateReset = class _MigrateReset2 {
45
+ static new() {
46
+ return new _MigrateReset2();
47
+ }
48
+ async parse(argv, config) {
49
+ const args = (0, import_internals.arg)(argv, {
50
+ "--help": Boolean,
51
+ "-h": "--help",
52
+ "--force": Boolean,
53
+ "-f": "--force",
54
+ "--skip-generate": Boolean,
55
+ "--skip-seed": Boolean,
56
+ "--schema": String,
57
+ "--config": String,
58
+ "--telemetry-information": String
59
+ });
60
+ if ((0, import_internals.isError)(args)) {
61
+ return this.help(args.message);
62
+ }
63
+ await (0, import_internals.checkUnsupportedDataProxy)("migrate reset", args, config.schema, true);
64
+ if (args["--help"]) {
65
+ return this.help();
66
+ }
67
+ await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true, config });
68
+ const { schemaPath } = await (0, import_chunk_6DFJIBJX.getSchemaPathAndPrint)(args["--schema"], config.schema);
69
+ const datasourceInfo = await (0, import_chunk_DJMFXNR4.getDatasourceInfo)({ schemaPath });
70
+ (0, import_chunk_QOPTDDIH.printDatasource)({ datasourceInfo });
71
+ const wasDbCreated = await (0, import_chunk_DJMFXNR4.ensureDatabaseExists)("create", schemaPath);
72
+ if (wasDbCreated) {
73
+ process.stdout.write("\n" + wasDbCreated + "\n");
74
+ }
75
+ process.stdout.write("\n");
76
+ if (!args["--force"]) {
77
+ if (!(0, import_internals.canPrompt)()) {
78
+ throw new import_chunk_3WC4XD74.MigrateResetEnvNonInteractiveError();
79
+ }
80
+ const confirmation = await (0, import_prompts.default)({
81
+ type: "confirm",
82
+ name: "value",
83
+ message: `Are you sure you want to reset your database? ${(0, import_chunk_SKRR5WT4.red)("All data will be lost")}.`
84
+ });
85
+ process.stdout.write("\n");
86
+ if (!confirmation.value) {
87
+ process.stdout.write("Reset cancelled.\n");
88
+ process.exit(130);
89
+ }
90
+ }
91
+ const migrate = new import_chunk_DDHPSYC4.Migrate(schemaPath);
92
+ let migrationIds;
93
+ try {
94
+ await migrate.reset();
95
+ const { appliedMigrationNames } = await migrate.applyMigrations();
96
+ migrationIds = appliedMigrationNames;
97
+ } finally {
98
+ migrate.stop();
99
+ }
100
+ if (migrationIds.length === 0) {
101
+ process.stdout.write(`${(0, import_chunk_SKRR5WT4.green)("Database reset successful\n")}
102
+ `);
103
+ } else {
104
+ process.stdout.write("\n");
105
+ process.stdout.write(
106
+ `${(0, import_chunk_SKRR5WT4.green)("Database reset successful")}
107
+
108
+ The following migration(s) have been applied:
109
+
110
+ ${(0, import_chunk_255BRND3.printFilesFromMigrationIds)("migrations", migrationIds, {
111
+ "migration.sql": ""
112
+ })}
113
+ `
114
+ );
115
+ }
116
+ if (!process.env.PRISMA_MIGRATE_SKIP_GENERATE && !args["--skip-generate"]) {
117
+ await migrate.tryToRunGenerate(datasourceInfo);
118
+ }
119
+ if (!process.env.PRISMA_MIGRATE_SKIP_SEED && !args["--skip-seed"]) {
120
+ const seedCommandFromPkgJson = await (0, import_chunk_V3ZMNXZC.getSeedCommandFromPackageJson)(process.cwd());
121
+ if (seedCommandFromPkgJson) {
122
+ process.stdout.write("\n");
123
+ const successfulSeeding = await (0, import_chunk_V3ZMNXZC.executeSeedCommand)({ commandFromConfig: seedCommandFromPkgJson });
124
+ if (successfulSeeding) {
125
+ process.stdout.write(`
126
+ ${process.platform === "win32" ? "" : "\u{1F331} "}The seed command has been executed.
127
+ `);
128
+ } else {
129
+ process.exit(1);
130
+ }
131
+ } else {
132
+ const { schemaPath: schemaPath2 } = await (0, import_internals.getSchemaWithPath)(args["--schema"], config.schema);
133
+ await (0, import_chunk_V3ZMNXZC.verifySeedConfigAndReturnMessage)(schemaPath2);
134
+ }
135
+ }
136
+ return ``;
137
+ }
138
+ help(error) {
139
+ if (error) {
140
+ return new import_internals.HelpError(`
141
+ ${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
142
+ ${_MigrateReset2.help}`);
143
+ }
144
+ return _MigrateReset2.help;
145
+ }
146
+ };
147
+ _MigrateReset.help = (0, import_internals.format)(`
148
+ Reset your database and apply all migrations, all data will be lost
149
+
150
+ ${(0, import_chunk_SKRR5WT4.bold)("Usage")}
151
+
152
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate reset [options]
153
+
154
+ ${(0, import_chunk_SKRR5WT4.bold)("Options")}
155
+
156
+ -h, --help Display this help message
157
+ --config Custom path to your Prisma config file
158
+ --schema Custom path to your Prisma schema
159
+ --skip-generate Skip triggering generators (e.g. Prisma Client)
160
+ --skip-seed Skip triggering seed
161
+ -f, --force Skip the confirmation prompt
162
+
163
+ ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
164
+
165
+ Reset your database and apply all migrations, all data will be lost
166
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate reset
167
+
168
+ Specify a schema
169
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate reset --schema=./schema.prisma
170
+
171
+ Use --force to skip the confirmation prompt
172
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate reset --force
173
+ `);
174
+ var MigrateReset = _MigrateReset;