@prisma/migrate 6.5.0-dev.1 → 6.5.0-dev.3

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 (102) 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-M5YNQ2NP.js → chunk-6DFJIBJX.js} +5 -12
  11. package/dist/{chunk-SGCF5OHF.js → chunk-7CQBDP4H.js} +6 -13
  12. package/dist/{chunk-7IT2ZO3D.js → chunk-AHJ2N6BJ.js} +3 -9
  13. package/dist/chunk-C2PR6JQR.js +266 -0
  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-V5LEZ5BX.js → chunk-DY3QUOB7.js} +634 -807
  20. package/dist/{chunk-YD7GG4WS.js → chunk-FRTPDRF2.js} +66 -74
  21. package/dist/chunk-HIFVDK2U.js +96 -0
  22. package/dist/chunk-I4EY55DC.js +195 -0
  23. package/dist/{chunk-WLJHGKMK.js → chunk-IHDN3L3R.js} +7 -8
  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-IFCV5MY4.js → chunk-OCQGHQED.js} +5 -11
  31. package/dist/chunk-ORL3LJOT.js +470 -0
  32. package/dist/{chunk-Q7ACZDDT.js → chunk-QOPTDDIH.js} +5 -12
  33. package/dist/chunk-QTAIWPLH.js +78 -0
  34. package/dist/{chunk-35LAJN5S.js → chunk-RP2N6UXA.js} +23 -29
  35. package/dist/chunk-RQFGRXJI.js +174 -0
  36. package/dist/{chunk-QBK5XTJE.js → chunk-RR6BKMNO.js} +3 -9
  37. package/dist/{chunk-ILJRJJ3S.js → chunk-RTGQXNX6.js} +3 -9
  38. package/dist/chunk-SKRR5WT4.js +76 -0
  39. package/dist/chunk-TM3ETZES.js +153 -0
  40. package/dist/{chunk-KPUNMK5W.js → chunk-TWPTG4XS.js} +5 -12
  41. package/dist/{chunk-6QFE3AWR.js → chunk-UP6FVCDK.js} +6 -13
  42. package/dist/{chunk-YKUZUAXA.js → chunk-V3ZMNXZC.js} +16 -23
  43. package/dist/chunk-WLPX3672.js +365 -0
  44. package/dist/chunk-WNH2ACJS.js +122 -0
  45. package/dist/chunk-XSNOKQTD.js +347 -0
  46. package/dist/{chunk-X6XGFLEF.js → chunk-YZVZCC3I.js} +25 -30
  47. package/dist/commands/DbCommand.js +3 -4
  48. package/dist/commands/DbDrop.js +9 -9
  49. package/dist/commands/DbExecute.js +7 -8
  50. package/dist/commands/DbPull.js +18 -19
  51. package/dist/commands/DbPush.js +12 -13
  52. package/dist/commands/DbSeed.js +4 -5
  53. package/dist/commands/MigrateCommand.js +3 -4
  54. package/dist/commands/MigrateDeploy.js +13 -14
  55. package/dist/commands/MigrateDev.js +17 -18
  56. package/dist/commands/MigrateDiff.js +8 -9
  57. package/dist/commands/MigrateReset.js +15 -16
  58. package/dist/commands/MigrateResolve.js +11 -12
  59. package/dist/commands/MigrateStatus.js +11 -12
  60. package/dist/index.js +60 -77
  61. package/dist/{multipart-parser-73VM3J4A.js → multipart-parser-NDLECNMN.js} +527 -561
  62. package/dist/utils/byline.js +5 -6
  63. package/dist/utils/captureStdout.js +2 -3
  64. package/dist/utils/countModelsAndTypes.js +2 -3
  65. package/dist/utils/ensureDatabaseExists.js +8 -9
  66. package/dist/utils/errors.js +8 -9
  67. package/dist/utils/flagErrors.js +5 -5
  68. package/dist/utils/getDatabaseVersionSafe.js +6 -7
  69. package/dist/utils/getSchemaPathAndPrint.js +4 -5
  70. package/dist/utils/handleEvaluateDataloss.js +3 -4
  71. package/dist/utils/introspectSql.js +6 -6
  72. package/dist/utils/isSchemaEmpty.js +2 -3
  73. package/dist/utils/printDatasource.js +3 -4
  74. package/dist/utils/printDatasources.js +3 -4
  75. package/dist/utils/printFiles.js +5 -6
  76. package/dist/utils/printIntrospectedSchema.js +2 -3
  77. package/dist/utils/printMigrationId.js +4 -5
  78. package/dist/utils/promptForMigrationName.js +2 -3
  79. package/dist/utils/removeSchemaFiles.js +2 -3
  80. package/dist/utils/replaceOrAddDatasource.js +2 -3
  81. package/dist/utils/replaceOrAddDatasource.test.js +7 -8
  82. package/dist/utils/saveSchemaFiles.js +2 -3
  83. package/dist/utils/seed.js +6 -7
  84. package/dist/utils/spinner.js +2 -3
  85. package/dist/utils/unixSocket.js +2 -3
  86. package/dist/views/handleViewsIO.js +2 -3
  87. package/package.json +6 -6
  88. package/dist/chunk-26XQQ4AG.js +0 -386
  89. package/dist/chunk-2RSEPJFX.js +0 -165
  90. package/dist/chunk-4B2LXK4R.js +0 -207
  91. package/dist/chunk-4UJBOCZJ.js +0 -130
  92. package/dist/chunk-5HZLCY6X.js +0 -161
  93. package/dist/chunk-6TE2RIPN.js +0 -80
  94. package/dist/chunk-7S3Q4MCN.js +0 -480
  95. package/dist/chunk-AOX7CJAS.js +0 -234
  96. package/dist/chunk-FF3526PX.js +0 -279
  97. package/dist/chunk-FUSFURVP.js +0 -86
  98. package/dist/chunk-GCTCQLOF.js +0 -365
  99. package/dist/chunk-K44VNAFW.js +0 -189
  100. package/dist/chunk-O4BT6W33.js +0 -104
  101. package/dist/chunk-TKAGMA5K.js +0 -72
  102. package/dist/chunk-U374EXYQ.js +0 -106
@@ -1,386 +0,0 @@
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_26XQQ4AG_exports = {};
30
- __export(chunk_26XQQ4AG_exports, {
31
- DbPull: () => DbPull,
32
- init_DbPull: () => init_DbPull
33
- });
34
- module.exports = __toCommonJS(chunk_26XQQ4AG_exports);
35
- var import_chunk_CUDKD32S = require("./chunk-CUDKD32S.js");
36
- var import_chunk_ILJRJJ3S = require("./chunk-ILJRJJ3S.js");
37
- var import_chunk_35LAJN5S = require("./chunk-35LAJN5S.js");
38
- var import_chunk_7IT2ZO3D = require("./chunk-7IT2ZO3D.js");
39
- var import_chunk_V7DE6JTG = require("./chunk-V7DE6JTG.js");
40
- var import_chunk_QBK5XTJE = require("./chunk-QBK5XTJE.js");
41
- var import_chunk_INC2OACE = require("./chunk-INC2OACE.js");
42
- var import_chunk_GN5BY5N2 = require("./chunk-GN5BY5N2.js");
43
- var import_chunk_7S3Q4MCN = require("./chunk-7S3Q4MCN.js");
44
- var import_chunk_CQQQ436N = require("./chunk-CQQQ436N.js");
45
- var import_chunk_U374EXYQ = require("./chunk-U374EXYQ.js");
46
- var import_chunk_Q7ACZDDT = require("./chunk-Q7ACZDDT.js");
47
- var import_chunk_XJQP3B4W = require("./chunk-XJQP3B4W.js");
48
- var import_chunk_6TE2RIPN = require("./chunk-6TE2RIPN.js");
49
- var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
50
- var import_debug = __toESM(require("@prisma/debug"));
51
- var import_internals = require("@prisma/internals");
52
- var import_path = __toESM(require("path"));
53
- var debug, _DbPull, DbPull;
54
- var init_DbPull = (0, import_chunk_WWAWV7DQ.__esm)({
55
- "src/commands/DbPull.ts"() {
56
- (0, import_chunk_6TE2RIPN.init_colors)();
57
- (0, import_chunk_CQQQ436N.init_dist)();
58
- (0, import_chunk_7S3Q4MCN.init_SchemaEngine)();
59
- (0, import_chunk_GN5BY5N2.init_countModelsAndTypes)();
60
- (0, import_chunk_XJQP3B4W.init_ensureDatabaseExists)();
61
- (0, import_chunk_U374EXYQ.init_errors)();
62
- (0, import_chunk_INC2OACE.init_isSchemaEmpty)();
63
- (0, import_chunk_Q7ACZDDT.init_printDatasource)();
64
- (0, import_chunk_35LAJN5S.init_printDatasources)();
65
- (0, import_chunk_7IT2ZO3D.init_printIntrospectedSchema)();
66
- (0, import_chunk_V7DE6JTG.init_removeSchemaFiles)();
67
- (0, import_chunk_QBK5XTJE.init_replaceOrAddDatasource)();
68
- (0, import_chunk_ILJRJJ3S.init_saveSchemaFiles)();
69
- (0, import_chunk_CUDKD32S.init_spinner)();
70
- debug = (0, import_debug.default)("prisma:db:pull");
71
- _DbPull = class _DbPull2 {
72
- static new() {
73
- return new _DbPull2();
74
- }
75
- urlToDatasource(url, defaultProvider) {
76
- const provider = defaultProvider || (0, import_internals.protocolToConnectorType)(`${url.split(":")[0]}:`);
77
- return (0, import_chunk_35LAJN5S.printDatasources)([
78
- {
79
- config: {},
80
- provider,
81
- name: "db",
82
- url
83
- }
84
- ]);
85
- }
86
- async parse(argv, config) {
87
- const args = (0, import_internals.arg)(argv, {
88
- "--help": Boolean,
89
- "-h": "--help",
90
- "--url": String,
91
- "--print": Boolean,
92
- "--schema": String,
93
- "--config": String,
94
- "--schemas": String,
95
- "--force": Boolean,
96
- "--composite-type-depth": Number,
97
- // optional, only on mongodb
98
- "--local-d1": Boolean
99
- // optional, only on cloudflare D1
100
- });
101
- const spinnerFactory = (0, import_chunk_CUDKD32S.createSpinner)(!args["--print"]);
102
- if (args instanceof Error) {
103
- return this.help(args.message);
104
- }
105
- await (0, import_internals.checkUnsupportedDataProxy)("db pull", args, config.schema, !args["--url"]);
106
- if (args["--help"]) {
107
- return this.help();
108
- }
109
- const url = args["--url"];
110
- const schemaPathResult = await (0, import_internals.getSchemaWithPathOptional)(args["--schema"], config.schema);
111
- let schemaPath = schemaPathResult?.schemaPath ?? null;
112
- const rootDir = schemaPathResult?.schemaRootDir ?? process.cwd();
113
- debug("schemaPathResult", schemaPathResult);
114
- if (schemaPath && !args["--print"]) {
115
- process.stdout.write((0, import_chunk_6TE2RIPN.dim)(`Prisma schema loaded from ${import_path.default.relative(process.cwd(), schemaPath)}`) + "\n");
116
- await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true, config });
117
- (0, import_chunk_Q7ACZDDT.printDatasource)({ datasourceInfo: await (0, import_chunk_XJQP3B4W.getDatasourceInfo)({ schemaPath }) });
118
- } else {
119
- await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: false, config });
120
- }
121
- const fromD1 = Boolean(args["--local-d1"]);
122
- if (!url && !schemaPath && !fromD1) {
123
- throw new import_chunk_U374EXYQ.NoSchemaFoundError();
124
- }
125
- const { firstDatasource, schema, validationWarning } = await (0, import_chunk_CQQQ436N.z)({ url, schemaPath, fromD1 }).when(
126
- (input) => input.schemaPath !== null,
127
- async (input) => {
128
- const rawSchema = await (0, import_internals.getSchema)(input.schemaPath, config.schema);
129
- const engineConfig = await (0, import_internals.getConfig)({
130
- datamodel: rawSchema,
131
- ignoreEnvVarErrors: true
132
- });
133
- const previewFeatures = engineConfig.generators.find(({ name }) => name === "client")?.previewFeatures;
134
- const firstDatasource2 = engineConfig.datasources[0] ? engineConfig.datasources[0] : void 0;
135
- if (input.url) {
136
- let providerFromSchema = firstDatasource2?.provider;
137
- if (providerFromSchema === "postgres") {
138
- providerFromSchema = "postgresql";
139
- }
140
- const providerFromUrl = (0, import_internals.protocolToConnectorType)(`${input.url.split(":")[0]}:`);
141
- const schema2 = (0, import_chunk_QBK5XTJE.replaceOrAddDatasource)(this.urlToDatasource(input.url, providerFromSchema), rawSchema);
142
- if (providerFromSchema && providerFromUrl && providerFromSchema !== providerFromUrl && Boolean(providerFromSchema === "cockroachdb" && providerFromUrl === "postgresql") === false) {
143
- throw new Error(
144
- `The database provider found in --url (${providerFromUrl}) is different from the provider found in the Prisma schema (${providerFromSchema}).`
145
- );
146
- }
147
- return { firstDatasource: firstDatasource2, schema: schema2, validationWarning: void 0 };
148
- } else if (input.fromD1) {
149
- const d1Database = await (0, import_internals.locateLocalCloudflareD1)({ arg: "--from-local-d1" });
150
- const pathToSQLiteFile = import_path.default.relative(import_path.default.dirname(input.schemaPath), d1Database);
151
- const schema2 = [
152
- ["schema.prisma", this.urlToDatasource(`file:${pathToSQLiteFile}`, "sqlite")]
153
- ];
154
- const config2 = await (0, import_internals.getConfig)({
155
- datamodel: schema2,
156
- ignoreEnvVarErrors: true
157
- });
158
- const result = { firstDatasource: config2.datasources[0], schema: schema2, validationWarning: void 0 };
159
- const hasDriverAdaptersPreviewFeature = (previewFeatures || []).includes("driverAdapters");
160
- const validationWarning2 = `Without the ${(0, import_chunk_6TE2RIPN.bold)(
161
- "driverAdapters"
162
- )} preview feature, the schema introspected via the ${(0, import_chunk_6TE2RIPN.bold)("--local-d1")} flag will not work with ${(0, import_chunk_6TE2RIPN.bold)(
163
- "@prisma/client"
164
- )}.`;
165
- if (hasDriverAdaptersPreviewFeature) {
166
- return result;
167
- } else {
168
- return { ...result, validationWarning: validationWarning2 };
169
- }
170
- } else {
171
- await (0, import_internals.getConfig)({
172
- datamodel: rawSchema,
173
- ignoreEnvVarErrors: false
174
- });
175
- }
176
- return { firstDatasource: firstDatasource2, schema: rawSchema, validationWarning: void 0 };
177
- }
178
- ).when(
179
- (input) => input.fromD1 === true,
180
- async (_) => {
181
- const d1Database = await (0, import_internals.locateLocalCloudflareD1)({ arg: "--from-local-d1" });
182
- const pathToSQLiteFile = import_path.default.relative(process.cwd(), d1Database);
183
- const schemaContent = `generator client {
184
- provider = "prisma-client-js"
185
- previewFeatures = ["driverAdapters"]
186
- }
187
- ${this.urlToDatasource(`file:${pathToSQLiteFile}`, "sqlite")}`;
188
- const schema2 = [["schema.prisma", schemaContent]];
189
- const config2 = await (0, import_internals.getConfig)({
190
- datamodel: schema2,
191
- ignoreEnvVarErrors: true
192
- });
193
- return { firstDatasource: config2.datasources[0], schema: schema2, validationWarning: void 0 };
194
- }
195
- ).when(
196
- (input) => input.url !== void 0,
197
- async (input) => {
198
- (0, import_internals.protocolToConnectorType)(`${input.url.split(":")[0]}:`);
199
- const schema2 = [["schema.prisma", this.urlToDatasource(input.url)]];
200
- const config2 = await (0, import_internals.getConfig)({
201
- datamodel: schema2,
202
- ignoreEnvVarErrors: true
203
- });
204
- return { firstDatasource: config2.datasources[0], schema: schema2, validationWarning: void 0 };
205
- }
206
- ).run();
207
- if (schemaPath) {
208
- const schemas = await (0, import_internals.getSchema)(args["--schema"], config.schema);
209
- const modelRegex = /\s*model\s*(\w+)\s*{/;
210
- const isReintrospection = schemas.some(([_, schema2]) => !!modelRegex.exec(schema2));
211
- if (isReintrospection && !args["--force"] && firstDatasource?.provider === "mongodb") {
212
- throw new Error(`Iterating on one schema using re-introspection with db pull is currently not supported with MongoDB provider.
213
- You can explicitly ignore and override your current local schema file with ${(0, import_chunk_6TE2RIPN.green)(
214
- (0, import_internals.getCommandWithExecutor)("prisma db pull --force")
215
- )}
216
- Some information will be lost (relations, comments, mapped fields, @ignore...), follow ${(0, import_internals.link)(
217
- "https://github.com/prisma/prisma/issues/9585"
218
- )} for more info.`);
219
- }
220
- }
221
- const engine = new import_chunk_7S3Q4MCN.SchemaEngine({
222
- schemaPath: schemaPath ?? void 0
223
- });
224
- const basedOn = !args["--url"] && schemaPath ? ` based on datasource defined in ${(0, import_chunk_6TE2RIPN.underline)(import_path.default.relative(process.cwd(), schemaPath))}` : "";
225
- const introspectionSpinner = spinnerFactory(`Introspecting${basedOn}`);
226
- const before = Math.round(performance.now());
227
- let introspectionSchema = void 0;
228
- let introspectionWarnings;
229
- try {
230
- const introspectionResult = await engine.introspect({
231
- schema: (0, import_internals.toSchemasContainer)(schema),
232
- baseDirectoryPath: rootDir,
233
- force: args["--force"],
234
- compositeTypeDepth: args["--composite-type-depth"],
235
- namespaces: args["--schemas"]?.split(",")
236
- });
237
- introspectionSchema = introspectionResult.schema;
238
- introspectionWarnings = introspectionResult.warnings;
239
- debug(`Introspection warnings`, introspectionWarnings);
240
- } catch (e) {
241
- introspectionSpinner.failure();
242
- if (e.code === "P4001" && (0, import_chunk_INC2OACE.isSchemaEmpty)(introspectionSchema)) {
243
- throw new Error(`
244
- ${(0, import_chunk_6TE2RIPN.red)((0, import_chunk_6TE2RIPN.bold)(`${e.code} `))}${(0, import_chunk_6TE2RIPN.red)("The introspected database was empty:")}
245
-
246
- ${(0, import_chunk_6TE2RIPN.bold)("prisma db pull")} could not create any models in your ${(0, import_chunk_6TE2RIPN.bold)(
247
- "schema.prisma"
248
- )} file and you will not be able to generate Prisma Client with the ${(0, import_chunk_6TE2RIPN.bold)(
249
- (0, import_internals.getCommandWithExecutor)("prisma generate")
250
- )} command.
251
-
252
- ${(0, import_chunk_6TE2RIPN.bold)("To fix this, you have two options:")}
253
-
254
- - manually create a table in your database.
255
- - make sure the database connection URL inside the ${(0, import_chunk_6TE2RIPN.bold)("datasource")} block in ${(0, import_chunk_6TE2RIPN.bold)(
256
- "schema.prisma"
257
- )} points to a database that is not empty (it must contain at least one table).
258
-
259
- Then you can run ${(0, import_chunk_6TE2RIPN.green)((0, import_internals.getCommandWithExecutor)("prisma db pull"))} again.
260
- `);
261
- } else if (e.code === "P1003") {
262
- throw new Error(`
263
- ${(0, import_chunk_6TE2RIPN.red)((0, import_chunk_6TE2RIPN.bold)(`${e.code} `))}${(0, import_chunk_6TE2RIPN.red)("The introspected database does not exist:")}
264
-
265
- ${(0, import_chunk_6TE2RIPN.bold)("prisma db pull")} could not create any models in your ${(0, import_chunk_6TE2RIPN.bold)(
266
- "schema.prisma"
267
- )} file and you will not be able to generate Prisma Client with the ${(0, import_chunk_6TE2RIPN.bold)(
268
- (0, import_internals.getCommandWithExecutor)("prisma generate")
269
- )} command.
270
-
271
- ${(0, import_chunk_6TE2RIPN.bold)("To fix this, you have two options:")}
272
-
273
- - manually create a database.
274
- - make sure the database connection URL inside the ${(0, import_chunk_6TE2RIPN.bold)("datasource")} block in ${(0, import_chunk_6TE2RIPN.bold)(
275
- "schema.prisma"
276
- )} points to an existing database.
277
-
278
- Then you can run ${(0, import_chunk_6TE2RIPN.green)((0, import_internals.getCommandWithExecutor)("prisma db pull"))} again.
279
- `);
280
- } else if (e.code === "P1012") {
281
- process.stdout.write("\n");
282
- const message = (0, import_internals.relativizePathInPSLError)(e.message);
283
- throw new Error(`${(0, import_chunk_6TE2RIPN.red)(message)}
284
- Introspection failed as your current Prisma schema file is invalid
285
-
286
- Please fix your current schema manually (using either ${(0, import_chunk_6TE2RIPN.green)(
287
- (0, import_internals.getCommandWithExecutor)("prisma validate")
288
- )} or the Prisma VS Code extension to understand what's broken and confirm you fixed it), and then run this command again.
289
- Or run this command with the ${(0, import_chunk_6TE2RIPN.green)(
290
- "--force"
291
- )} flag to ignore your current schema and overwrite it. All local modifications will be lost.
292
- `);
293
- }
294
- process.stdout.write("\n");
295
- throw e;
296
- }
297
- const introspectionWarningsMessage = this.getWarningMessage(introspectionWarnings);
298
- if (args["--print"]) {
299
- (0, import_chunk_7IT2ZO3D.printIntrospectedSchema)(introspectionSchema, process.stdout);
300
- if (introspectionWarningsMessage.trim().length > 0) {
301
- console.error(introspectionWarningsMessage.replace(/(\n)/gm, "\n// "));
302
- }
303
- } else {
304
- schemaPath = schemaPath || "schema.prisma";
305
- if (args["--force"]) {
306
- await (0, import_chunk_V7DE6JTG.removeSchemaFiles)(schema);
307
- }
308
- await (0, import_chunk_ILJRJJ3S.saveSchemaFiles)(introspectionSchema);
309
- const { modelsCount, typesCount } = (0, import_chunk_GN5BY5N2.countModelsAndTypes)(introspectionSchema);
310
- const modelsCountMessage = `${modelsCount} ${modelsCount > 1 ? "models" : "model"}`;
311
- const typesCountMessage = `${typesCount} ${typesCount > 1 ? "embedded documents" : "embedded document"}`;
312
- let modelsAndTypesMessage;
313
- if (typesCount > 0) {
314
- modelsAndTypesMessage = `${modelsCountMessage} and ${typesCountMessage}`;
315
- } else {
316
- modelsAndTypesMessage = `${modelsCountMessage}`;
317
- }
318
- const modelsAndTypesCountMessage = modelsCount + typesCount > 1 ? `${modelsAndTypesMessage} and wrote them` : `${modelsAndTypesMessage} and wrote it`;
319
- const renderValidationWarning = validationWarning ? `
320
- ${(0, import_chunk_6TE2RIPN.yellow)(validationWarning)}` : "";
321
- introspectionSpinner.success(`Introspected ${modelsAndTypesCountMessage} into ${(0, import_chunk_6TE2RIPN.underline)(
322
- import_path.default.relative(process.cwd(), schemaPath)
323
- )} in ${(0, import_chunk_6TE2RIPN.bold)((0, import_internals.formatms)(Math.round(performance.now()) - before))}
324
- ${(0, import_chunk_6TE2RIPN.yellow)(introspectionWarningsMessage)}
325
- ${`Run ${(0, import_chunk_6TE2RIPN.green)((0, import_internals.getCommandWithExecutor)("prisma generate"))} to generate Prisma Client.`}${renderValidationWarning}`);
326
- }
327
- return "";
328
- }
329
- getWarningMessage(warnings) {
330
- if (warnings) {
331
- return `
332
- ${warnings}`;
333
- }
334
- return "";
335
- }
336
- help(error) {
337
- if (error) {
338
- return new import_internals.HelpError(`
339
- ${(0, import_chunk_6TE2RIPN.bold)((0, import_chunk_6TE2RIPN.red)(`!`))} ${error}
340
- ${_DbPull2.help}`);
341
- }
342
- return _DbPull2.help;
343
- }
344
- };
345
- _DbPull.help = (0, import_internals.format)(`
346
- Pull the state from the database to the Prisma schema using introspection
347
-
348
- ${(0, import_chunk_6TE2RIPN.bold)("Usage")}
349
-
350
- ${(0, import_chunk_6TE2RIPN.dim)("$")} prisma db pull [flags/options]
351
-
352
- ${(0, import_chunk_6TE2RIPN.bold)("Flags")}
353
-
354
- -h, --help Display this help message
355
- --force Ignore current Prisma schema file
356
- --print Print the introspected Prisma schema to stdout
357
-
358
- ${(0, import_chunk_6TE2RIPN.bold)("Options")}
359
-
360
- --config Custom path to your Prisma config file
361
- --schema Custom path to your Prisma schema
362
- --composite-type-depth Specify the depth for introspecting composite types (e.g. Embedded Documents in MongoDB)
363
- Number, default is -1 for infinite depth, 0 = off
364
- --schemas Specify the database schemas to introspect. This overrides the schemas defined in the datasource block of your Prisma schema.
365
- --local-d1 Generate a Prisma schema from a local Cloudflare D1 database
366
- ${(0, import_chunk_6TE2RIPN.bold)("Examples")}
367
-
368
- With an existing Prisma schema
369
- ${(0, import_chunk_6TE2RIPN.dim)("$")} prisma db pull
370
-
371
- Or specify a Prisma schema path
372
- ${(0, import_chunk_6TE2RIPN.dim)("$")} prisma db pull --schema=./schema.prisma
373
-
374
- Instead of saving the result to the filesystem, you can also print it to stdout
375
- ${(0, import_chunk_6TE2RIPN.dim)("$")} prisma db pull --print
376
-
377
- Overwrite the current schema with the introspected schema instead of enriching it
378
- ${(0, import_chunk_6TE2RIPN.dim)("$")} prisma db pull --force
379
-
380
- Set composite types introspection depth to 2 levels
381
- ${(0, import_chunk_6TE2RIPN.dim)("$")} prisma db pull --composite-type-depth=2
382
-
383
- `);
384
- DbPull = _DbPull;
385
- }
386
- });
@@ -1,165 +0,0 @@
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_2RSEPJFX_exports = {};
20
- __export(chunk_2RSEPJFX_exports, {
21
- MigrateResolve: () => MigrateResolve,
22
- init_MigrateResolve: () => init_MigrateResolve
23
- });
24
- module.exports = __toCommonJS(chunk_2RSEPJFX_exports);
25
- var import_chunk_UVNSK22K = require("./chunk-UVNSK22K.js");
26
- var import_chunk_M5YNQ2NP = require("./chunk-M5YNQ2NP.js");
27
- var import_chunk_Q7ACZDDT = require("./chunk-Q7ACZDDT.js");
28
- var import_chunk_XJQP3B4W = require("./chunk-XJQP3B4W.js");
29
- var import_chunk_6TE2RIPN = require("./chunk-6TE2RIPN.js");
30
- var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
31
- var import_internals = require("@prisma/internals");
32
- var _MigrateResolve, MigrateResolve;
33
- var init_MigrateResolve = (0, import_chunk_WWAWV7DQ.__esm)({
34
- "src/commands/MigrateResolve.ts"() {
35
- (0, import_chunk_6TE2RIPN.init_colors)();
36
- (0, import_chunk_UVNSK22K.init_Migrate)();
37
- (0, import_chunk_XJQP3B4W.init_ensureDatabaseExists)();
38
- (0, import_chunk_M5YNQ2NP.init_getSchemaPathAndPrint)();
39
- (0, import_chunk_Q7ACZDDT.init_printDatasource)();
40
- _MigrateResolve = class _MigrateResolve2 {
41
- static new() {
42
- return new _MigrateResolve2();
43
- }
44
- async parse(argv, config) {
45
- const args = (0, import_internals.arg)(
46
- argv,
47
- {
48
- "--help": Boolean,
49
- "-h": "--help",
50
- "--applied": String,
51
- "--rolled-back": String,
52
- "--schema": String,
53
- "--config": String,
54
- "--telemetry-information": String
55
- },
56
- false
57
- );
58
- if ((0, import_internals.isError)(args)) {
59
- return this.help(args.message);
60
- }
61
- await (0, import_internals.checkUnsupportedDataProxy)("migrate resolve", args, config.schema, true);
62
- if (args["--help"]) {
63
- return this.help();
64
- }
65
- await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true, config });
66
- const { schemaPath } = await (0, import_chunk_M5YNQ2NP.getSchemaPathAndPrint)(args["--schema"], config.schema);
67
- (0, import_chunk_Q7ACZDDT.printDatasource)({ datasourceInfo: await (0, import_chunk_XJQP3B4W.getDatasourceInfo)({ schemaPath }) });
68
- if (!args["--applied"] && !args["--rolled-back"]) {
69
- throw new Error(
70
- `--applied or --rolled-back must be part of the command like:
71
- ${(0, import_chunk_6TE2RIPN.bold)((0, import_chunk_6TE2RIPN.green)((0, import_internals.getCommandWithExecutor)("prisma migrate resolve --applied 20201231000000_example")))}
72
- ${(0, import_chunk_6TE2RIPN.bold)((0, import_chunk_6TE2RIPN.green)((0, import_internals.getCommandWithExecutor)("prisma migrate resolve --rolled-back 20201231000000_example")))}`
73
- );
74
- } else if (args["--applied"] && args["--rolled-back"]) {
75
- throw new Error("Pass either --applied or --rolled-back, not both.");
76
- }
77
- if (args["--applied"]) {
78
- if (typeof args["--applied"] !== "string" || args["--applied"].length === 0) {
79
- throw new Error(
80
- `--applied value must be a string like ${(0, import_chunk_6TE2RIPN.bold)(
81
- (0, import_chunk_6TE2RIPN.green)((0, import_internals.getCommandWithExecutor)("prisma migrate resolve --applied 20201231000000_example"))
82
- )}`
83
- );
84
- }
85
- await (0, import_chunk_XJQP3B4W.ensureCanConnectToDatabase)(schemaPath);
86
- const migrate = new import_chunk_UVNSK22K.Migrate(schemaPath);
87
- try {
88
- await migrate.markMigrationApplied({
89
- migrationId: args["--applied"]
90
- });
91
- } finally {
92
- migrate.stop();
93
- }
94
- process.stdout.write(`
95
- Migration ${args["--applied"]} marked as applied.
96
- `);
97
- return ``;
98
- } else {
99
- if (typeof args["--rolled-back"] !== "string" || args["--rolled-back"].length === 0) {
100
- throw new Error(
101
- `--rolled-back value must be a string like ${(0, import_chunk_6TE2RIPN.bold)(
102
- (0, import_chunk_6TE2RIPN.green)((0, import_internals.getCommandWithExecutor)("prisma migrate resolve --rolled-back 20201231000000_example"))
103
- )}`
104
- );
105
- }
106
- await (0, import_chunk_XJQP3B4W.ensureCanConnectToDatabase)(schemaPath);
107
- const migrate = new import_chunk_UVNSK22K.Migrate(schemaPath);
108
- try {
109
- await migrate.markMigrationRolledBack({
110
- migrationId: args["--rolled-back"]
111
- });
112
- } finally {
113
- migrate.stop();
114
- }
115
- process.stdout.write(`
116
- Migration ${args["--rolled-back"]} marked as rolled back.
117
- `);
118
- return ``;
119
- }
120
- }
121
- help(error) {
122
- if (error) {
123
- return new import_internals.HelpError(`
124
- ${(0, import_chunk_6TE2RIPN.bold)((0, import_chunk_6TE2RIPN.red)(`!`))} ${error}
125
- ${_MigrateResolve2.help}`);
126
- }
127
- return _MigrateResolve2.help;
128
- }
129
- };
130
- _MigrateResolve.help = (0, import_internals.format)(`
131
- Resolve issues with database migrations in deployment databases:
132
- - recover from failed migrations
133
- - baseline databases when starting to use Prisma Migrate on existing databases
134
- - reconcile hotfixes done manually on databases with your migration history
135
-
136
- Run "prisma migrate status" to identify if you need to use resolve.
137
-
138
- Read more about resolving migration history issues: ${(0, import_internals.link)("https://pris.ly/d/migrate-resolve")}
139
-
140
- ${(0, import_chunk_6TE2RIPN.bold)("Usage")}
141
-
142
- ${(0, import_chunk_6TE2RIPN.dim)("$")} prisma migrate resolve [options]
143
-
144
- ${(0, import_chunk_6TE2RIPN.bold)("Options")}
145
-
146
- -h, --help Display this help message
147
- --config Custom path to your Prisma config file
148
- --schema Custom path to your Prisma schema
149
- --applied Record a specific migration as applied
150
- --rolled-back Record a specific migration as rolled back
151
-
152
- ${(0, import_chunk_6TE2RIPN.bold)("Examples")}
153
-
154
- Update migrations table, recording a specific migration as applied
155
- ${(0, import_chunk_6TE2RIPN.dim)("$")} prisma migrate resolve --applied 20201231000000_add_users_table
156
-
157
- Update migrations table, recording a specific migration as rolled back
158
- ${(0, import_chunk_6TE2RIPN.dim)("$")} prisma migrate resolve --rolled-back 20201231000000_add_users_table
159
-
160
- Specify a schema
161
- ${(0, import_chunk_6TE2RIPN.dim)("$")} prisma migrate resolve --rolled-back 20201231000000_add_users_table --schema=./schema.prisma
162
- `);
163
- MigrateResolve = _MigrateResolve;
164
- }
165
- });