@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,365 @@
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_WLPX3672_exports = {};
30
+ __export(chunk_WLPX3672_exports, {
31
+ DbPull: () => DbPull
32
+ });
33
+ module.exports = __toCommonJS(chunk_WLPX3672_exports);
34
+ var import_chunk_DIAO4W7O = require("./chunk-DIAO4W7O.js");
35
+ var import_chunk_RTGQXNX6 = require("./chunk-RTGQXNX6.js");
36
+ var import_chunk_RP2N6UXA = require("./chunk-RP2N6UXA.js");
37
+ var import_chunk_AHJ2N6BJ = require("./chunk-AHJ2N6BJ.js");
38
+ var import_chunk_JZ75RIMZ = require("./chunk-JZ75RIMZ.js");
39
+ var import_chunk_RR6BKMNO = require("./chunk-RR6BKMNO.js");
40
+ var import_chunk_JFKDSUIE = require("./chunk-JFKDSUIE.js");
41
+ var import_chunk_LGYRZ6CV = require("./chunk-LGYRZ6CV.js");
42
+ var import_chunk_ORL3LJOT = require("./chunk-ORL3LJOT.js");
43
+ var import_chunk_MATFO4ZW = require("./chunk-MATFO4ZW.js");
44
+ var import_chunk_3WC4XD74 = require("./chunk-3WC4XD74.js");
45
+ var import_chunk_QOPTDDIH = require("./chunk-QOPTDDIH.js");
46
+ var import_chunk_DJMFXNR4 = require("./chunk-DJMFXNR4.js");
47
+ var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
48
+ var import_debug = __toESM(require("@prisma/debug"));
49
+ var import_internals = require("@prisma/internals");
50
+ var import_path = __toESM(require("path"));
51
+ var debug = (0, import_debug.default)("prisma:db:pull");
52
+ var _DbPull = class _DbPull2 {
53
+ static new() {
54
+ return new _DbPull2();
55
+ }
56
+ urlToDatasource(url, defaultProvider) {
57
+ const provider = defaultProvider || (0, import_internals.protocolToConnectorType)(`${url.split(":")[0]}:`);
58
+ return (0, import_chunk_RP2N6UXA.printDatasources)([
59
+ {
60
+ config: {},
61
+ provider,
62
+ name: "db",
63
+ url
64
+ }
65
+ ]);
66
+ }
67
+ async parse(argv, config) {
68
+ const args = (0, import_internals.arg)(argv, {
69
+ "--help": Boolean,
70
+ "-h": "--help",
71
+ "--url": String,
72
+ "--print": Boolean,
73
+ "--schema": String,
74
+ "--config": String,
75
+ "--schemas": String,
76
+ "--force": Boolean,
77
+ "--composite-type-depth": Number,
78
+ // optional, only on mongodb
79
+ "--local-d1": Boolean
80
+ // optional, only on cloudflare D1
81
+ });
82
+ const spinnerFactory = (0, import_chunk_DIAO4W7O.createSpinner)(!args["--print"]);
83
+ if (args instanceof Error) {
84
+ return this.help(args.message);
85
+ }
86
+ await (0, import_internals.checkUnsupportedDataProxy)("db pull", args, config.schema, !args["--url"]);
87
+ if (args["--help"]) {
88
+ return this.help();
89
+ }
90
+ const url = args["--url"];
91
+ const schemaPathResult = await (0, import_internals.getSchemaWithPathOptional)(args["--schema"], config.schema);
92
+ let schemaPath = schemaPathResult?.schemaPath ?? null;
93
+ const rootDir = schemaPathResult?.schemaRootDir ?? process.cwd();
94
+ debug("schemaPathResult", schemaPathResult);
95
+ if (schemaPath && !args["--print"]) {
96
+ process.stdout.write((0, import_chunk_SKRR5WT4.dim)(`Prisma schema loaded from ${import_path.default.relative(process.cwd(), schemaPath)}`) + "\n");
97
+ await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true, config });
98
+ (0, import_chunk_QOPTDDIH.printDatasource)({ datasourceInfo: await (0, import_chunk_DJMFXNR4.getDatasourceInfo)({ schemaPath }) });
99
+ } else {
100
+ await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: false, config });
101
+ }
102
+ const fromD1 = Boolean(args["--local-d1"]);
103
+ if (!url && !schemaPath && !fromD1) {
104
+ throw new import_chunk_3WC4XD74.NoSchemaFoundError();
105
+ }
106
+ const { firstDatasource, schema, validationWarning } = await (0, import_chunk_MATFO4ZW.z)({ url, schemaPath, fromD1 }).when(
107
+ (input) => input.schemaPath !== null,
108
+ async (input) => {
109
+ const rawSchema = await (0, import_internals.getSchema)(input.schemaPath, config.schema);
110
+ const engineConfig = await (0, import_internals.getConfig)({
111
+ datamodel: rawSchema,
112
+ ignoreEnvVarErrors: true
113
+ });
114
+ const previewFeatures = engineConfig.generators.find(({ name }) => name === "client")?.previewFeatures;
115
+ const firstDatasource2 = engineConfig.datasources[0] ? engineConfig.datasources[0] : void 0;
116
+ if (input.url) {
117
+ let providerFromSchema = firstDatasource2?.provider;
118
+ if (providerFromSchema === "postgres") {
119
+ providerFromSchema = "postgresql";
120
+ }
121
+ const providerFromUrl = (0, import_internals.protocolToConnectorType)(`${input.url.split(":")[0]}:`);
122
+ const schema2 = (0, import_chunk_RR6BKMNO.replaceOrAddDatasource)(this.urlToDatasource(input.url, providerFromSchema), rawSchema);
123
+ if (providerFromSchema && providerFromUrl && providerFromSchema !== providerFromUrl && Boolean(providerFromSchema === "cockroachdb" && providerFromUrl === "postgresql") === false) {
124
+ throw new Error(
125
+ `The database provider found in --url (${providerFromUrl}) is different from the provider found in the Prisma schema (${providerFromSchema}).`
126
+ );
127
+ }
128
+ return { firstDatasource: firstDatasource2, schema: schema2, validationWarning: void 0 };
129
+ } else if (input.fromD1) {
130
+ const d1Database = await (0, import_internals.locateLocalCloudflareD1)({ arg: "--from-local-d1" });
131
+ const pathToSQLiteFile = import_path.default.relative(import_path.default.dirname(input.schemaPath), d1Database);
132
+ const schema2 = [
133
+ ["schema.prisma", this.urlToDatasource(`file:${pathToSQLiteFile}`, "sqlite")]
134
+ ];
135
+ const config2 = await (0, import_internals.getConfig)({
136
+ datamodel: schema2,
137
+ ignoreEnvVarErrors: true
138
+ });
139
+ const result = { firstDatasource: config2.datasources[0], schema: schema2, validationWarning: void 0 };
140
+ const hasDriverAdaptersPreviewFeature = (previewFeatures || []).includes("driverAdapters");
141
+ const validationWarning2 = `Without the ${(0, import_chunk_SKRR5WT4.bold)(
142
+ "driverAdapters"
143
+ )} preview feature, the schema introspected via the ${(0, import_chunk_SKRR5WT4.bold)("--local-d1")} flag will not work with ${(0, import_chunk_SKRR5WT4.bold)(
144
+ "@prisma/client"
145
+ )}.`;
146
+ if (hasDriverAdaptersPreviewFeature) {
147
+ return result;
148
+ } else {
149
+ return { ...result, validationWarning: validationWarning2 };
150
+ }
151
+ } else {
152
+ await (0, import_internals.getConfig)({
153
+ datamodel: rawSchema,
154
+ ignoreEnvVarErrors: false
155
+ });
156
+ }
157
+ return { firstDatasource: firstDatasource2, schema: rawSchema, validationWarning: void 0 };
158
+ }
159
+ ).when(
160
+ (input) => input.fromD1 === true,
161
+ async (_) => {
162
+ const d1Database = await (0, import_internals.locateLocalCloudflareD1)({ arg: "--from-local-d1" });
163
+ const pathToSQLiteFile = import_path.default.relative(process.cwd(), d1Database);
164
+ const schemaContent = `generator client {
165
+ provider = "prisma-client-js"
166
+ previewFeatures = ["driverAdapters"]
167
+ }
168
+ ${this.urlToDatasource(`file:${pathToSQLiteFile}`, "sqlite")}`;
169
+ const schema2 = [["schema.prisma", schemaContent]];
170
+ const config2 = await (0, import_internals.getConfig)({
171
+ datamodel: schema2,
172
+ ignoreEnvVarErrors: true
173
+ });
174
+ return { firstDatasource: config2.datasources[0], schema: schema2, validationWarning: void 0 };
175
+ }
176
+ ).when(
177
+ (input) => input.url !== void 0,
178
+ async (input) => {
179
+ (0, import_internals.protocolToConnectorType)(`${input.url.split(":")[0]}:`);
180
+ const schema2 = [["schema.prisma", this.urlToDatasource(input.url)]];
181
+ const config2 = await (0, import_internals.getConfig)({
182
+ datamodel: schema2,
183
+ ignoreEnvVarErrors: true
184
+ });
185
+ return { firstDatasource: config2.datasources[0], schema: schema2, validationWarning: void 0 };
186
+ }
187
+ ).run();
188
+ if (schemaPath) {
189
+ const schemas = await (0, import_internals.getSchema)(args["--schema"], config.schema);
190
+ const modelRegex = /\s*model\s*(\w+)\s*{/;
191
+ const isReintrospection = schemas.some(([_, schema2]) => !!modelRegex.exec(schema2));
192
+ if (isReintrospection && !args["--force"] && firstDatasource?.provider === "mongodb") {
193
+ throw new Error(`Iterating on one schema using re-introspection with db pull is currently not supported with MongoDB provider.
194
+ You can explicitly ignore and override your current local schema file with ${(0, import_chunk_SKRR5WT4.green)(
195
+ (0, import_internals.getCommandWithExecutor)("prisma db pull --force")
196
+ )}
197
+ Some information will be lost (relations, comments, mapped fields, @ignore...), follow ${(0, import_internals.link)(
198
+ "https://github.com/prisma/prisma/issues/9585"
199
+ )} for more info.`);
200
+ }
201
+ }
202
+ const engine = new import_chunk_ORL3LJOT.SchemaEngine({
203
+ schemaPath: schemaPath ?? void 0
204
+ });
205
+ const basedOn = !args["--url"] && schemaPath ? ` based on datasource defined in ${(0, import_chunk_SKRR5WT4.underline)(import_path.default.relative(process.cwd(), schemaPath))}` : "";
206
+ const introspectionSpinner = spinnerFactory(`Introspecting${basedOn}`);
207
+ const before = Math.round(performance.now());
208
+ let introspectionSchema = void 0;
209
+ let introspectionWarnings;
210
+ try {
211
+ const introspectionResult = await engine.introspect({
212
+ schema: (0, import_internals.toSchemasContainer)(schema),
213
+ baseDirectoryPath: rootDir,
214
+ force: args["--force"],
215
+ compositeTypeDepth: args["--composite-type-depth"],
216
+ namespaces: args["--schemas"]?.split(",")
217
+ });
218
+ introspectionSchema = introspectionResult.schema;
219
+ introspectionWarnings = introspectionResult.warnings;
220
+ debug(`Introspection warnings`, introspectionWarnings);
221
+ } catch (e) {
222
+ introspectionSpinner.failure();
223
+ if (e.code === "P4001" && (0, import_chunk_JFKDSUIE.isSchemaEmpty)(introspectionSchema)) {
224
+ throw new Error(`
225
+ ${(0, import_chunk_SKRR5WT4.red)((0, import_chunk_SKRR5WT4.bold)(`${e.code} `))}${(0, import_chunk_SKRR5WT4.red)("The introspected database was empty:")}
226
+
227
+ ${(0, import_chunk_SKRR5WT4.bold)("prisma db pull")} could not create any models in your ${(0, import_chunk_SKRR5WT4.bold)(
228
+ "schema.prisma"
229
+ )} file and you will not be able to generate Prisma Client with the ${(0, import_chunk_SKRR5WT4.bold)(
230
+ (0, import_internals.getCommandWithExecutor)("prisma generate")
231
+ )} command.
232
+
233
+ ${(0, import_chunk_SKRR5WT4.bold)("To fix this, you have two options:")}
234
+
235
+ - manually create a table in your database.
236
+ - make sure the database connection URL inside the ${(0, import_chunk_SKRR5WT4.bold)("datasource")} block in ${(0, import_chunk_SKRR5WT4.bold)(
237
+ "schema.prisma"
238
+ )} points to a database that is not empty (it must contain at least one table).
239
+
240
+ Then you can run ${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExecutor)("prisma db pull"))} again.
241
+ `);
242
+ } else if (e.code === "P1003") {
243
+ throw new Error(`
244
+ ${(0, import_chunk_SKRR5WT4.red)((0, import_chunk_SKRR5WT4.bold)(`${e.code} `))}${(0, import_chunk_SKRR5WT4.red)("The introspected database does not exist:")}
245
+
246
+ ${(0, import_chunk_SKRR5WT4.bold)("prisma db pull")} could not create any models in your ${(0, import_chunk_SKRR5WT4.bold)(
247
+ "schema.prisma"
248
+ )} file and you will not be able to generate Prisma Client with the ${(0, import_chunk_SKRR5WT4.bold)(
249
+ (0, import_internals.getCommandWithExecutor)("prisma generate")
250
+ )} command.
251
+
252
+ ${(0, import_chunk_SKRR5WT4.bold)("To fix this, you have two options:")}
253
+
254
+ - manually create a database.
255
+ - make sure the database connection URL inside the ${(0, import_chunk_SKRR5WT4.bold)("datasource")} block in ${(0, import_chunk_SKRR5WT4.bold)(
256
+ "schema.prisma"
257
+ )} points to an existing database.
258
+
259
+ Then you can run ${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExecutor)("prisma db pull"))} again.
260
+ `);
261
+ } else if (e.code === "P1012") {
262
+ process.stdout.write("\n");
263
+ const message = (0, import_internals.relativizePathInPSLError)(e.message);
264
+ throw new Error(`${(0, import_chunk_SKRR5WT4.red)(message)}
265
+ Introspection failed as your current Prisma schema file is invalid
266
+
267
+ Please fix your current schema manually (using either ${(0, import_chunk_SKRR5WT4.green)(
268
+ (0, import_internals.getCommandWithExecutor)("prisma validate")
269
+ )} or the Prisma VS Code extension to understand what's broken and confirm you fixed it), and then run this command again.
270
+ Or run this command with the ${(0, import_chunk_SKRR5WT4.green)(
271
+ "--force"
272
+ )} flag to ignore your current schema and overwrite it. All local modifications will be lost.
273
+ `);
274
+ }
275
+ process.stdout.write("\n");
276
+ throw e;
277
+ }
278
+ const introspectionWarningsMessage = this.getWarningMessage(introspectionWarnings);
279
+ if (args["--print"]) {
280
+ (0, import_chunk_AHJ2N6BJ.printIntrospectedSchema)(introspectionSchema, process.stdout);
281
+ if (introspectionWarningsMessage.trim().length > 0) {
282
+ console.error(introspectionWarningsMessage.replace(/(\n)/gm, "\n// "));
283
+ }
284
+ } else {
285
+ schemaPath = schemaPath || "schema.prisma";
286
+ if (args["--force"]) {
287
+ await (0, import_chunk_JZ75RIMZ.removeSchemaFiles)(schema);
288
+ }
289
+ await (0, import_chunk_RTGQXNX6.saveSchemaFiles)(introspectionSchema);
290
+ const { modelsCount, typesCount } = (0, import_chunk_LGYRZ6CV.countModelsAndTypes)(introspectionSchema);
291
+ const modelsCountMessage = `${modelsCount} ${modelsCount > 1 ? "models" : "model"}`;
292
+ const typesCountMessage = `${typesCount} ${typesCount > 1 ? "embedded documents" : "embedded document"}`;
293
+ let modelsAndTypesMessage;
294
+ if (typesCount > 0) {
295
+ modelsAndTypesMessage = `${modelsCountMessage} and ${typesCountMessage}`;
296
+ } else {
297
+ modelsAndTypesMessage = `${modelsCountMessage}`;
298
+ }
299
+ const modelsAndTypesCountMessage = modelsCount + typesCount > 1 ? `${modelsAndTypesMessage} and wrote them` : `${modelsAndTypesMessage} and wrote it`;
300
+ const renderValidationWarning = validationWarning ? `
301
+ ${(0, import_chunk_SKRR5WT4.yellow)(validationWarning)}` : "";
302
+ introspectionSpinner.success(`Introspected ${modelsAndTypesCountMessage} into ${(0, import_chunk_SKRR5WT4.underline)(
303
+ import_path.default.relative(process.cwd(), schemaPath)
304
+ )} in ${(0, import_chunk_SKRR5WT4.bold)((0, import_internals.formatms)(Math.round(performance.now()) - before))}
305
+ ${(0, import_chunk_SKRR5WT4.yellow)(introspectionWarningsMessage)}
306
+ ${`Run ${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExecutor)("prisma generate"))} to generate Prisma Client.`}${renderValidationWarning}`);
307
+ }
308
+ return "";
309
+ }
310
+ getWarningMessage(warnings) {
311
+ if (warnings) {
312
+ return `
313
+ ${warnings}`;
314
+ }
315
+ return "";
316
+ }
317
+ help(error) {
318
+ if (error) {
319
+ return new import_internals.HelpError(`
320
+ ${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
321
+ ${_DbPull2.help}`);
322
+ }
323
+ return _DbPull2.help;
324
+ }
325
+ };
326
+ _DbPull.help = (0, import_internals.format)(`
327
+ Pull the state from the database to the Prisma schema using introspection
328
+
329
+ ${(0, import_chunk_SKRR5WT4.bold)("Usage")}
330
+
331
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull [flags/options]
332
+
333
+ ${(0, import_chunk_SKRR5WT4.bold)("Flags")}
334
+
335
+ -h, --help Display this help message
336
+ --force Ignore current Prisma schema file
337
+ --print Print the introspected Prisma schema to stdout
338
+
339
+ ${(0, import_chunk_SKRR5WT4.bold)("Options")}
340
+
341
+ --config Custom path to your Prisma config file
342
+ --schema Custom path to your Prisma schema
343
+ --composite-type-depth Specify the depth for introspecting composite types (e.g. Embedded Documents in MongoDB)
344
+ Number, default is -1 for infinite depth, 0 = off
345
+ --schemas Specify the database schemas to introspect. This overrides the schemas defined in the datasource block of your Prisma schema.
346
+ --local-d1 Generate a Prisma schema from a local Cloudflare D1 database
347
+ ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
348
+
349
+ With an existing Prisma schema
350
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull
351
+
352
+ Or specify a Prisma schema path
353
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --schema=./schema.prisma
354
+
355
+ Instead of saving the result to the filesystem, you can also print it to stdout
356
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --print
357
+
358
+ Overwrite the current schema with the introspected schema instead of enriching it
359
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --force
360
+
361
+ Set composite types introspection depth to 2 levels
362
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --composite-type-depth=2
363
+
364
+ `);
365
+ var DbPull = _DbPull;
@@ -0,0 +1,122 @@
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_WNH2ACJS_exports = {};
20
+ __export(chunk_WNH2ACJS_exports, {
21
+ MigrateCommand: () => MigrateCommand
22
+ });
23
+ module.exports = __toCommonJS(chunk_WNH2ACJS_exports);
24
+ var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
25
+ var import_internals = require("@prisma/internals");
26
+ var _MigrateCommand = class _MigrateCommand2 {
27
+ constructor(cmds) {
28
+ this.cmds = cmds;
29
+ }
30
+ static new(cmds) {
31
+ return new _MigrateCommand2(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
+ "--preview-feature": Boolean,
39
+ "--telemetry-information": String
40
+ });
41
+ if ((0, import_internals.isError)(args)) {
42
+ return this.help(args.message);
43
+ }
44
+ if (args._.length === 0 || args["--help"]) {
45
+ return this.help();
46
+ }
47
+ const commandName = args._[0];
48
+ const cmd = this.cmds[commandName];
49
+ if (cmd) {
50
+ let argsForCmd;
51
+ if (commandName === "diff") {
52
+ argsForCmd = args["--preview-feature"] ? [...args._.slice(1), `--preview-feature`] : args._.slice(1);
53
+ } else {
54
+ const filteredArgs = args._.filter((item) => item !== "--preview-feature");
55
+ argsForCmd = filteredArgs.slice(1);
56
+ }
57
+ return cmd.parse(argsForCmd, config);
58
+ }
59
+ return (0, import_internals.unknownCommand)(_MigrateCommand2.help, commandName);
60
+ }
61
+ help(error) {
62
+ if (error) {
63
+ return new import_internals.HelpError(`
64
+ ${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
65
+ ${_MigrateCommand2.help}`);
66
+ }
67
+ return _MigrateCommand2.help;
68
+ }
69
+ };
70
+ _MigrateCommand.help = (0, import_internals.format)(`
71
+ Update the database schema with migrations
72
+
73
+ ${(0, import_chunk_SKRR5WT4.bold)("Usage")}
74
+
75
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate [command] [options]
76
+
77
+ ${(0, import_chunk_SKRR5WT4.bold)("Commands for development")}
78
+
79
+ dev Create a migration from changes in Prisma schema, apply it to the database
80
+ trigger generators (e.g. Prisma Client)
81
+ reset Reset your database and apply all migrations, all data will be lost
82
+
83
+ ${(0, import_chunk_SKRR5WT4.bold)("Commands for production/staging")}
84
+
85
+ deploy Apply pending migrations to the database
86
+ status Check the status of your database migrations
87
+ resolve Resolve issues with database migrations, i.e. baseline, failed migration, hotfix
88
+
89
+ ${(0, import_chunk_SKRR5WT4.bold)("Command for any stage")}
90
+
91
+ diff Compare the database schema from two arbitrary sources
92
+
93
+ ${(0, import_chunk_SKRR5WT4.bold)("Options")}
94
+
95
+ -h, --help Display this help message
96
+ --config Custom path to your Prisma config file
97
+ --schema Custom path to your Prisma schema
98
+
99
+ ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
100
+
101
+ Create a migration from changes in Prisma schema, apply it to the database, trigger generators (e.g. Prisma Client)
102
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate dev
103
+
104
+ Reset your database and apply all migrations
105
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate reset
106
+
107
+ Apply pending migrations to the database in production/staging
108
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate deploy
109
+
110
+ Check the status of migrations in the production/staging database
111
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate status
112
+
113
+ Specify a schema
114
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate status --schema=./schema.prisma
115
+
116
+ Compare the database schema from two databases and render the diff as a SQL script
117
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate diff \\
118
+ --from-url "$DATABASE_URL" \\
119
+ --to-url "postgresql://login:password@localhost:5432/db" \\
120
+ --script
121
+ `);
122
+ var MigrateCommand = _MigrateCommand;
@@ -26,24 +26,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_X6XGFLEF_exports = {};
30
- __export(chunk_X6XGFLEF_exports, {
29
+ var chunk_YZVZCC3I_exports = {};
30
+ __export(chunk_YZVZCC3I_exports, {
31
31
  DbDrop: () => DbDrop
32
32
  });
33
- module.exports = __toCommonJS(chunk_X6XGFLEF_exports);
34
- var import_chunk_WLJHGKMK = require("./chunk-WLJHGKMK.js");
35
- var import_chunk_U374EXYQ = require("./chunk-U374EXYQ.js");
36
- var import_chunk_M5YNQ2NP = require("./chunk-M5YNQ2NP.js");
37
- var import_chunk_Q7ACZDDT = require("./chunk-Q7ACZDDT.js");
38
- var import_chunk_XJQP3B4W = require("./chunk-XJQP3B4W.js");
39
- var import_chunk_6TE2RIPN = require("./chunk-6TE2RIPN.js");
33
+ module.exports = __toCommonJS(chunk_YZVZCC3I_exports);
34
+ var import_chunk_IHDN3L3R = require("./chunk-IHDN3L3R.js");
35
+ var import_chunk_3WC4XD74 = require("./chunk-3WC4XD74.js");
36
+ var import_chunk_6DFJIBJX = require("./chunk-6DFJIBJX.js");
37
+ var import_chunk_QOPTDDIH = require("./chunk-QOPTDDIH.js");
38
+ var import_chunk_DJMFXNR4 = require("./chunk-DJMFXNR4.js");
39
+ var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
40
40
  var import_internals = require("@prisma/internals");
41
41
  var import_prompts = __toESM(require("prompts"));
42
- (0, import_chunk_6TE2RIPN.init_colors)();
43
- (0, import_chunk_XJQP3B4W.init_ensureDatabaseExists)();
44
- (0, import_chunk_U374EXYQ.init_errors)();
45
- (0, import_chunk_M5YNQ2NP.init_getSchemaPathAndPrint)();
46
- (0, import_chunk_Q7ACZDDT.init_printDatasource)();
47
42
  var _DbDrop = class _DbDrop2 {
48
43
  static new() {
49
44
  return new _DbDrop2();
@@ -67,23 +62,23 @@ var _DbDrop = class _DbDrop2 {
67
62
  return this.help();
68
63
  }
69
64
  if (!args["--preview-feature"]) {
70
- throw new import_chunk_WLJHGKMK.PreviewFlagError();
65
+ throw new import_chunk_IHDN3L3R.PreviewFlagError();
71
66
  }
72
67
  await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true, config });
73
- const { schemaPath } = await (0, import_chunk_M5YNQ2NP.getSchemaPathAndPrint)(args["--schema"], config.schema);
74
- const datasourceInfo = await (0, import_chunk_XJQP3B4W.getDatasourceInfo)({ schemaPath, throwIfEnvError: true });
75
- (0, import_chunk_Q7ACZDDT.printDatasource)({ datasourceInfo });
68
+ const { schemaPath } = await (0, import_chunk_6DFJIBJX.getSchemaPathAndPrint)(args["--schema"], config.schema);
69
+ const datasourceInfo = await (0, import_chunk_DJMFXNR4.getDatasourceInfo)({ schemaPath, throwIfEnvError: true });
70
+ (0, import_chunk_QOPTDDIH.printDatasource)({ datasourceInfo });
76
71
  process.stdout.write("\n");
77
72
  if (!args["--force"]) {
78
73
  if (!(0, import_internals.canPrompt)()) {
79
- throw new import_chunk_U374EXYQ.DbDropNeedsForceError("drop");
74
+ throw new import_chunk_3WC4XD74.DbDropNeedsForceError("drop");
80
75
  }
81
76
  const confirmation = await (0, import_prompts.default)({
82
77
  type: "text",
83
78
  name: "value",
84
79
  message: `Enter the ${datasourceInfo.prettyProvider} database name "${datasourceInfo.dbName}" to drop it.
85
80
  Location: "${datasourceInfo.dbLocation}".
86
- ${(0, import_chunk_6TE2RIPN.red)("All data will be lost")}.`
81
+ ${(0, import_chunk_SKRR5WT4.red)("All data will be lost")}.`
87
82
  });
88
83
  process.stdout.write("\n");
89
84
  if (!confirmation.value) {
@@ -103,7 +98,7 @@ ${(0, import_chunk_6TE2RIPN.red)("All data will be lost")}.`
103
98
  help(error) {
104
99
  if (error) {
105
100
  return new import_internals.HelpError(`
106
- ${(0, import_chunk_6TE2RIPN.bold)((0, import_chunk_6TE2RIPN.red)(`!`))} ${error}
101
+ ${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
107
102
  ${_DbDrop2.help}`);
108
103
  }
109
104
  return _DbDrop2.help;
@@ -112,32 +107,32 @@ ${_DbDrop2.help}`);
112
107
  _DbDrop.help = (0, import_internals.format)(`
113
108
  ${process.platform === "win32" ? "" : "\u{1F4A3} "}Drop the database
114
109
 
115
- ${(0, import_chunk_6TE2RIPN.bold)((0, import_chunk_6TE2RIPN.yellow)("WARNING"))} ${(0, import_chunk_6TE2RIPN.bold)(
110
+ ${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.yellow)("WARNING"))} ${(0, import_chunk_SKRR5WT4.bold)(
116
111
  `Prisma db drop is currently in Preview (${(0, import_internals.link)("https://pris.ly/d/preview")}).
117
112
  There may be bugs and it's not recommended to use it in production environments.`
118
113
  )}
119
- ${(0, import_chunk_6TE2RIPN.dim)("When using any of the subcommands below you need to explicitly opt-in via the --preview-feature flag.")}
114
+ ${(0, import_chunk_SKRR5WT4.dim)("When using any of the subcommands below you need to explicitly opt-in via the --preview-feature flag.")}
120
115
 
121
- ${(0, import_chunk_6TE2RIPN.bold)("Usage")}
116
+ ${(0, import_chunk_SKRR5WT4.bold)("Usage")}
122
117
 
123
- ${(0, import_chunk_6TE2RIPN.dim)("$")} prisma db drop [options] --preview-feature
118
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db drop [options] --preview-feature
124
119
 
125
- ${(0, import_chunk_6TE2RIPN.bold)("Options")}
120
+ ${(0, import_chunk_SKRR5WT4.bold)("Options")}
126
121
 
127
122
  -h, --help Display this help message
128
123
  --config Custom path to your Prisma config file
129
124
  --schema Custom path to your Prisma schema
130
125
  -f, --force Skip the confirmation prompt
131
126
 
132
- ${(0, import_chunk_6TE2RIPN.bold)("Examples")}
127
+ ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
133
128
 
134
129
  Drop the database
135
- ${(0, import_chunk_6TE2RIPN.dim)("$")} prisma db drop --preview-feature
130
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db drop --preview-feature
136
131
 
137
132
  Specify a schema
138
- ${(0, import_chunk_6TE2RIPN.dim)("$")} prisma db drop --preview-feature --schema=./schema.prisma
133
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db drop --preview-feature --schema=./schema.prisma
139
134
 
140
135
  Use --force to skip the confirmation prompt
141
- ${(0, import_chunk_6TE2RIPN.dim)("$")} prisma db drop --preview-feature --force
136
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db drop --preview-feature --force
142
137
  `);
143
138
  var DbDrop = _DbDrop;
@@ -18,10 +18,9 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var DbCommand_exports = {};
20
20
  __export(DbCommand_exports, {
21
- DbCommand: () => import_chunk_O4BT6W33.DbCommand
21
+ DbCommand: () => import_chunk_HIFVDK2U.DbCommand
22
22
  });
23
23
  module.exports = __toCommonJS(DbCommand_exports);
24
- var import_chunk_O4BT6W33 = require("../chunk-O4BT6W33.js");
25
- var import_chunk_6TE2RIPN = require("../chunk-6TE2RIPN.js");
24
+ var import_chunk_HIFVDK2U = require("../chunk-HIFVDK2U.js");
25
+ var import_chunk_SKRR5WT4 = require("../chunk-SKRR5WT4.js");
26
26
  var import_chunk_WWAWV7DQ = require("../chunk-WWAWV7DQ.js");
27
- (0, import_chunk_O4BT6W33.init_DbCommand)();
@@ -18,15 +18,15 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var DbDrop_exports = {};
20
20
  __export(DbDrop_exports, {
21
- DbDrop: () => import_chunk_X6XGFLEF.DbDrop
21
+ DbDrop: () => import_chunk_YZVZCC3I.DbDrop
22
22
  });
23
23
  module.exports = __toCommonJS(DbDrop_exports);
24
- var import_chunk_X6XGFLEF = require("../chunk-X6XGFLEF.js");
25
- var import_chunk_WLJHGKMK = require("../chunk-WLJHGKMK.js");
26
- var import_chunk_U374EXYQ = require("../chunk-U374EXYQ.js");
27
- var import_chunk_M5YNQ2NP = require("../chunk-M5YNQ2NP.js");
28
- var import_chunk_Q7ACZDDT = require("../chunk-Q7ACZDDT.js");
29
- var import_chunk_XJQP3B4W = require("../chunk-XJQP3B4W.js");
30
- var import_chunk_KPUNMK5W = require("../chunk-KPUNMK5W.js");
31
- var import_chunk_6TE2RIPN = require("../chunk-6TE2RIPN.js");
24
+ var import_chunk_YZVZCC3I = require("../chunk-YZVZCC3I.js");
25
+ var import_chunk_IHDN3L3R = require("../chunk-IHDN3L3R.js");
26
+ var import_chunk_3WC4XD74 = require("../chunk-3WC4XD74.js");
27
+ var import_chunk_6DFJIBJX = require("../chunk-6DFJIBJX.js");
28
+ var import_chunk_QOPTDDIH = require("../chunk-QOPTDDIH.js");
29
+ var import_chunk_DJMFXNR4 = require("../chunk-DJMFXNR4.js");
30
+ var import_chunk_TWPTG4XS = require("../chunk-TWPTG4XS.js");
31
+ var import_chunk_SKRR5WT4 = require("../chunk-SKRR5WT4.js");
32
32
  var import_chunk_WWAWV7DQ = require("../chunk-WWAWV7DQ.js");
@@ -18,16 +18,15 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var DbExecute_exports = {};
20
20
  __export(DbExecute_exports, {
21
- DbExecute: () => import_chunk_AOX7CJAS.DbExecute
21
+ DbExecute: () => import_chunk_4EV2RVXY.DbExecute
22
22
  });
23
23
  module.exports = __toCommonJS(DbExecute_exports);
24
- var import_chunk_AOX7CJAS = require("../chunk-AOX7CJAS.js");
25
- var import_chunk_UVNSK22K = require("../chunk-UVNSK22K.js");
24
+ var import_chunk_4EV2RVXY = require("../chunk-4EV2RVXY.js");
25
+ var import_chunk_DDHPSYC4 = require("../chunk-DDHPSYC4.js");
26
26
  var import_chunk_6C7ESGWY = require("../chunk-6C7ESGWY.js");
27
27
  var import_chunk_J46BJQHT = require("../chunk-J46BJQHT.js");
28
- var import_chunk_7S3Q4MCN = require("../chunk-7S3Q4MCN.js");
29
- var import_chunk_CQQQ436N = require("../chunk-CQQQ436N.js");
30
- var import_chunk_AAATUOV6 = require("../chunk-AAATUOV6.js");
31
- var import_chunk_6TE2RIPN = require("../chunk-6TE2RIPN.js");
28
+ var import_chunk_ORL3LJOT = require("../chunk-ORL3LJOT.js");
29
+ var import_chunk_MATFO4ZW = require("../chunk-MATFO4ZW.js");
30
+ var import_chunk_L6KOIJJ5 = require("../chunk-L6KOIJJ5.js");
31
+ var import_chunk_SKRR5WT4 = require("../chunk-SKRR5WT4.js");
32
32
  var import_chunk_WWAWV7DQ = require("../chunk-WWAWV7DQ.js");
33
- (0, import_chunk_AOX7CJAS.init_DbExecute)();