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

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-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-V5LEZ5BX.js → chunk-IIBRYI63.js} +634 -807
  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
@@ -0,0 +1,226 @@
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_4EV2RVXY_exports = {};
30
+ __export(chunk_4EV2RVXY_exports, {
31
+ DbExecute: () => DbExecute
32
+ });
33
+ module.exports = __toCommonJS(chunk_4EV2RVXY_exports);
34
+ var import_chunk_DDHPSYC4 = require("./chunk-DDHPSYC4.js");
35
+ var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
36
+ var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
37
+ var import_internals = require("@prisma/internals");
38
+ var import_fs = __toESM(require("fs"));
39
+ var import_path = __toESM(require("path"));
40
+ var require_get_stdin = (0, import_chunk_WWAWV7DQ.__commonJS)({
41
+ "../../node_modules/.pnpm/get-stdin@8.0.0/node_modules/get-stdin/index.js"(exports, module2) {
42
+ "use strict";
43
+ var { stdin } = process;
44
+ module2.exports = async () => {
45
+ let result = "";
46
+ if (stdin.isTTY) {
47
+ return result;
48
+ }
49
+ stdin.setEncoding("utf8");
50
+ for await (const chunk of stdin) {
51
+ result += chunk;
52
+ }
53
+ return result;
54
+ };
55
+ module2.exports.buffer = async () => {
56
+ const result = [];
57
+ let length = 0;
58
+ if (stdin.isTTY) {
59
+ return Buffer.concat([]);
60
+ }
61
+ for await (const chunk of stdin) {
62
+ result.push(chunk);
63
+ length += chunk.length;
64
+ }
65
+ return Buffer.concat(result, length);
66
+ };
67
+ }
68
+ });
69
+ var import_get_stdin = (0, import_chunk_WWAWV7DQ.__toESM)(require_get_stdin());
70
+ var helpOptions = (0, import_internals.format)(
71
+ `${(0, import_chunk_SKRR5WT4.bold)("Usage")}
72
+
73
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db execute [options]
74
+
75
+ ${(0, import_chunk_SKRR5WT4.bold)("Options")}
76
+
77
+ -h, --help Display this help message
78
+ --config Custom path to your Prisma config file
79
+
80
+ ${(0, import_chunk_SKRR5WT4.italic)("Datasource input, only 1 must be provided:")}
81
+ --url URL of the datasource to run the command on
82
+ --schema Path to your Prisma schema file to take the datasource URL from
83
+
84
+ ${(0, import_chunk_SKRR5WT4.italic)("Script input, only 1 must be provided:")}
85
+ --file Path to a file. The content will be sent as the script to be executed
86
+
87
+ ${(0, import_chunk_SKRR5WT4.bold)("Flags")}
88
+
89
+ --stdin Use the terminal standard input as the script to be executed`
90
+ );
91
+ var _DbExecute = class _DbExecute2 {
92
+ static new() {
93
+ return new _DbExecute2();
94
+ }
95
+ async parse(argv, config) {
96
+ const args = (0, import_internals.arg)(
97
+ argv,
98
+ {
99
+ "--help": Boolean,
100
+ "-h": "--help",
101
+ "--config": String,
102
+ "--stdin": Boolean,
103
+ "--file": String,
104
+ "--schema": String,
105
+ "--url": String,
106
+ "--telemetry-information": String
107
+ },
108
+ false
109
+ );
110
+ if ((0, import_internals.isError)(args)) {
111
+ return this.help(args.message);
112
+ }
113
+ await (0, import_internals.checkUnsupportedDataProxy)("db execute", args, config.schema, !args["--url"]);
114
+ if (args["--help"]) {
115
+ return this.help();
116
+ }
117
+ await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: false, config });
118
+ if (args["--stdin"] && args["--file"]) {
119
+ throw new Error(
120
+ `--stdin and --file cannot be used at the same time. Only 1 must be provided.
121
+ See \`${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExecutor)("prisma db execute -h"))}\``
122
+ );
123
+ } else if (!args["--stdin"] && !args["--file"]) {
124
+ throw new Error(
125
+ `Either --stdin or --file must be provided.
126
+ See \`${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExecutor)("prisma db execute -h"))}\``
127
+ );
128
+ }
129
+ if (args["--url"] && args["--schema"]) {
130
+ throw new Error(
131
+ `--url and --schema cannot be used at the same time. Only 1 must be provided.
132
+ See \`${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExecutor)("prisma db execute -h"))}\``
133
+ );
134
+ } else if (!args["--url"] && !args["--schema"]) {
135
+ throw new Error(
136
+ `Either --url or --schema must be provided.
137
+ See \`${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExecutor)("prisma db execute -h"))}\``
138
+ );
139
+ }
140
+ let script = "";
141
+ if (args["--file"]) {
142
+ try {
143
+ script = import_fs.default.readFileSync(import_path.default.resolve(args["--file"]), "utf-8");
144
+ } catch (e) {
145
+ if (e.code === "ENOENT") {
146
+ throw new Error(`Provided --file at ${args["--file"]} doesn't exist.`);
147
+ } else {
148
+ console.error(`An error occurred while reading the provided --file at ${args["--file"]}`);
149
+ throw e;
150
+ }
151
+ }
152
+ }
153
+ if (args["--stdin"]) {
154
+ script = await (0, import_get_stdin.default)();
155
+ }
156
+ let datasourceType;
157
+ if (args["--url"]) {
158
+ datasourceType = {
159
+ tag: "url",
160
+ url: args["--url"]
161
+ };
162
+ } else {
163
+ const schemaWithPath = await (0, import_internals.getSchemaWithPath)(args["--schema"], config.schema);
164
+ const engineConfig = await (0, import_internals.getConfig)({ datamodel: schemaWithPath.schemas });
165
+ datasourceType = {
166
+ tag: "schema",
167
+ ...(0, import_internals.toSchemasWithConfigDir)(schemaWithPath, engineConfig)
168
+ };
169
+ }
170
+ const migrate = new import_chunk_DDHPSYC4.Migrate();
171
+ try {
172
+ await migrate.engine.dbExecute({
173
+ script,
174
+ datasourceType
175
+ });
176
+ } finally {
177
+ migrate.stop();
178
+ }
179
+ return `Script executed successfully.`;
180
+ }
181
+ help(error) {
182
+ if (error) {
183
+ throw new import_internals.HelpError(`
184
+ ${error}
185
+
186
+ ${helpOptions}`);
187
+ }
188
+ return _DbExecute2.help;
189
+ }
190
+ };
191
+ _DbExecute.help = (0, import_internals.format)(`
192
+ ${process.platform === "win32" ? "" : "\u{1F4DD} "}Execute native commands to your database
193
+
194
+ This command takes as input a datasource, using ${(0, import_chunk_SKRR5WT4.green)(`--url`)} or ${(0, import_chunk_SKRR5WT4.green)(`--schema`)} and a script, using ${(0, import_chunk_SKRR5WT4.green)(
195
+ `--stdin`
196
+ )} or ${(0, import_chunk_SKRR5WT4.green)(`--file`)}.
197
+ The input parameters are mutually exclusive, only 1 of each (datasource & script) must be provided.
198
+
199
+ The output of the command is connector-specific, and is not meant for returning data, but only to report success or failure.
200
+
201
+ On SQL databases, this command takes as input a SQL script.
202
+ The whole script will be sent as a single command to the database.
203
+
204
+ ${(0, import_chunk_SKRR5WT4.italic)(`This command is currently not supported on MongoDB.`)}
205
+
206
+ ${helpOptions}
207
+ ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
208
+
209
+ Execute the content of a SQL script file to the datasource URL taken from the schema
210
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db execute
211
+ --file ./script.sql \\
212
+ --schema schema.prisma
213
+
214
+ Execute the SQL script from stdin to the datasource URL specified via the \`DATABASE_URL\` environment variable
215
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} echo 'TRUNCATE TABLE dev;' | \\
216
+ prisma db execute \\
217
+ --stdin \\
218
+ --url="$DATABASE_URL"
219
+
220
+ Like previous example, but exposing the datasource url credentials to your terminal history
221
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} echo 'TRUNCATE TABLE dev;' | \\
222
+ prisma db execute \\
223
+ --stdin \\
224
+ --url="mysql://root:root@localhost/mydb"
225
+ `);
226
+ var DbExecute = _DbExecute;
@@ -26,20 +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_YWWOSXMY_exports = {};
30
- __export(chunk_YWWOSXMY_exports, {
31
- getDatabaseVersionSafe: () => getDatabaseVersionSafe,
32
- init_getDatabaseVersionSafe: () => init_getDatabaseVersionSafe
29
+ var chunk_4JQIX6O7_exports = {};
30
+ __export(chunk_4JQIX6O7_exports, {
31
+ getDatabaseVersionSafe: () => getDatabaseVersionSafe
33
32
  });
34
- module.exports = __toCommonJS(chunk_YWWOSXMY_exports);
35
- var import_chunk_7S3Q4MCN = require("./chunk-7S3Q4MCN.js");
36
- var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
33
+ module.exports = __toCommonJS(chunk_4JQIX6O7_exports);
34
+ var import_chunk_ORL3LJOT = require("./chunk-ORL3LJOT.js");
37
35
  var import_debug = __toESM(require("@prisma/debug"));
36
+ var debug = (0, import_debug.default)("prisma:cli");
38
37
  async function getDatabaseVersionSafe(args) {
39
38
  let engine;
40
39
  let dbVersion;
41
40
  try {
42
- engine = new import_chunk_7S3Q4MCN.SchemaEngine({});
41
+ engine = new import_chunk_ORL3LJOT.SchemaEngine({});
43
42
  dbVersion = await engine.getDatabaseVersion(args);
44
43
  } catch (e) {
45
44
  debug(e);
@@ -50,10 +49,3 @@ async function getDatabaseVersionSafe(args) {
50
49
  }
51
50
  return dbVersion;
52
51
  }
53
- var debug;
54
- var init_getDatabaseVersionSafe = (0, import_chunk_WWAWV7DQ.__esm)({
55
- "src/utils/getDatabaseVersionSafe.ts"() {
56
- (0, import_chunk_7S3Q4MCN.init_SchemaEngine)();
57
- debug = (0, import_debug.default)("prisma:cli");
58
- }
59
- });
@@ -26,15 +26,13 @@ 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_M5YNQ2NP_exports = {};
30
- __export(chunk_M5YNQ2NP_exports, {
29
+ var chunk_6DFJIBJX_exports = {};
30
+ __export(chunk_6DFJIBJX_exports, {
31
31
  getSchemaPathAndPrint: () => getSchemaPathAndPrint,
32
- init_getSchemaPathAndPrint: () => init_getSchemaPathAndPrint,
33
32
  printSchemaLoadedMessage: () => printSchemaLoadedMessage
34
33
  });
35
- module.exports = __toCommonJS(chunk_M5YNQ2NP_exports);
36
- var import_chunk_6TE2RIPN = require("./chunk-6TE2RIPN.js");
37
- var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
34
+ module.exports = __toCommonJS(chunk_6DFJIBJX_exports);
35
+ var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
38
36
  var import_internals = require("@prisma/internals");
39
37
  var import_path = __toESM(require("path"));
40
38
  async function getSchemaPathAndPrint(schemaPathProvided, schemaPathFromConfig, options) {
@@ -43,10 +41,5 @@ async function getSchemaPathAndPrint(schemaPathProvided, schemaPathFromConfig, o
43
41
  return schemaPathResult;
44
42
  }
45
43
  function printSchemaLoadedMessage(schemaPath) {
46
- process.stdout.write((0, import_chunk_6TE2RIPN.dim)(`Prisma schema loaded from ${import_path.default.relative(process.cwd(), schemaPath)}`) + "\n");
44
+ process.stdout.write((0, import_chunk_SKRR5WT4.dim)(`Prisma schema loaded from ${import_path.default.relative(process.cwd(), schemaPath)}`) + "\n");
47
45
  }
48
- var init_getSchemaPathAndPrint = (0, import_chunk_WWAWV7DQ.__esm)({
49
- "src/utils/getSchemaPathAndPrint.ts"() {
50
- (0, import_chunk_6TE2RIPN.init_colors)();
51
- }
52
- });
@@ -16,19 +16,17 @@ 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_SGCF5OHF_exports = {};
20
- __export(chunk_SGCF5OHF_exports, {
21
- handleUnexecutableSteps: () => handleUnexecutableSteps,
22
- init_handleEvaluateDataloss: () => init_handleEvaluateDataloss
19
+ var chunk_7CQBDP4H_exports = {};
20
+ __export(chunk_7CQBDP4H_exports, {
21
+ handleUnexecutableSteps: () => handleUnexecutableSteps
23
22
  });
24
- module.exports = __toCommonJS(chunk_SGCF5OHF_exports);
25
- var import_chunk_6TE2RIPN = require("./chunk-6TE2RIPN.js");
26
- var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
23
+ module.exports = __toCommonJS(chunk_7CQBDP4H_exports);
24
+ var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
27
25
  var import_internals = require("@prisma/internals");
28
26
  function handleUnexecutableSteps(unexecutableSteps, createOnly = false) {
29
27
  if (unexecutableSteps && unexecutableSteps.length > 0) {
30
28
  const messages = [];
31
- messages.push(`${(0, import_chunk_6TE2RIPN.bold)((0, import_chunk_6TE2RIPN.red)("\n\u26A0\uFE0F We found changes that cannot be executed:\n"))}`);
29
+ messages.push(`${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)("\n\u26A0\uFE0F We found changes that cannot be executed:\n"))}`);
32
30
  for (const item of unexecutableSteps) {
33
31
  messages.push(`${` \u2022 Step ${item.stepIndex} ${item.message}`}`);
34
32
  }
@@ -49,8 +47,3 @@ Then run ${(0, import_internals.getCommandWithExecutor)("prisma migrate dev")} t
49
47
  }
50
48
  return void 0;
51
49
  }
52
- var init_handleEvaluateDataloss = (0, import_chunk_WWAWV7DQ.__esm)({
53
- "src/utils/handleEvaluateDataloss.ts"() {
54
- (0, import_chunk_6TE2RIPN.init_colors)();
55
- }
56
- });
@@ -26,13 +26,11 @@ 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_7IT2ZO3D_exports = {};
30
- __export(chunk_7IT2ZO3D_exports, {
31
- init_printIntrospectedSchema: () => init_printIntrospectedSchema,
29
+ var chunk_AHJ2N6BJ_exports = {};
30
+ __export(chunk_AHJ2N6BJ_exports, {
32
31
  printIntrospectedSchema: () => printIntrospectedSchema
33
32
  });
34
- module.exports = __toCommonJS(chunk_7IT2ZO3D_exports);
35
- var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
33
+ module.exports = __toCommonJS(chunk_AHJ2N6BJ_exports);
36
34
  var import_path = __toESM(require("path"));
37
35
  function printIntrospectedSchema(schema, out) {
38
36
  if (schema.files.length === 1) {
@@ -47,7 +45,3 @@ ${file.content}
47
45
  `);
48
46
  }
49
47
  }
50
- var init_printIntrospectedSchema = (0, import_chunk_WWAWV7DQ.__esm)({
51
- "src/utils/printIntrospectedSchema.ts"() {
52
- }
53
- });
@@ -0,0 +1,266 @@
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_C2PR6JQR_exports = {};
30
+ __export(chunk_C2PR6JQR_exports, {
31
+ DbPush: () => DbPush
32
+ });
33
+ module.exports = __toCommonJS(chunk_C2PR6JQR_exports);
34
+ var import_chunk_DDHPSYC4 = require("./chunk-DDHPSYC4.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
+ var import_internals = require("@prisma/internals");
41
+ var import_prompts = __toESM(require("prompts"));
42
+ var _DbPush = class _DbPush2 {
43
+ static new() {
44
+ return new _DbPush2();
45
+ }
46
+ async parse(argv, config) {
47
+ const args = (0, import_internals.arg)(
48
+ argv,
49
+ {
50
+ "--help": Boolean,
51
+ "-h": "--help",
52
+ "--accept-data-loss": Boolean,
53
+ "--force-reset": Boolean,
54
+ "--skip-generate": Boolean,
55
+ "--schema": String,
56
+ "--config": String,
57
+ "--telemetry-information": String
58
+ },
59
+ false
60
+ );
61
+ if ((0, import_internals.isError)(args)) {
62
+ return this.help(args.message);
63
+ }
64
+ await (0, import_internals.checkUnsupportedDataProxy)("db push", args, config.schema, true);
65
+ if (args["--help"]) {
66
+ return this.help();
67
+ }
68
+ await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true, config });
69
+ const { schemaPath } = await (0, import_chunk_6DFJIBJX.getSchemaPathAndPrint)(args["--schema"], config.schema);
70
+ const datasourceInfo = await (0, import_chunk_DJMFXNR4.getDatasourceInfo)({ schemaPath });
71
+ (0, import_chunk_QOPTDDIH.printDatasource)({ datasourceInfo });
72
+ const migrate = new import_chunk_DDHPSYC4.Migrate(schemaPath);
73
+ try {
74
+ const wasDbCreated = await (0, import_chunk_DJMFXNR4.ensureDatabaseExists)("push", schemaPath);
75
+ if (wasDbCreated) {
76
+ process.stdout.write("\n" + wasDbCreated + "\n");
77
+ }
78
+ } catch (e) {
79
+ process.stdout.write("\n");
80
+ throw e;
81
+ }
82
+ let wasDatabaseReset = false;
83
+ if (args["--force-reset"]) {
84
+ process.stdout.write("\n");
85
+ try {
86
+ await migrate.reset();
87
+ } catch (e) {
88
+ migrate.stop();
89
+ throw e;
90
+ }
91
+ let successfulResetMsg = `The ${datasourceInfo.prettyProvider} database`;
92
+ if (datasourceInfo.dbName) {
93
+ successfulResetMsg += ` "${datasourceInfo.dbName}"`;
94
+ }
95
+ const schemasLength = datasourceInfo.schemas?.length || 0;
96
+ if (datasourceInfo.schemas && schemasLength > 0) {
97
+ successfulResetMsg += ` schema${schemasLength > 1 ? "s" : ""} "${datasourceInfo.schemas.join(", ")}"`;
98
+ } else if (datasourceInfo.schema) {
99
+ successfulResetMsg += ` schema "${datasourceInfo.schema}"`;
100
+ }
101
+ if (datasourceInfo.dbLocation) {
102
+ successfulResetMsg += ` at "${datasourceInfo.dbLocation}"`;
103
+ }
104
+ successfulResetMsg += ` ${schemasLength > 1 ? "were" : "was"} successfully reset.
105
+ `;
106
+ process.stdout.write(successfulResetMsg);
107
+ wasDatabaseReset = true;
108
+ }
109
+ const before = Math.round(performance.now());
110
+ let migration;
111
+ try {
112
+ migration = await migrate.push({
113
+ force: args["--accept-data-loss"]
114
+ });
115
+ } catch (e) {
116
+ migrate.stop();
117
+ throw e;
118
+ }
119
+ if (migration.unexecutable && migration.unexecutable.length > 0) {
120
+ const messages = [];
121
+ messages.push(`${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)("\n\u26A0\uFE0F We found changes that cannot be executed:\n"))}`);
122
+ for (const item of migration.unexecutable) {
123
+ messages.push(` \u2022 ${item}`);
124
+ }
125
+ process.stdout.write("\n");
126
+ if (!(0, import_internals.canPrompt)()) {
127
+ migrate.stop();
128
+ throw new Error(`${messages.join("\n")}
129
+
130
+ Use the --force-reset flag to drop the database before push like ${(0, import_chunk_SKRR5WT4.bold)(
131
+ (0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExecutor)("prisma db push --force-reset"))
132
+ )}
133
+ ${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)("All data will be lost."))}
134
+ `);
135
+ } else {
136
+ process.stdout.write(`${messages.join("\n")}
137
+
138
+ `);
139
+ }
140
+ process.stdout.write("\n");
141
+ const confirmation = await (0, import_prompts.default)({
142
+ type: "confirm",
143
+ name: "value",
144
+ message: `To apply this change we need to reset the database, do you want to continue? ${(0, import_chunk_SKRR5WT4.red)(
145
+ "All data will be lost"
146
+ )}.`
147
+ });
148
+ if (!confirmation.value) {
149
+ process.stdout.write("Reset cancelled.\n");
150
+ migrate.stop();
151
+ process.exit(130);
152
+ }
153
+ try {
154
+ await migrate.reset();
155
+ if (datasourceInfo.dbName && datasourceInfo.dbLocation) {
156
+ process.stdout.write(
157
+ `The ${datasourceInfo.prettyProvider} database "${datasourceInfo.dbName}" from "${datasourceInfo.dbLocation}" was successfully reset.
158
+ `
159
+ );
160
+ } else {
161
+ process.stdout.write(`The ${datasourceInfo.prettyProvider} database was successfully reset.
162
+ `);
163
+ }
164
+ wasDatabaseReset = true;
165
+ await migrate.push({});
166
+ } catch (e) {
167
+ migrate.stop();
168
+ throw e;
169
+ }
170
+ }
171
+ if (migration.warnings && migration.warnings.length > 0) {
172
+ process.stdout.write((0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.yellow)(`
173
+ \u26A0\uFE0F There might be data loss when applying the changes:
174
+
175
+ `)));
176
+ for (const warning of migration.warnings) {
177
+ process.stdout.write(` \u2022 ${warning}
178
+
179
+ `);
180
+ }
181
+ process.stdout.write("\n");
182
+ if (!args["--accept-data-loss"]) {
183
+ if (!(0, import_internals.canPrompt)()) {
184
+ migrate.stop();
185
+ throw new import_chunk_3WC4XD74.DbPushIgnoreWarningsWithFlagError();
186
+ }
187
+ process.stdout.write("\n");
188
+ const confirmation = await (0, import_prompts.default)({
189
+ type: "confirm",
190
+ name: "value",
191
+ message: `Do you want to ignore the warning(s)?`
192
+ });
193
+ if (!confirmation.value) {
194
+ process.stdout.write("Push cancelled.\n");
195
+ migrate.stop();
196
+ process.exit(130);
197
+ }
198
+ try {
199
+ await migrate.push({
200
+ force: true
201
+ });
202
+ } catch (e) {
203
+ migrate.stop();
204
+ throw e;
205
+ }
206
+ }
207
+ }
208
+ migrate.stop();
209
+ if (!wasDatabaseReset && migration.warnings.length === 0 && migration.executedSteps === 0) {
210
+ process.stdout.write(`
211
+ The database is already in sync with the Prisma schema.
212
+ `);
213
+ } else {
214
+ const migrationTimeMessage = `Done in ${(0, import_internals.formatms)(Math.round(performance.now()) - before)}`;
215
+ const rocketEmoji = process.platform === "win32" ? "" : "\u{1F680} ";
216
+ const migrationSuccessStdMessage = "Your database is now in sync with your Prisma schema.";
217
+ const migrationSuccessMongoMessage = "Your database indexes are now in sync with your Prisma schema.";
218
+ const provider = (0, import_internals.protocolToConnectorType)(`${datasourceInfo.url?.split(":")[0]}:`);
219
+ process.stdout.write(
220
+ `
221
+ ${rocketEmoji}${provider === "mongodb" ? migrationSuccessMongoMessage : migrationSuccessStdMessage} ${migrationTimeMessage}
222
+ `
223
+ );
224
+ }
225
+ if (!process.env.PRISMA_MIGRATE_SKIP_GENERATE && !args["--skip-generate"]) {
226
+ await migrate.tryToRunGenerate(datasourceInfo);
227
+ }
228
+ return ``;
229
+ }
230
+ help(error) {
231
+ if (error) {
232
+ return new import_internals.HelpError(`
233
+ ${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
234
+ ${_DbPush2.help}`);
235
+ }
236
+ return _DbPush2.help;
237
+ }
238
+ };
239
+ _DbPush.help = (0, import_internals.format)(`
240
+ ${process.platform === "win32" ? "" : "\u{1F64C} "}Push the state from your Prisma schema to your database
241
+
242
+ ${(0, import_chunk_SKRR5WT4.bold)("Usage")}
243
+
244
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db push [options]
245
+
246
+ ${(0, import_chunk_SKRR5WT4.bold)("Options")}
247
+
248
+ -h, --help Display this help message
249
+ --config Custom path to your Prisma config file
250
+ --schema Custom path to your Prisma schema
251
+ --accept-data-loss Ignore data loss warnings
252
+ --force-reset Force a reset of the database before push
253
+ --skip-generate Skip triggering generators (e.g. Prisma Client)
254
+
255
+ ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
256
+
257
+ Push the Prisma schema state to the database
258
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db push
259
+
260
+ Specify a schema
261
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db push --schema=./schema.prisma
262
+
263
+ Ignore data loss warnings
264
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db push --accept-data-loss
265
+ `);
266
+ var DbPush = _DbPush;
@@ -0,0 +1,65 @@
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_CTPONE6G_exports = {};
20
+ __export(chunk_CTPONE6G_exports, {
21
+ CaptureStdout: () => CaptureStdout
22
+ });
23
+ module.exports = __toCommonJS(chunk_CTPONE6G_exports);
24
+ var CaptureStdout = class {
25
+ constructor() {
26
+ this._capturedText = [];
27
+ this._orig_stdout_write = null;
28
+ }
29
+ /**
30
+ * Starts capturing the writes to process.stdout
31
+ */
32
+ startCapture() {
33
+ this._orig_stdout_write = process.stdout.write;
34
+ process.stdout.write = this._writeCapture.bind(this);
35
+ }
36
+ /**
37
+ * Stops capturing the writes to process.stdout.
38
+ */
39
+ stopCapture() {
40
+ if (this._orig_stdout_write) {
41
+ process.stdout.write = this._orig_stdout_write;
42
+ }
43
+ }
44
+ /**
45
+ * Private method that is used as the replacement write function for process.stdout
46
+ * @param string
47
+ * @private
48
+ */
49
+ _writeCapture(string) {
50
+ this._capturedText.push(string);
51
+ }
52
+ /**
53
+ * Retrieve the text that has been captured since creation or since the last clear call
54
+ * @returns {Array} of Strings
55
+ */
56
+ getCapturedText() {
57
+ return this._capturedText;
58
+ }
59
+ /**
60
+ * Clears all of the captured text
61
+ */
62
+ clearCaptureText() {
63
+ this._capturedText = [];
64
+ }
65
+ };