@prisma/migrate 6.6.0-dev.3 → 6.6.0-dev.31

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 (108) hide show
  1. package/dist/CLI.js +3 -3
  2. package/dist/Migrate.js +8 -6
  3. package/dist/SchemaEngine.js +5 -5
  4. package/dist/bin.js +48 -47
  5. package/dist/chunk-23DZXSTI.js +62 -0
  6. package/dist/{chunk-WWAWV7DQ.js → chunk-2ESYSVXG.js} +3 -27
  7. package/dist/{chunk-LKTTJWFT.js → chunk-2R6DII47.js} +5 -5
  8. package/dist/chunk-33LPBNDX.js +1399 -0
  9. package/dist/{chunk-V3ZMNXZC.js → chunk-5LKIRKDL.js} +307 -382
  10. package/dist/chunk-5Q5BJS5B.js +889 -0
  11. package/dist/{chunk-LOGAFLCN.js → chunk-5R44VVVX.js} +29 -29
  12. package/dist/{chunk-GG54LOYV.js → chunk-63ZT25OL.js} +43 -43
  13. package/dist/{chunk-DJMFXNR4.js → chunk-74LUB4XX.js} +56 -57
  14. package/dist/{chunk-IR55GBON.js → chunk-ABQZ5J74.js} +5 -5
  15. package/dist/{chunk-RP2N6UXA.js → chunk-AI6DH66U.js} +6 -6
  16. package/dist/{chunk-KS7IEA6Z.js → chunk-AM7BRZFD.js} +48 -51
  17. package/dist/{chunk-G2XUUMKH.js → chunk-B4SUSDC2.js} +31 -39
  18. package/dist/{chunk-N4XTKFY6.js → chunk-BUAYZ4KA.js} +37 -37
  19. package/dist/{chunk-W2SZNLK4.js → chunk-EJG7GKM7.js} +37 -39
  20. package/dist/{chunk-5PSO7BDO.js → chunk-EJUXYFV3.js} +15 -15
  21. package/dist/{chunk-MATFO4ZW.js → chunk-G7PJKEOV.js} +33 -33
  22. package/dist/{chunk-ZOEKRXDP.js → chunk-GHZAN2PG.js} +21 -24
  23. package/dist/{chunk-V5TUSOJX.js → chunk-HPT54KSO.js} +44 -44
  24. package/dist/{chunk-HCBZB4XC.js → chunk-HQJ7FIWN.js} +51 -51
  25. package/dist/{chunk-MCWCB2AX.js → chunk-IINN7QUV.js} +170 -643
  26. package/dist/{chunk-CQZFVAXC.js → chunk-IRYXRMQC.js} +40 -40
  27. package/dist/{chunk-4RDVKU5F.js → chunk-KQDO26SV.js} +331 -344
  28. package/dist/{chunk-255BRND3.js → chunk-KRQEFTDT.js} +6 -6
  29. package/dist/{chunk-N3KYWSX2.js → chunk-LAEOX7QH.js} +53 -48
  30. package/dist/{chunk-VVKOFN3Y.js → chunk-LLO7YF56.js} +44 -46
  31. package/dist/{chunk-MKK3GSDF.js → chunk-MTJFLQI4.js} +5 -5
  32. package/dist/{chunk-VZ23KD5C.js → chunk-NGQA5JTN.js} +8 -10
  33. package/dist/{chunk-WI2A2TQE.js → chunk-SCH55BRJ.js} +84 -87
  34. package/dist/{chunk-EGPJABTW.js → chunk-TGV6QGEF.js} +69 -69
  35. package/dist/chunk-URKH6SE2.js +479 -0
  36. package/dist/chunk-V6PVGSDJ.js +76 -0
  37. package/dist/{chunk-DLLXDCI2.js → chunk-VAJ4VX67.js} +5 -6
  38. package/dist/{chunk-OWIFBVPC.js → chunk-WJ6HO7L7.js} +330 -343
  39. package/dist/{chunk-OCQGHQED.js → chunk-YBX7R3MT.js} +12 -12
  40. package/dist/{chunk-A6PMXMMT.js → chunk-ZB5NPOJW.js} +13 -13
  41. package/dist/{chunk-Q3ZLC44N.js → chunk-ZCR4PTT3.js} +54 -64
  42. package/dist/commands/DbCommand.js +3 -3
  43. package/dist/commands/DbDrop.js +4 -5
  44. package/dist/commands/DbExecute.js +9 -7
  45. package/dist/commands/DbPull.js +12 -11
  46. package/dist/commands/DbPush.js +10 -9
  47. package/dist/commands/DbSeed.js +4 -5
  48. package/dist/commands/MigrateCommand.js +3 -3
  49. package/dist/commands/MigrateDeploy.js +12 -11
  50. package/dist/commands/MigrateDev.js +14 -13
  51. package/dist/commands/MigrateDiff.js +12 -10
  52. package/dist/commands/MigrateReset.js +13 -12
  53. package/dist/commands/MigrateResolve.js +10 -9
  54. package/dist/commands/MigrateStatus.js +10 -9
  55. package/dist/index.js +52 -50
  56. package/dist/internals/src/cli/schemaContext.d.ts +43 -0
  57. package/dist/internals/src/index.d.ts +1 -0
  58. package/dist/internals/src/migrateTypes.d.ts +63 -0
  59. package/dist/migrate/src/Migrate.d.ts +3 -1
  60. package/dist/migrate/src/SchemaEngine.d.ts +0 -4
  61. package/dist/migrate/src/types.d.ts +13 -10
  62. package/dist/migrate/src/utils/createMigration.d.ts +21 -0
  63. package/dist/migrate/src/utils/ensureDatabaseExists.d.ts +4 -6
  64. package/dist/migrate/src/utils/listMigrations.d.ts +9 -0
  65. package/dist/migrate/src/utils/seed.d.ts +0 -2
  66. package/dist/{multipart-parser-54WEFGGN-NLZG56KM.js → multipart-parser-ASKQAOL4-WZ47HU6G.js} +92 -125
  67. package/dist/{multipart-parser-NDLECNMN.js → multipart-parser-QCI3Y5IB.js} +66 -68
  68. package/dist/types.js +1 -1
  69. package/dist/{typescript-WN4QH2CP.js → typescript-2LKASCMC.js} +33 -33
  70. package/dist/{typescript-AILDXN3I.js → typescript-H3AVJ6KX.js} +32 -32
  71. package/dist/utils/byline.js +1 -1
  72. package/dist/utils/captureStdout.js +3 -3
  73. package/dist/utils/countModelsAndTypes.js +1 -1
  74. package/dist/utils/createMigration.js +27 -0
  75. package/dist/utils/customColors.js +1 -1
  76. package/dist/utils/ensureDatabaseExists.js +7 -7
  77. package/dist/utils/errors.js +1 -1
  78. package/dist/utils/flagErrors.js +1 -1
  79. package/dist/utils/getDatabaseVersionSafe.js +5 -5
  80. package/dist/utils/getSchemaPathAndPrint.js +1 -1
  81. package/dist/utils/handleEvaluateDataloss.js +1 -1
  82. package/dist/utils/introspectSql.js +5 -5
  83. package/dist/utils/isSchemaEmpty.js +1 -1
  84. package/dist/utils/listMigrations.js +25 -0
  85. package/dist/utils/now.js +1 -1
  86. package/dist/utils/printDatasource.js +1 -1
  87. package/dist/utils/printDatasources.js +5 -5
  88. package/dist/utils/printFiles.js +5 -5
  89. package/dist/utils/printIntrospectedSchema.js +1 -1
  90. package/dist/utils/printMigrationId.js +1 -1
  91. package/dist/utils/promptForMigrationName.js +3 -3
  92. package/dist/utils/removeSchemaFiles.js +1 -1
  93. package/dist/utils/replaceOrAddDatasource.js +1 -1
  94. package/dist/utils/replaceOrAddDatasource.test.js +1 -1
  95. package/dist/utils/saveSchemaFiles.js +1 -1
  96. package/dist/utils/seed.js +4 -7
  97. package/dist/utils/setupCockroach.js +3 -3
  98. package/dist/utils/setupMSSQL.js +759 -675
  99. package/dist/utils/setupMongo.js +552 -552
  100. package/dist/utils/setupMysql.js +508 -563
  101. package/dist/utils/setupPostgres.js +3 -3
  102. package/dist/utils/spinner.js +4 -3
  103. package/dist/utils/unixSocket.js +1 -1
  104. package/dist/views/handleViewsIO.js +3 -3
  105. package/package.json +9 -9
  106. package/dist/chunk-J46BJQHT.js +0 -268
  107. package/dist/chunk-KOF4LGTS.js +0 -1817
  108. package/dist/chunk-YYPMC5FN.js +0 -1407
@@ -16,16 +16,16 @@ 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_255BRND3_exports = {};
20
- __export(chunk_255BRND3_exports, {
19
+ var chunk_KRQEFTDT_exports = {};
20
+ __export(chunk_KRQEFTDT_exports, {
21
21
  printFiles: () => printFiles,
22
22
  printFilesFromMigrationIds: () => printFilesFromMigrationIds
23
23
  });
24
- module.exports = __toCommonJS(chunk_255BRND3_exports);
24
+ module.exports = __toCommonJS(chunk_KRQEFTDT_exports);
25
25
  var import_chunk_UP6FVCDK = require("./chunk-UP6FVCDK.js");
26
- var import_chunk_LKTTJWFT = require("./chunk-LKTTJWFT.js");
27
- var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
28
- var import_indent_string = (0, import_chunk_WWAWV7DQ.__toESM)((0, import_chunk_LKTTJWFT.require_indent_string)());
26
+ var import_chunk_2R6DII47 = require("./chunk-2R6DII47.js");
27
+ var import_chunk_2ESYSVXG = require("./chunk-2ESYSVXG.js");
28
+ var import_indent_string = (0, import_chunk_2ESYSVXG.__toESM)((0, import_chunk_2R6DII47.require_indent_string)());
29
29
  function printFiles(printPath, files) {
30
30
  const fileNames = Object.keys(files);
31
31
  const folders = printPath.split("/");
@@ -26,14 +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_N3KYWSX2_exports = {};
30
- __export(chunk_N3KYWSX2_exports, {
29
+ var chunk_LAEOX7QH_exports = {};
30
+ __export(chunk_LAEOX7QH_exports, {
31
31
  DbExecute: () => DbExecute
32
32
  });
33
- module.exports = __toCommonJS(chunk_N3KYWSX2_exports);
34
- var import_chunk_KOF4LGTS = require("./chunk-KOF4LGTS.js");
33
+ module.exports = __toCommonJS(chunk_LAEOX7QH_exports);
34
+ var import_chunk_5Q5BJS5B = require("./chunk-5Q5BJS5B.js");
35
35
  var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
36
- var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
37
36
  var import_internals = require("@prisma/internals");
38
37
  var import_fs = __toESM(require("fs"));
39
38
  var import_path = __toESM(require("path"));
@@ -82,10 +81,48 @@ ${(0, import_chunk_SKRR5WT4.bold)("Flags")}
82
81
 
83
82
  --stdin Use the terminal standard input as the script to be executed`
84
83
  );
85
- var _DbExecute = class _DbExecute2 {
84
+ var DbExecute = class _DbExecute {
86
85
  static new() {
87
- return new _DbExecute2();
86
+ return new _DbExecute();
88
87
  }
88
+ // TODO: This command needs to get proper support for `prisma.config.ts` eventually. Not just taking the schema path
89
+ // from prisma.config.ts but likely to support driver adapters, too?
90
+ // See https://linear.app/prisma-company/issue/ORM-639/prisma-db-execute-support-prismaconfigts-and-driver-adapters
91
+ static help = (0, import_internals.format)(`
92
+ ${process.platform === "win32" ? "" : "\u{1F4DD} "}Execute native commands to your database
93
+
94
+ 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)(
95
+ `--stdin`
96
+ )} or ${(0, import_chunk_SKRR5WT4.green)(`--file`)}.
97
+ The input parameters are mutually exclusive, only 1 of each (datasource & script) must be provided.
98
+
99
+ The output of the command is connector-specific, and is not meant for returning data, but only to report success or failure.
100
+
101
+ On SQL databases, this command takes as input a SQL script.
102
+ The whole script will be sent as a single command to the database.
103
+
104
+ ${(0, import_chunk_SKRR5WT4.italic)(`This command is currently not supported on MongoDB.`)}
105
+
106
+ ${helpOptions}
107
+ ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
108
+
109
+ Execute the content of a SQL script file to the datasource URL taken from the schema
110
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db execute
111
+ --file ./script.sql \\
112
+ --schema schema.prisma
113
+
114
+ Execute the SQL script from stdin to the datasource URL specified via the \`DATABASE_URL\` environment variable
115
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} echo 'TRUNCATE TABLE dev;' | \\
116
+ prisma db execute \\
117
+ --stdin \\
118
+ --url="$DATABASE_URL"
119
+
120
+ Like previous example, but exposing the datasource url credentials to your terminal history
121
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} echo 'TRUNCATE TABLE dev;' | \\
122
+ prisma db execute \\
123
+ --stdin \\
124
+ --url="mysql://root:root@localhost/mydb"
125
+ `);
89
126
  async parse(argv, config) {
90
127
  const args = (0, import_internals.arg)(
91
128
  argv,
@@ -154,14 +191,18 @@ See \`${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExec
154
191
  url: args["--url"]
155
192
  };
156
193
  } else {
157
- const schemaWithPath = await (0, import_internals.getSchemaWithPath)(args["--schema"], config.schema);
158
- const engineConfig = await (0, import_internals.getConfig)({ datamodel: schemaWithPath.schemas });
194
+ const schemaContext = await (0, import_internals.loadSchemaContext)({
195
+ schemaPathFromArg: args["--schema"],
196
+ schemaPathFromConfig: config.schema,
197
+ printLoadMessage: false
198
+ });
159
199
  datasourceType = {
160
200
  tag: "schema",
161
- ...(0, import_internals.toSchemasWithConfigDir)(schemaWithPath, engineConfig)
201
+ ...(0, import_internals.toSchemasContainer)(schemaContext.schemaFiles),
202
+ configDir: schemaContext.primaryDatasourceDirectory
162
203
  };
163
204
  }
164
- const migrate = new import_chunk_KOF4LGTS.Migrate();
205
+ const migrate = new import_chunk_5Q5BJS5B.Migrate();
165
206
  try {
166
207
  await migrate.engine.dbExecute({
167
208
  script,
@@ -179,42 +220,6 @@ ${error}
179
220
 
180
221
  ${helpOptions}`);
181
222
  }
182
- return _DbExecute2.help;
223
+ return _DbExecute.help;
183
224
  }
184
225
  };
185
- (0, import_chunk_WWAWV7DQ.__publicField)(_DbExecute, "help", (0, import_internals.format)(`
186
- ${process.platform === "win32" ? "" : "\u{1F4DD} "}Execute native commands to your database
187
-
188
- 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)(
189
- `--stdin`
190
- )} or ${(0, import_chunk_SKRR5WT4.green)(`--file`)}.
191
- The input parameters are mutually exclusive, only 1 of each (datasource & script) must be provided.
192
-
193
- The output of the command is connector-specific, and is not meant for returning data, but only to report success or failure.
194
-
195
- On SQL databases, this command takes as input a SQL script.
196
- The whole script will be sent as a single command to the database.
197
-
198
- ${(0, import_chunk_SKRR5WT4.italic)(`This command is currently not supported on MongoDB.`)}
199
-
200
- ${helpOptions}
201
- ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
202
-
203
- Execute the content of a SQL script file to the datasource URL taken from the schema
204
- ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db execute
205
- --file ./script.sql \\
206
- --schema schema.prisma
207
-
208
- Execute the SQL script from stdin to the datasource URL specified via the \`DATABASE_URL\` environment variable
209
- ${(0, import_chunk_SKRR5WT4.dim)("$")} echo 'TRUNCATE TABLE dev;' | \\
210
- prisma db execute \\
211
- --stdin \\
212
- --url="$DATABASE_URL"
213
-
214
- Like previous example, but exposing the datasource url credentials to your terminal history
215
- ${(0, import_chunk_SKRR5WT4.dim)("$")} echo 'TRUNCATE TABLE dev;' | \\
216
- prisma db execute \\
217
- --stdin \\
218
- --url="mysql://root:root@localhost/mydb"
219
- `));
220
- var DbExecute = _DbExecute;
@@ -16,59 +16,21 @@ 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_VVKOFN3Y_exports = {};
20
- __export(chunk_VVKOFN3Y_exports, {
19
+ var chunk_LLO7YF56_exports = {};
20
+ __export(chunk_LLO7YF56_exports, {
21
21
  MigrateCommand: () => MigrateCommand
22
22
  });
23
- module.exports = __toCommonJS(chunk_VVKOFN3Y_exports);
23
+ module.exports = __toCommonJS(chunk_LLO7YF56_exports);
24
24
  var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
25
- var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
26
25
  var import_internals = require("@prisma/internals");
27
- var _MigrateCommand = class _MigrateCommand2 {
26
+ var MigrateCommand = class _MigrateCommand {
28
27
  constructor(cmds) {
29
28
  this.cmds = cmds;
30
29
  }
31
30
  static new(cmds) {
32
- return new _MigrateCommand2(cmds);
31
+ return new _MigrateCommand(cmds);
33
32
  }
34
- async parse(argv, config) {
35
- const args = (0, import_internals.arg)(argv, {
36
- "--help": Boolean,
37
- "-h": "--help",
38
- "--config": String,
39
- "--preview-feature": Boolean,
40
- "--telemetry-information": String
41
- });
42
- if ((0, import_internals.isError)(args)) {
43
- return this.help(args.message);
44
- }
45
- if (args._.length === 0 || args["--help"]) {
46
- return this.help();
47
- }
48
- const commandName = args._[0];
49
- const cmd = this.cmds[commandName];
50
- if (cmd) {
51
- let argsForCmd;
52
- if (commandName === "diff") {
53
- argsForCmd = args["--preview-feature"] ? [...args._.slice(1), `--preview-feature`] : args._.slice(1);
54
- } else {
55
- const filteredArgs = args._.filter((item) => item !== "--preview-feature");
56
- argsForCmd = filteredArgs.slice(1);
57
- }
58
- return cmd.parse(argsForCmd, config);
59
- }
60
- return (0, import_internals.unknownCommand)(_MigrateCommand2.help, commandName);
61
- }
62
- help(error) {
63
- if (error) {
64
- return new import_internals.HelpError(`
65
- ${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
66
- ${_MigrateCommand2.help}`);
67
- }
68
- return _MigrateCommand2.help;
69
- }
70
- };
71
- (0, import_chunk_WWAWV7DQ.__publicField)(_MigrateCommand, "help", (0, import_internals.format)(`
33
+ static help = (0, import_internals.format)(`
72
34
  Update the database schema with migrations
73
35
 
74
36
  ${(0, import_chunk_SKRR5WT4.bold)("Usage")}
@@ -119,5 +81,41 @@ ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
119
81
  --from-url "$DATABASE_URL" \\
120
82
  --to-url "postgresql://login:password@localhost:5432/db" \\
121
83
  --script
122
- `));
123
- var MigrateCommand = _MigrateCommand;
84
+ `);
85
+ async parse(argv, config) {
86
+ const args = (0, import_internals.arg)(argv, {
87
+ "--help": Boolean,
88
+ "-h": "--help",
89
+ "--config": String,
90
+ "--preview-feature": Boolean,
91
+ "--telemetry-information": String
92
+ });
93
+ if ((0, import_internals.isError)(args)) {
94
+ return this.help(args.message);
95
+ }
96
+ if (args._.length === 0 || args["--help"]) {
97
+ return this.help();
98
+ }
99
+ const commandName = args._[0];
100
+ const cmd = this.cmds[commandName];
101
+ if (cmd) {
102
+ let argsForCmd;
103
+ if (commandName === "diff") {
104
+ argsForCmd = args["--preview-feature"] ? [...args._.slice(1), `--preview-feature`] : args._.slice(1);
105
+ } else {
106
+ const filteredArgs = args._.filter((item) => item !== "--preview-feature");
107
+ argsForCmd = filteredArgs.slice(1);
108
+ }
109
+ return cmd.parse(argsForCmd, config);
110
+ }
111
+ return (0, import_internals.unknownCommand)(_MigrateCommand.help, commandName);
112
+ }
113
+ help(error) {
114
+ if (error) {
115
+ return new import_internals.HelpError(`
116
+ ${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
117
+ ${_MigrateCommand.help}`);
118
+ }
119
+ return _MigrateCommand.help;
120
+ }
121
+ };
@@ -26,19 +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_MKK3GSDF_exports = {};
30
- __export(chunk_MKK3GSDF_exports, {
29
+ var chunk_MTJFLQI4_exports = {};
30
+ __export(chunk_MTJFLQI4_exports, {
31
31
  getDatabaseVersionSafe: () => getDatabaseVersionSafe
32
32
  });
33
- module.exports = __toCommonJS(chunk_MKK3GSDF_exports);
34
- var import_chunk_ZOEKRXDP = require("./chunk-ZOEKRXDP.js");
33
+ module.exports = __toCommonJS(chunk_MTJFLQI4_exports);
34
+ var import_chunk_GHZAN2PG = require("./chunk-GHZAN2PG.js");
35
35
  var import_debug = __toESM(require("@prisma/debug"));
36
36
  var debug = (0, import_debug.default)("prisma:cli");
37
37
  async function getDatabaseVersionSafe(args) {
38
38
  let engine;
39
39
  let dbVersion;
40
40
  try {
41
- engine = new import_chunk_ZOEKRXDP.SchemaEngine({});
41
+ engine = new import_chunk_GHZAN2PG.SchemaEngine({});
42
42
  dbVersion = await engine.getDatabaseVersion(args);
43
43
  } catch (e) {
44
44
  debug(e);
@@ -16,20 +16,19 @@ 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_VZ23KD5C_exports = {};
20
- __export(chunk_VZ23KD5C_exports, {
19
+ var chunk_NGQA5JTN_exports = {};
20
+ __export(chunk_NGQA5JTN_exports, {
21
21
  CLI: () => CLI
22
22
  });
23
- module.exports = __toCommonJS(chunk_VZ23KD5C_exports);
23
+ module.exports = __toCommonJS(chunk_NGQA5JTN_exports);
24
24
  var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
25
- var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
26
25
  var import_internals = require("@prisma/internals");
27
- var _CLI = class _CLI2 {
26
+ var CLI = class _CLI {
28
27
  constructor(cmds) {
29
28
  this.cmds = cmds;
30
29
  }
31
30
  static new(cmds) {
32
- return new _CLI2(cmds);
31
+ return new _CLI(cmds);
33
32
  }
34
33
  async parse(argv, config) {
35
34
  const args = (0, import_internals.arg)(argv, {
@@ -70,10 +69,9 @@ var _CLI = class _CLI2 {
70
69
  if (error) {
71
70
  return new import_internals.HelpError(`
72
71
  ${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
73
- ${_CLI2.help}`);
72
+ ${_CLI.help}`);
74
73
  }
75
- return _CLI2.help;
74
+ return _CLI.help;
76
75
  }
76
+ static help = (0, import_internals.format)(`This is the internal CLI for @prisma/migrate`);
77
77
  };
78
- (0, import_chunk_WWAWV7DQ.__publicField)(_CLI, "help", (0, import_internals.format)(`This is the internal CLI for @prisma/migrate`));
79
- var CLI = _CLI;
@@ -26,37 +26,75 @@ 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_WI2A2TQE_exports = {};
30
- __export(chunk_WI2A2TQE_exports, {
29
+ var chunk_SCH55BRJ_exports = {};
30
+ __export(chunk_SCH55BRJ_exports, {
31
31
  DbPull: () => DbPull
32
32
  });
33
- module.exports = __toCommonJS(chunk_WI2A2TQE_exports);
34
- var import_chunk_MCWCB2AX = require("./chunk-MCWCB2AX.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");
33
+ module.exports = __toCommonJS(chunk_SCH55BRJ_exports);
34
+ var import_chunk_IINN7QUV = require("./chunk-IINN7QUV.js");
38
35
  var import_chunk_JZ75RIMZ = require("./chunk-JZ75RIMZ.js");
39
36
  var import_chunk_RR6BKMNO = require("./chunk-RR6BKMNO.js");
37
+ var import_chunk_RTGQXNX6 = require("./chunk-RTGQXNX6.js");
38
+ var import_chunk_AI6DH66U = require("./chunk-AI6DH66U.js");
39
+ var import_chunk_AHJ2N6BJ = require("./chunk-AHJ2N6BJ.js");
40
40
  var import_chunk_JFKDSUIE = require("./chunk-JFKDSUIE.js");
41
41
  var import_chunk_LGYRZ6CV = require("./chunk-LGYRZ6CV.js");
42
- var import_chunk_ZOEKRXDP = require("./chunk-ZOEKRXDP.js");
43
- var import_chunk_MATFO4ZW = require("./chunk-MATFO4ZW.js");
42
+ var import_chunk_GHZAN2PG = require("./chunk-GHZAN2PG.js");
43
+ var import_chunk_G7PJKEOV = require("./chunk-G7PJKEOV.js");
44
44
  var import_chunk_3WC4XD74 = require("./chunk-3WC4XD74.js");
45
45
  var import_chunk_QOPTDDIH = require("./chunk-QOPTDDIH.js");
46
- var import_chunk_DJMFXNR4 = require("./chunk-DJMFXNR4.js");
46
+ var import_chunk_74LUB4XX = require("./chunk-74LUB4XX.js");
47
47
  var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
48
- var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
49
48
  var import_debug = __toESM(require("@prisma/debug"));
50
49
  var import_internals = require("@prisma/internals");
51
50
  var import_path = __toESM(require("path"));
52
51
  var debug = (0, import_debug.default)("prisma:db:pull");
53
- var _DbPull = class _DbPull2 {
52
+ var DbPull = class _DbPull {
54
53
  static new() {
55
- return new _DbPull2();
54
+ return new _DbPull();
56
55
  }
56
+ static help = (0, import_internals.format)(`
57
+ Pull the state from the database to the Prisma schema using introspection
58
+
59
+ ${(0, import_chunk_SKRR5WT4.bold)("Usage")}
60
+
61
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull [flags/options]
62
+
63
+ ${(0, import_chunk_SKRR5WT4.bold)("Flags")}
64
+
65
+ -h, --help Display this help message
66
+ --force Ignore current Prisma schema file
67
+ --print Print the introspected Prisma schema to stdout
68
+
69
+ ${(0, import_chunk_SKRR5WT4.bold)("Options")}
70
+
71
+ --config Custom path to your Prisma config file
72
+ --schema Custom path to your Prisma schema
73
+ --composite-type-depth Specify the depth for introspecting composite types (e.g. Embedded Documents in MongoDB)
74
+ Number, default is -1 for infinite depth, 0 = off
75
+ --schemas Specify the database schemas to introspect. This overrides the schemas defined in the datasource block of your Prisma schema.
76
+ --local-d1 Generate a Prisma schema from a local Cloudflare D1 database
77
+ ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
78
+
79
+ With an existing Prisma schema
80
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull
81
+
82
+ Or specify a Prisma schema path
83
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --schema=./schema.prisma
84
+
85
+ Instead of saving the result to the filesystem, you can also print it to stdout
86
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --print
87
+
88
+ Overwrite the current schema with the introspected schema instead of enriching it
89
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --force
90
+
91
+ Set composite types introspection depth to 2 levels
92
+ ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --composite-type-depth=2
93
+
94
+ `);
57
95
  urlToDatasource(url, defaultProvider) {
58
96
  const provider = defaultProvider || (0, import_internals.protocolToConnectorType)(`${url.split(":")[0]}:`);
59
- return (0, import_chunk_RP2N6UXA.printDatasources)([
97
+ return (0, import_chunk_AI6DH66U.printDatasources)([
60
98
  {
61
99
  config: {},
62
100
  provider,
@@ -80,7 +118,7 @@ var _DbPull = class _DbPull2 {
80
118
  "--local-d1": Boolean
81
119
  // optional, only on cloudflare D1
82
120
  });
83
- const spinnerFactory = (0, import_chunk_MCWCB2AX.createSpinner)(!args["--print"]);
121
+ const spinnerFactory = (0, import_chunk_IINN7QUV.createSpinner)(!args["--print"]);
84
122
  if (args instanceof Error) {
85
123
  return this.help(args.message);
86
124
  }
@@ -89,38 +127,38 @@ var _DbPull = class _DbPull2 {
89
127
  return this.help();
90
128
  }
91
129
  const url = args["--url"];
92
- const schemaPathResult = await (0, import_internals.getSchemaWithPathOptional)(args["--schema"], config.schema);
93
- let schemaPath = schemaPathResult?.schemaPath ?? null;
94
- const rootDir = schemaPathResult?.schemaRootDir ?? process.cwd();
95
- debug("schemaPathResult", schemaPathResult);
96
- if (schemaPath && !args["--print"]) {
97
- process.stdout.write((0, import_chunk_SKRR5WT4.dim)(`Prisma schema loaded from ${import_path.default.relative(process.cwd(), schemaPath)}`) + "\n");
130
+ const schemaContext = await (0, import_internals.loadSchemaContext)({
131
+ schemaPathFromArg: args["--schema"],
132
+ schemaPathFromConfig: config.schema,
133
+ printLoadMessage: false,
134
+ allowNull: true
135
+ });
136
+ if (schemaContext && !args["--print"]) {
137
+ process.stdout.write((0, import_chunk_SKRR5WT4.dim)(`Prisma schema loaded from ${schemaContext.loadedFromPathForLogMessages}`) + "\n");
98
138
  await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true, config });
99
- (0, import_chunk_QOPTDDIH.printDatasource)({ datasourceInfo: await (0, import_chunk_DJMFXNR4.getDatasourceInfo)({ schemaPath }) });
139
+ (0, import_chunk_QOPTDDIH.printDatasource)({ datasourceInfo: (0, import_chunk_74LUB4XX.parseDatasourceInfo)(schemaContext?.primaryDatasource) });
100
140
  } else {
101
141
  await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: false, config });
102
142
  }
103
143
  const fromD1 = Boolean(args["--local-d1"]);
104
- if (!url && !schemaPath && !fromD1) {
144
+ if (!url && !schemaContext && !fromD1) {
105
145
  throw new import_chunk_3WC4XD74.NoSchemaFoundError();
106
146
  }
107
- const { firstDatasource, schema, validationWarning } = await (0, import_chunk_MATFO4ZW.z)({ url, schemaPath, fromD1 }).when(
108
- (input) => input.schemaPath !== null,
147
+ const { firstDatasource, schema, validationWarning } = await (0, import_chunk_G7PJKEOV.z)({ url, schemaContext, fromD1 }).when(
148
+ (input) => input.schemaContext !== null,
109
149
  async (input) => {
110
- const rawSchema = await (0, import_internals.getSchema)(input.schemaPath, config.schema);
111
- const engineConfig = await (0, import_internals.getConfig)({
112
- datamodel: rawSchema,
113
- ignoreEnvVarErrors: true
114
- });
115
- const previewFeatures = engineConfig.generators.find(({ name }) => name === "client")?.previewFeatures;
116
- const firstDatasource2 = engineConfig.datasources[0] ? engineConfig.datasources[0] : void 0;
150
+ const previewFeatures = input.schemaContext.generators.find(({ name }) => name === "client")?.previewFeatures;
151
+ const firstDatasource2 = input.schemaContext.primaryDatasource ? input.schemaContext.primaryDatasource : void 0;
117
152
  if (input.url) {
118
153
  let providerFromSchema = firstDatasource2?.provider;
119
154
  if (providerFromSchema === "postgres") {
120
155
  providerFromSchema = "postgresql";
121
156
  }
122
157
  const providerFromUrl = (0, import_internals.protocolToConnectorType)(`${input.url.split(":")[0]}:`);
123
- const schema2 = (0, import_chunk_RR6BKMNO.replaceOrAddDatasource)(this.urlToDatasource(input.url, providerFromSchema), rawSchema);
158
+ const schema2 = (0, import_chunk_RR6BKMNO.replaceOrAddDatasource)(
159
+ this.urlToDatasource(input.url, providerFromSchema),
160
+ input.schemaContext.schemaFiles
161
+ );
124
162
  if (providerFromSchema && providerFromUrl && providerFromSchema !== providerFromUrl && Boolean(providerFromSchema === "cockroachdb" && providerFromUrl === "postgresql") === false) {
125
163
  throw new Error(
126
164
  `The database provider found in --url (${providerFromUrl}) is different from the provider found in the Prisma schema (${providerFromSchema}).`
@@ -129,7 +167,7 @@ var _DbPull = class _DbPull2 {
129
167
  return { firstDatasource: firstDatasource2, schema: schema2, validationWarning: void 0 };
130
168
  } else if (input.fromD1) {
131
169
  const d1Database = await (0, import_internals.locateLocalCloudflareD1)({ arg: "--from-local-d1" });
132
- const pathToSQLiteFile = import_path.default.relative(import_path.default.dirname(input.schemaPath), d1Database);
170
+ const pathToSQLiteFile = import_path.default.relative(input.schemaContext.schemaRootDir, d1Database);
133
171
  const schema2 = [
134
172
  ["schema.prisma", this.urlToDatasource(`file:${pathToSQLiteFile}`, "sqlite")]
135
173
  ];
@@ -151,11 +189,11 @@ var _DbPull = class _DbPull2 {
151
189
  }
152
190
  } else {
153
191
  await (0, import_internals.getConfig)({
154
- datamodel: rawSchema,
192
+ datamodel: input.schemaContext.schemaFiles,
155
193
  ignoreEnvVarErrors: false
156
194
  });
157
195
  }
158
- return { firstDatasource: firstDatasource2, schema: rawSchema, validationWarning: void 0 };
196
+ return { firstDatasource: firstDatasource2, schema: input.schemaContext.schemaFiles, validationWarning: void 0 };
159
197
  }
160
198
  ).when(
161
199
  (input) => input.fromD1 === true,
@@ -186,10 +224,9 @@ ${this.urlToDatasource(`file:${pathToSQLiteFile}`, "sqlite")}`;
186
224
  return { firstDatasource: config2.datasources[0], schema: schema2, validationWarning: void 0 };
187
225
  }
188
226
  ).run();
189
- if (schemaPath) {
190
- const schemas = await (0, import_internals.getSchema)(args["--schema"], config.schema);
227
+ if (schemaContext) {
191
228
  const modelRegex = /\s*model\s*(\w+)\s*{/;
192
- const isReintrospection = schemas.some(([_, schema2]) => !!modelRegex.exec(schema2));
229
+ const isReintrospection = schemaContext.schemaFiles.some(([_, schema2]) => !!modelRegex.exec(schema2));
193
230
  if (isReintrospection && !args["--force"] && firstDatasource?.provider === "mongodb") {
194
231
  throw new Error(`Iterating on one schema using re-introspection with db pull is currently not supported with MongoDB provider.
195
232
  You can explicitly ignore and override your current local schema file with ${(0, import_chunk_SKRR5WT4.green)(
@@ -200,10 +237,10 @@ Some information will be lost (relations, comments, mapped fields, @ignore...),
200
237
  )} for more info.`);
201
238
  }
202
239
  }
203
- const engine = new import_chunk_ZOEKRXDP.SchemaEngine({
204
- schemaPath: schemaPath ?? void 0
240
+ const engine = new import_chunk_GHZAN2PG.SchemaEngine({
241
+ schemaPath: schemaContext?.schemaPath ?? void 0
205
242
  });
206
- const basedOn = !args["--url"] && schemaPath ? ` based on datasource defined in ${(0, import_chunk_SKRR5WT4.underline)(import_path.default.relative(process.cwd(), schemaPath))}` : "";
243
+ const basedOn = !args["--url"] && schemaContext?.primaryDatasource ? ` based on datasource defined in ${(0, import_chunk_SKRR5WT4.underline)(schemaContext.loadedFromPathForLogMessages)}` : "";
207
244
  const introspectionSpinner = spinnerFactory(`Introspecting${basedOn}`);
208
245
  const before = Math.round(performance.now());
209
246
  let introspectionSchema = void 0;
@@ -211,7 +248,7 @@ Some information will be lost (relations, comments, mapped fields, @ignore...),
211
248
  try {
212
249
  const introspectionResult = await engine.introspect({
213
250
  schema: (0, import_internals.toSchemasContainer)(schema),
214
- baseDirectoryPath: rootDir,
251
+ baseDirectoryPath: schemaContext?.schemaRootDir ?? process.cwd(),
215
252
  force: args["--force"],
216
253
  compositeTypeDepth: args["--composite-type-depth"],
217
254
  namespaces: args["--schemas"]?.split(",")
@@ -283,7 +320,6 @@ Or run this command with the ${(0, import_chunk_SKRR5WT4.green)(
283
320
  console.error(introspectionWarningsMessage.replace(/(\n)/gm, "\n// "));
284
321
  }
285
322
  } else {
286
- schemaPath = schemaPath || "schema.prisma";
287
323
  if (args["--force"]) {
288
324
  await (0, import_chunk_JZ75RIMZ.removeSchemaFiles)(schema);
289
325
  }
@@ -300,8 +336,9 @@ Or run this command with the ${(0, import_chunk_SKRR5WT4.green)(
300
336
  const modelsAndTypesCountMessage = modelsCount + typesCount > 1 ? `${modelsAndTypesMessage} and wrote them` : `${modelsAndTypesMessage} and wrote it`;
301
337
  const renderValidationWarning = validationWarning ? `
302
338
  ${(0, import_chunk_SKRR5WT4.yellow)(validationWarning)}` : "";
339
+ const introspectedSchemaPath = schemaContext?.loadedFromPathForLogMessages || introspectionSchema.files[0].path;
303
340
  introspectionSpinner.success(`Introspected ${modelsAndTypesCountMessage} into ${(0, import_chunk_SKRR5WT4.underline)(
304
- import_path.default.relative(process.cwd(), schemaPath)
341
+ import_path.default.relative(process.cwd(), introspectedSchemaPath)
305
342
  )} in ${(0, import_chunk_SKRR5WT4.bold)((0, import_internals.formatms)(Math.round(performance.now()) - before))}
306
343
  ${(0, import_chunk_SKRR5WT4.yellow)(introspectionWarningsMessage)}
307
344
  ${`Run ${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExecutor)("prisma generate"))} to generate Prisma Client.`}${renderValidationWarning}`);
@@ -319,48 +356,8 @@ ${warnings}`;
319
356
  if (error) {
320
357
  return new import_internals.HelpError(`
321
358
  ${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
322
- ${_DbPull2.help}`);
359
+ ${_DbPull.help}`);
323
360
  }
324
- return _DbPull2.help;
361
+ return _DbPull.help;
325
362
  }
326
363
  };
327
- (0, import_chunk_WWAWV7DQ.__publicField)(_DbPull, "help", (0, import_internals.format)(`
328
- Pull the state from the database to the Prisma schema using introspection
329
-
330
- ${(0, import_chunk_SKRR5WT4.bold)("Usage")}
331
-
332
- ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull [flags/options]
333
-
334
- ${(0, import_chunk_SKRR5WT4.bold)("Flags")}
335
-
336
- -h, --help Display this help message
337
- --force Ignore current Prisma schema file
338
- --print Print the introspected Prisma schema to stdout
339
-
340
- ${(0, import_chunk_SKRR5WT4.bold)("Options")}
341
-
342
- --config Custom path to your Prisma config file
343
- --schema Custom path to your Prisma schema
344
- --composite-type-depth Specify the depth for introspecting composite types (e.g. Embedded Documents in MongoDB)
345
- Number, default is -1 for infinite depth, 0 = off
346
- --schemas Specify the database schemas to introspect. This overrides the schemas defined in the datasource block of your Prisma schema.
347
- --local-d1 Generate a Prisma schema from a local Cloudflare D1 database
348
- ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
349
-
350
- With an existing Prisma schema
351
- ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull
352
-
353
- Or specify a Prisma schema path
354
- ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --schema=./schema.prisma
355
-
356
- Instead of saving the result to the filesystem, you can also print it to stdout
357
- ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --print
358
-
359
- Overwrite the current schema with the introspected schema instead of enriching it
360
- ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --force
361
-
362
- Set composite types introspection depth to 2 levels
363
- ${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --composite-type-depth=2
364
-
365
- `));
366
- var DbPull = _DbPull;