@prisma/migrate 6.6.0-dev.27 → 6.6.0-dev.28

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.
package/dist/bin.js CHANGED
@@ -24,11 +24,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  ));
25
25
  var import_chunk_NGQA5JTN = require("./chunk-NGQA5JTN.js");
26
26
  var import_chunk_MKS2ZJJ5 = require("./chunk-MKS2ZJJ5.js");
27
- var import_chunk_324Z6HS7 = require("./chunk-324Z6HS7.js");
28
- var import_chunk_KMHFSDY6 = require("./chunk-KMHFSDY6.js");
29
- var import_chunk_HJFSTAJX = require("./chunk-HJFSTAJX.js");
30
- var import_chunk_FBWTUBJC = require("./chunk-FBWTUBJC.js");
31
- var import_chunk_NJYZPNB4 = require("./chunk-NJYZPNB4.js");
27
+ var import_chunk_WR2C56DM = require("./chunk-WR2C56DM.js");
28
+ var import_chunk_YQBUDHMZ = require("./chunk-YQBUDHMZ.js");
29
+ var import_chunk_Y4DAOJ7D = require("./chunk-Y4DAOJ7D.js");
30
+ var import_chunk_E4LVVJWG = require("./chunk-E4LVVJWG.js");
31
+ var import_chunk_DTHO2IRV = require("./chunk-DTHO2IRV.js");
32
32
  var import_chunk_IINN7QUV = require("./chunk-IINN7QUV.js");
33
33
  var import_chunk_RTGQXNX6 = require("./chunk-RTGQXNX6.js");
34
34
  var import_chunk_AI6DH66U = require("./chunk-AI6DH66U.js");
@@ -37,18 +37,18 @@ var import_chunk_JZ75RIMZ = require("./chunk-JZ75RIMZ.js");
37
37
  var import_chunk_RR6BKMNO = require("./chunk-RR6BKMNO.js");
38
38
  var import_chunk_JFKDSUIE = require("./chunk-JFKDSUIE.js");
39
39
  var import_chunk_LGYRZ6CV = require("./chunk-LGYRZ6CV.js");
40
- var import_chunk_YBNDKPPO = require("./chunk-YBNDKPPO.js");
40
+ var import_chunk_47RUC4JR = require("./chunk-47RUC4JR.js");
41
41
  var import_chunk_B4SUSDC2 = require("./chunk-B4SUSDC2.js");
42
42
  var import_chunk_LLO7YF56 = require("./chunk-LLO7YF56.js");
43
- var import_chunk_GPNGRJAR = require("./chunk-GPNGRJAR.js");
44
- var import_chunk_BURHAP6O = require("./chunk-BURHAP6O.js");
43
+ var import_chunk_QDOXBF4N = require("./chunk-QDOXBF4N.js");
44
+ var import_chunk_EJ6HP3SA = require("./chunk-EJ6HP3SA.js");
45
45
  var import_chunk_YBX7R3MT = require("./chunk-YBX7R3MT.js");
46
46
  var import_chunk_7CQBDP4H = require("./chunk-7CQBDP4H.js");
47
47
  var import_chunk_5LKIRKDL = require("./chunk-5LKIRKDL.js");
48
48
  var import_chunk_KRQEFTDT = require("./chunk-KRQEFTDT.js");
49
49
  var import_chunk_UP6FVCDK = require("./chunk-UP6FVCDK.js");
50
50
  var import_chunk_2R6DII47 = require("./chunk-2R6DII47.js");
51
- var import_chunk_RI5NUPOB = require("./chunk-RI5NUPOB.js");
51
+ var import_chunk_YVMQRD65 = require("./chunk-YVMQRD65.js");
52
52
  var import_chunk_ZB5NPOJW = require("./chunk-ZB5NPOJW.js");
53
53
  var import_chunk_33LPBNDX = require("./chunk-33LPBNDX.js");
54
54
  var import_chunk_VAJ4VX67 = require("./chunk-VAJ4VX67.js");
@@ -59,9 +59,8 @@ var import_chunk_G7PJKEOV = require("./chunk-G7PJKEOV.js");
59
59
  var import_chunk_L6KOIJJ5 = require("./chunk-L6KOIJJ5.js");
60
60
  var import_chunk_EJG7GKM7 = require("./chunk-EJG7GKM7.js");
61
61
  var import_chunk_3WC4XD74 = require("./chunk-3WC4XD74.js");
62
- var import_chunk_GKDFIHM2 = require("./chunk-GKDFIHM2.js");
63
62
  var import_chunk_QOPTDDIH = require("./chunk-QOPTDDIH.js");
64
- var import_chunk_DJMFXNR4 = require("./chunk-DJMFXNR4.js");
63
+ var import_chunk_74LUB4XX = require("./chunk-74LUB4XX.js");
65
64
  var import_chunk_TWPTG4XS = require("./chunk-TWPTG4XS.js");
66
65
  var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
67
66
  var import_chunk_2ESYSVXG = require("./chunk-2ESYSVXG.js");
@@ -69,7 +68,7 @@ var import_config = require("@prisma/config");
69
68
  var import_debug = __toESM(require("@prisma/debug"));
70
69
  var import_engines_version = require("@prisma/engines-version");
71
70
  var import_internals = require("@prisma/internals");
72
- var version = "6.6.0-dev.27";
71
+ var version = "6.6.0-dev.28";
73
72
  process.on("uncaughtException", (e) => {
74
73
  console.log(e);
75
74
  });
@@ -91,17 +90,17 @@ var args = (0, import_internals.arg)(
91
90
  async function main() {
92
91
  const cli = import_chunk_NGQA5JTN.CLI.new({
93
92
  migrate: import_chunk_LLO7YF56.MigrateCommand.new({
94
- dev: import_chunk_BURHAP6O.MigrateDev.new(),
95
- status: import_chunk_HJFSTAJX.MigrateStatus.new(),
96
- resolve: import_chunk_KMHFSDY6.MigrateResolve.new(),
97
- reset: import_chunk_324Z6HS7.MigrateReset.new(),
98
- deploy: import_chunk_GPNGRJAR.MigrateDeploy.new(),
99
- diff: import_chunk_RI5NUPOB.MigrateDiff.new()
93
+ dev: import_chunk_EJ6HP3SA.MigrateDev.new(),
94
+ status: import_chunk_Y4DAOJ7D.MigrateStatus.new(),
95
+ resolve: import_chunk_YQBUDHMZ.MigrateResolve.new(),
96
+ reset: import_chunk_WR2C56DM.MigrateReset.new(),
97
+ deploy: import_chunk_QDOXBF4N.MigrateDeploy.new(),
98
+ diff: import_chunk_YVMQRD65.MigrateDiff.new()
100
99
  }),
101
100
  db: import_chunk_EJG7GKM7.DbCommand.new({
102
- execute: import_chunk_FBWTUBJC.DbExecute.new(),
103
- pull: import_chunk_NJYZPNB4.DbPull.new(),
104
- push: import_chunk_YBNDKPPO.DbPush.new(),
101
+ execute: import_chunk_E4LVVJWG.DbExecute.new(),
102
+ pull: import_chunk_DTHO2IRV.DbPull.new(),
103
+ push: import_chunk_47RUC4JR.DbPush.new(),
105
104
  // drop: DbDrop.new(),
106
105
  seed: import_chunk_B4SUSDC2.DbSeed.new()
107
106
  })
@@ -26,16 +26,15 @@ 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_YBNDKPPO_exports = {};
30
- __export(chunk_YBNDKPPO_exports, {
29
+ var chunk_47RUC4JR_exports = {};
30
+ __export(chunk_47RUC4JR_exports, {
31
31
  DbPush: () => DbPush
32
32
  });
33
- module.exports = __toCommonJS(chunk_YBNDKPPO_exports);
33
+ module.exports = __toCommonJS(chunk_47RUC4JR_exports);
34
34
  var import_chunk_VVP3QZ7Q = require("./chunk-VVP3QZ7Q.js");
35
35
  var import_chunk_3WC4XD74 = require("./chunk-3WC4XD74.js");
36
- var import_chunk_GKDFIHM2 = require("./chunk-GKDFIHM2.js");
37
36
  var import_chunk_QOPTDDIH = require("./chunk-QOPTDDIH.js");
38
- var import_chunk_DJMFXNR4 = require("./chunk-DJMFXNR4.js");
37
+ var import_chunk_74LUB4XX = require("./chunk-74LUB4XX.js");
39
38
  var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
40
39
  var import_internals = require("@prisma/internals");
41
40
  var import_prompts = __toESM(require("prompts"));
@@ -93,12 +92,15 @@ ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
93
92
  return this.help();
94
93
  }
95
94
  await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true, config });
96
- const { schemaPath } = await (0, import_chunk_GKDFIHM2.getSchemaPathAndPrint)(args["--schema"], config.schema);
97
- const datasourceInfo = await (0, import_chunk_DJMFXNR4.getDatasourceInfo)({ schemaPath });
95
+ const schemaContext = await (0, import_internals.loadSchemaContext)({
96
+ schemaPathFromArg: args["--schema"],
97
+ schemaPathFromConfig: config.schema
98
+ });
99
+ const datasourceInfo = (0, import_chunk_74LUB4XX.parseDatasourceInfo)(schemaContext.primaryDatasource);
98
100
  (0, import_chunk_QOPTDDIH.printDatasource)({ datasourceInfo });
99
- const migrate = new import_chunk_VVP3QZ7Q.Migrate(schemaPath);
101
+ const migrate = new import_chunk_VVP3QZ7Q.Migrate(schemaContext.schemaPath);
100
102
  try {
101
- const wasDbCreated = await (0, import_chunk_DJMFXNR4.ensureDatabaseExists)("push", schemaPath);
103
+ const wasDbCreated = await (0, import_chunk_74LUB4XX.ensureDatabaseExists)(schemaContext.primaryDatasource);
102
104
  if (wasDbCreated) {
103
105
  process.stdout.write("\n" + wasDbCreated + "\n");
104
106
  }
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,35 +17,30 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
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
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_DJMFXNR4_exports = {};
20
- __export(chunk_DJMFXNR4_exports, {
29
+ var chunk_74LUB4XX_exports = {};
30
+ __export(chunk_74LUB4XX_exports, {
21
31
  ensureCanConnectToDatabase: () => ensureCanConnectToDatabase,
22
32
  ensureDatabaseExists: () => ensureDatabaseExists,
23
- getDatasourceInfo: () => getDatasourceInfo,
24
33
  getDbLocation: () => getDbLocation,
34
+ parseDatasourceInfo: () => parseDatasourceInfo,
25
35
  prettifyProvider: () => prettifyProvider
26
36
  });
27
- module.exports = __toCommonJS(chunk_DJMFXNR4_exports);
37
+ module.exports = __toCommonJS(chunk_74LUB4XX_exports);
28
38
  var import_chunk_TWPTG4XS = require("./chunk-TWPTG4XS.js");
29
39
  var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
30
40
  var import_internals = require("@prisma/internals");
31
- async function getDatasourceInfo({
32
- schemaPath,
33
- throwIfEnvError
34
- } = {}) {
35
- const schema = await (0, import_internals.getSchema)(schemaPath);
36
- let config;
37
- try {
38
- config = await (0, import_internals.getConfig)({ datamodel: schema, ignoreEnvVarErrors: false });
39
- } catch (error) {
40
- if (throwIfEnvError) {
41
- throw error;
42
- }
43
- config = await (0, import_internals.getConfig)({ datamodel: schema, ignoreEnvVarErrors: true });
44
- }
45
- const firstDatasource = config.datasources[0] ? config.datasources[0] : void 0;
46
- if (!firstDatasource) {
41
+ var import_path = __toESM(require("path"));
42
+ function parseDatasourceInfo(datasource) {
43
+ if (!datasource) {
47
44
  return {
48
45
  name: void 0,
49
46
  prettyProvider: void 0,
@@ -55,67 +52,64 @@ async function getDatasourceInfo({
55
52
  configDir: void 0
56
53
  };
57
54
  }
58
- const prettyProvider = prettifyProvider(firstDatasource.provider);
59
- const url = (0, import_internals.getEffectiveUrl)(firstDatasource).value;
60
- if (!url || firstDatasource.provider === "sqlserver") {
55
+ const prettyProvider = prettifyProvider(datasource.provider);
56
+ const url = (0, import_internals.getEffectiveUrl)(datasource).value;
57
+ if (!url || datasource.provider === "sqlserver") {
61
58
  return {
62
- name: firstDatasource.name,
59
+ name: datasource.name,
63
60
  prettyProvider,
64
61
  dbName: void 0,
65
62
  dbLocation: void 0,
66
63
  url: url || void 0,
67
64
  schema: void 0,
68
- schemas: firstDatasource.schemas,
69
- configDir: (0, import_internals.getMigrateConfigDir)(config, schemaPath)
65
+ schemas: datasource.schemas,
66
+ configDir: import_path.default.dirname(datasource.sourceFilePath)
70
67
  };
71
68
  }
72
69
  try {
73
70
  const credentials = (0, import_internals.uriToCredentials)(url);
74
71
  const dbLocation = getDbLocation(credentials);
75
- let schema2 = void 0;
76
- if (["postgresql", "cockroachdb"].includes(firstDatasource.provider)) {
72
+ let schema = void 0;
73
+ if (["postgresql", "cockroachdb"].includes(datasource.provider)) {
77
74
  if (credentials.schema) {
78
- schema2 = credentials.schema;
75
+ schema = credentials.schema;
79
76
  } else {
80
- schema2 = "public";
77
+ schema = "public";
81
78
  }
82
79
  }
83
80
  const datasourceInfo = {
84
- name: firstDatasource.name,
81
+ name: datasource.name,
85
82
  prettyProvider,
86
83
  dbName: credentials.database,
87
84
  dbLocation,
88
85
  url,
89
- schema: schema2,
90
- schemas: firstDatasource.schemas,
91
- configDir: (0, import_internals.getMigrateConfigDir)(config, schemaPath)
86
+ schema,
87
+ schemas: datasource.schemas,
88
+ configDir: import_path.default.dirname(datasource.sourceFilePath)
92
89
  };
93
- if (firstDatasource.provider === "postgresql" && datasourceInfo.dbName === void 0) {
90
+ if (datasource.provider === "postgresql" && datasourceInfo.dbName === void 0) {
94
91
  datasourceInfo.dbName = "postgres";
95
92
  }
96
93
  return datasourceInfo;
97
94
  } catch (e) {
98
95
  return {
99
- name: firstDatasource.name,
96
+ name: datasource.name,
100
97
  prettyProvider,
101
98
  dbName: void 0,
102
99
  dbLocation: void 0,
103
100
  url,
104
101
  schema: void 0,
105
- schemas: firstDatasource.schemas,
106
- configDir: (0, import_internals.getMigrateConfigDir)(config, schemaPath)
102
+ schemas: datasource.schemas,
103
+ configDir: import_path.default.dirname(datasource.sourceFilePath)
107
104
  };
108
105
  }
109
106
  }
110
- async function ensureCanConnectToDatabase(schemaPath) {
111
- const schema = await (0, import_internals.getSchema)(schemaPath);
112
- const config = await (0, import_internals.getConfig)({ datamodel: schema, ignoreEnvVarErrors: false });
113
- const firstDatasource = config.datasources[0] ? config.datasources[0] : void 0;
114
- if (!firstDatasource) {
107
+ async function ensureCanConnectToDatabase(datasource) {
108
+ if (!datasource) {
115
109
  throw new Error(`A datasource block is missing in the Prisma schema file.`);
116
110
  }
117
- const schemaDir = (0, import_internals.getMigrateConfigDir)(config, schemaPath);
118
- const url = (0, import_internals.getEffectiveUrl)(firstDatasource).value;
111
+ const schemaDir = import_path.default.dirname(datasource.sourceFilePath);
112
+ const url = getConnectionUrl(datasource);
119
113
  const canConnect = await (0, import_internals.canConnectToDatabase)(url, schemaDir);
120
114
  if (canConnect === true) {
121
115
  return true;
@@ -124,15 +118,12 @@ async function ensureCanConnectToDatabase(schemaPath) {
124
118
  throw new Error(`${code}: ${message}`);
125
119
  }
126
120
  }
127
- async function ensureDatabaseExists(action, schemaPath) {
128
- const schemas = await (0, import_internals.getSchema)(schemaPath);
129
- const config = await (0, import_internals.getConfig)({ datamodel: schemas, ignoreEnvVarErrors: false });
130
- const firstDatasource = config.datasources[0] ? config.datasources[0] : void 0;
131
- if (!firstDatasource) {
121
+ async function ensureDatabaseExists(datasource) {
122
+ if (!datasource) {
132
123
  throw new Error(`A datasource block is missing in the Prisma schema file.`);
133
124
  }
134
- const schemaDir = (0, import_internals.getMigrateConfigDir)(config, schemaPath);
135
- const url = (0, import_internals.getEffectiveUrl)(firstDatasource).value;
125
+ const schemaDir = import_path.default.dirname(datasource.sourceFilePath);
126
+ const url = getConnectionUrl(datasource);
136
127
  const canConnect = await (0, import_internals.canConnectToDatabase)(url, schemaDir);
137
128
  if (canConnect === true) {
138
129
  return;
@@ -141,16 +132,13 @@ async function ensureDatabaseExists(action, schemaPath) {
141
132
  if (code !== "P1003") {
142
133
  throw new Error(`${code}: ${message}`);
143
134
  }
144
- if (!schemaDir) {
145
- throw new Error(`Could not locate ${schemaPath || "schema.prisma"}`);
146
- }
147
135
  if (await (0, import_internals.createDatabase)(url, schemaDir)) {
148
- if (firstDatasource.provider === "sqlserver") {
136
+ if (datasource.provider === "sqlserver") {
149
137
  return `SQL Server database created.
150
138
  `;
151
139
  }
152
140
  const credentials = (0, import_internals.uriToCredentials)(url);
153
- const prettyProvider = prettifyProvider(firstDatasource.provider);
141
+ const prettyProvider = prettifyProvider(datasource.provider);
154
142
  let message2 = `${prettyProvider} database${credentials.database ? ` ${credentials.database} ` : " "}created`;
155
143
  const dbLocation = getDbLocation(credentials);
156
144
  if (dbLocation) {
@@ -193,3 +181,14 @@ function prettifyProvider(provider) {
193
181
  return `MongoDB`;
194
182
  }
195
183
  }
184
+ function getConnectionUrl(datasource) {
185
+ const url = (0, import_internals.getEffectiveUrl)(datasource);
186
+ if (!url.value) {
187
+ if (url.fromEnvVar) {
188
+ throw new Error(`Environment variable '${url.fromEnvVar}' with database connection URL was not found.`);
189
+ } else {
190
+ throw new Error(`Datasource is missing a database connection URL.`);
191
+ }
192
+ }
193
+ return url.value;
194
+ }
@@ -26,11 +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_NJYZPNB4_exports = {};
30
- __export(chunk_NJYZPNB4_exports, {
29
+ var chunk_DTHO2IRV_exports = {};
30
+ __export(chunk_DTHO2IRV_exports, {
31
31
  DbPull: () => DbPull
32
32
  });
33
- module.exports = __toCommonJS(chunk_NJYZPNB4_exports);
33
+ module.exports = __toCommonJS(chunk_DTHO2IRV_exports);
34
34
  var import_chunk_IINN7QUV = require("./chunk-IINN7QUV.js");
35
35
  var import_chunk_RTGQXNX6 = require("./chunk-RTGQXNX6.js");
36
36
  var import_chunk_AI6DH66U = require("./chunk-AI6DH66U.js");
@@ -43,7 +43,7 @@ var import_chunk_K43RXWQY = require("./chunk-K43RXWQY.js");
43
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
48
  var import_debug = __toESM(require("@prisma/debug"));
49
49
  var import_internals = require("@prisma/internals");
@@ -127,38 +127,38 @@ Set composite types introspection depth to 2 levels
127
127
  return this.help();
128
128
  }
129
129
  const url = args["--url"];
130
- const schemaPathResult = await (0, import_internals.getSchemaWithPathOptional)(args["--schema"], config.schema);
131
- let schemaPath = schemaPathResult?.schemaPath ?? null;
132
- const rootDir = schemaPathResult?.schemaRootDir ?? process.cwd();
133
- debug("schemaPathResult", schemaPathResult);
134
- if (schemaPath && !args["--print"]) {
135
- 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");
136
138
  await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true, config });
137
- (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) });
138
140
  } else {
139
141
  await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: false, config });
140
142
  }
141
143
  const fromD1 = Boolean(args["--local-d1"]);
142
- if (!url && !schemaPath && !fromD1) {
144
+ if (!url && !schemaContext && !fromD1) {
143
145
  throw new import_chunk_3WC4XD74.NoSchemaFoundError();
144
146
  }
145
- const { firstDatasource, schema, validationWarning } = await (0, import_chunk_G7PJKEOV.z)({ url, schemaPath, fromD1 }).when(
146
- (input) => input.schemaPath !== null,
147
+ const { firstDatasource, schema, validationWarning } = await (0, import_chunk_G7PJKEOV.z)({ url, schemaContext, fromD1 }).when(
148
+ (input) => input.schemaContext !== null,
147
149
  async (input) => {
148
- const rawSchema = await (0, import_internals.getSchema)(input.schemaPath, config.schema);
149
- const engineConfig = await (0, import_internals.getConfig)({
150
- datamodel: rawSchema,
151
- ignoreEnvVarErrors: true
152
- });
153
- const previewFeatures = engineConfig.generators.find(({ name }) => name === "client")?.previewFeatures;
154
- 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;
155
152
  if (input.url) {
156
153
  let providerFromSchema = firstDatasource2?.provider;
157
154
  if (providerFromSchema === "postgres") {
158
155
  providerFromSchema = "postgresql";
159
156
  }
160
157
  const providerFromUrl = (0, import_internals.protocolToConnectorType)(`${input.url.split(":")[0]}:`);
161
- 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
+ );
162
162
  if (providerFromSchema && providerFromUrl && providerFromSchema !== providerFromUrl && Boolean(providerFromSchema === "cockroachdb" && providerFromUrl === "postgresql") === false) {
163
163
  throw new Error(
164
164
  `The database provider found in --url (${providerFromUrl}) is different from the provider found in the Prisma schema (${providerFromSchema}).`
@@ -167,7 +167,7 @@ Set composite types introspection depth to 2 levels
167
167
  return { firstDatasource: firstDatasource2, schema: schema2, validationWarning: void 0 };
168
168
  } else if (input.fromD1) {
169
169
  const d1Database = await (0, import_internals.locateLocalCloudflareD1)({ arg: "--from-local-d1" });
170
- const pathToSQLiteFile = import_path.default.relative(import_path.default.dirname(input.schemaPath), d1Database);
170
+ const pathToSQLiteFile = import_path.default.relative(input.schemaContext.schemaRootDir, d1Database);
171
171
  const schema2 = [
172
172
  ["schema.prisma", this.urlToDatasource(`file:${pathToSQLiteFile}`, "sqlite")]
173
173
  ];
@@ -189,11 +189,11 @@ Set composite types introspection depth to 2 levels
189
189
  }
190
190
  } else {
191
191
  await (0, import_internals.getConfig)({
192
- datamodel: rawSchema,
192
+ datamodel: input.schemaContext.schemaFiles,
193
193
  ignoreEnvVarErrors: false
194
194
  });
195
195
  }
196
- return { firstDatasource: firstDatasource2, schema: rawSchema, validationWarning: void 0 };
196
+ return { firstDatasource: firstDatasource2, schema: input.schemaContext.schemaFiles, validationWarning: void 0 };
197
197
  }
198
198
  ).when(
199
199
  (input) => input.fromD1 === true,
@@ -224,10 +224,9 @@ ${this.urlToDatasource(`file:${pathToSQLiteFile}`, "sqlite")}`;
224
224
  return { firstDatasource: config2.datasources[0], schema: schema2, validationWarning: void 0 };
225
225
  }
226
226
  ).run();
227
- if (schemaPath) {
228
- const schemas = await (0, import_internals.getSchema)(args["--schema"], config.schema);
227
+ if (schemaContext) {
229
228
  const modelRegex = /\s*model\s*(\w+)\s*{/;
230
- const isReintrospection = schemas.some(([_, schema2]) => !!modelRegex.exec(schema2));
229
+ const isReintrospection = schemaContext.schemaFiles.some(([_, schema2]) => !!modelRegex.exec(schema2));
231
230
  if (isReintrospection && !args["--force"] && firstDatasource?.provider === "mongodb") {
232
231
  throw new Error(`Iterating on one schema using re-introspection with db pull is currently not supported with MongoDB provider.
233
232
  You can explicitly ignore and override your current local schema file with ${(0, import_chunk_SKRR5WT4.green)(
@@ -239,9 +238,9 @@ Some information will be lost (relations, comments, mapped fields, @ignore...),
239
238
  }
240
239
  }
241
240
  const engine = new import_chunk_K43RXWQY.SchemaEngine({
242
- schemaPath: schemaPath ?? void 0
241
+ schemaPath: schemaContext?.schemaPath ?? void 0
243
242
  });
244
- 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)}` : "";
245
244
  const introspectionSpinner = spinnerFactory(`Introspecting${basedOn}`);
246
245
  const before = Math.round(performance.now());
247
246
  let introspectionSchema = void 0;
@@ -249,7 +248,7 @@ Some information will be lost (relations, comments, mapped fields, @ignore...),
249
248
  try {
250
249
  const introspectionResult = await engine.introspect({
251
250
  schema: (0, import_internals.toSchemasContainer)(schema),
252
- baseDirectoryPath: rootDir,
251
+ baseDirectoryPath: schemaContext?.schemaRootDir ?? process.cwd(),
253
252
  force: args["--force"],
254
253
  compositeTypeDepth: args["--composite-type-depth"],
255
254
  namespaces: args["--schemas"]?.split(",")
@@ -321,7 +320,6 @@ Or run this command with the ${(0, import_chunk_SKRR5WT4.green)(
321
320
  console.error(introspectionWarningsMessage.replace(/(\n)/gm, "\n// "));
322
321
  }
323
322
  } else {
324
- schemaPath = schemaPath || "schema.prisma";
325
323
  if (args["--force"]) {
326
324
  await (0, import_chunk_JZ75RIMZ.removeSchemaFiles)(schema);
327
325
  }
@@ -338,8 +336,9 @@ Or run this command with the ${(0, import_chunk_SKRR5WT4.green)(
338
336
  const modelsAndTypesCountMessage = modelsCount + typesCount > 1 ? `${modelsAndTypesMessage} and wrote them` : `${modelsAndTypesMessage} and wrote it`;
339
337
  const renderValidationWarning = validationWarning ? `
340
338
  ${(0, import_chunk_SKRR5WT4.yellow)(validationWarning)}` : "";
339
+ const introspectedSchemaPath = schemaContext?.loadedFromPathForLogMessages || introspectionSchema.files[0].path;
341
340
  introspectionSpinner.success(`Introspected ${modelsAndTypesCountMessage} into ${(0, import_chunk_SKRR5WT4.underline)(
342
- import_path.default.relative(process.cwd(), schemaPath)
341
+ import_path.default.relative(process.cwd(), introspectedSchemaPath)
343
342
  )} in ${(0, import_chunk_SKRR5WT4.bold)((0, import_internals.formatms)(Math.round(performance.now()) - before))}
344
343
  ${(0, import_chunk_SKRR5WT4.yellow)(introspectionWarningsMessage)}
345
344
  ${`Run ${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExecutor)("prisma generate"))} to generate Prisma Client.`}${renderValidationWarning}`);
@@ -26,11 +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_FBWTUBJC_exports = {};
30
- __export(chunk_FBWTUBJC_exports, {
29
+ var chunk_E4LVVJWG_exports = {};
30
+ __export(chunk_E4LVVJWG_exports, {
31
31
  DbExecute: () => DbExecute
32
32
  });
33
- module.exports = __toCommonJS(chunk_FBWTUBJC_exports);
33
+ module.exports = __toCommonJS(chunk_E4LVVJWG_exports);
34
34
  var import_chunk_VVP3QZ7Q = require("./chunk-VVP3QZ7Q.js");
35
35
  var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
36
36
  var import_internals = require("@prisma/internals");
@@ -191,11 +191,15 @@ See \`${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExec
191
191
  url: args["--url"]
192
192
  };
193
193
  } else {
194
- const schemaWithPath = await (0, import_internals.getSchemaWithPath)(args["--schema"], config.schema);
195
- 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
+ });
196
199
  datasourceType = {
197
200
  tag: "schema",
198
- ...(0, import_internals.toSchemasWithConfigDir)(schemaWithPath, engineConfig)
201
+ ...(0, import_internals.toSchemasContainer)(schemaContext.schemaFiles),
202
+ configDir: schemaContext.primaryDatasourceDirectory
199
203
  };
200
204
  }
201
205
  const migrate = new import_chunk_VVP3QZ7Q.Migrate();
@@ -26,11 +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_BURHAP6O_exports = {};
30
- __export(chunk_BURHAP6O_exports, {
29
+ var chunk_EJ6HP3SA_exports = {};
30
+ __export(chunk_EJ6HP3SA_exports, {
31
31
  MigrateDev: () => MigrateDev
32
32
  });
33
- module.exports = __toCommonJS(chunk_BURHAP6O_exports);
33
+ module.exports = __toCommonJS(chunk_EJ6HP3SA_exports);
34
34
  var import_chunk_YBX7R3MT = require("./chunk-YBX7R3MT.js");
35
35
  var import_chunk_7CQBDP4H = require("./chunk-7CQBDP4H.js");
36
36
  var import_chunk_5LKIRKDL = require("./chunk-5LKIRKDL.js");
@@ -38,9 +38,8 @@ var import_chunk_KRQEFTDT = require("./chunk-KRQEFTDT.js");
38
38
  var import_chunk_UP6FVCDK = require("./chunk-UP6FVCDK.js");
39
39
  var import_chunk_VVP3QZ7Q = require("./chunk-VVP3QZ7Q.js");
40
40
  var import_chunk_3WC4XD74 = require("./chunk-3WC4XD74.js");
41
- var import_chunk_GKDFIHM2 = require("./chunk-GKDFIHM2.js");
42
41
  var import_chunk_QOPTDDIH = require("./chunk-QOPTDDIH.js");
43
- var import_chunk_DJMFXNR4 = require("./chunk-DJMFXNR4.js");
42
+ var import_chunk_74LUB4XX = require("./chunk-74LUB4XX.js");
44
43
  var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
45
44
  var import_debug = __toESM(require("@prisma/debug"));
46
45
  var import_internals = require("@prisma/internals");
@@ -102,22 +101,19 @@ ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
102
101
  return this.help();
103
102
  }
104
103
  await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true, config });
105
- const { schemaPath, schemas } = await (0, import_chunk_GKDFIHM2.getSchemaPathAndPrint)(args["--schema"], config.schema);
106
- const datasourceInfo = await (0, import_chunk_DJMFXNR4.getDatasourceInfo)({ schemaPath });
104
+ const schemaContext = await (0, import_internals.loadSchemaContext)({
105
+ schemaPathFromArg: args["--schema"],
106
+ schemaPathFromConfig: config.schema
107
+ });
108
+ const datasourceInfo = (0, import_chunk_74LUB4XX.parseDatasourceInfo)(schemaContext.primaryDatasource);
107
109
  (0, import_chunk_QOPTDDIH.printDatasource)({ datasourceInfo });
108
110
  process.stdout.write("\n");
109
- (0, import_internals.validate)({
110
- schemas
111
- });
112
- await (0, import_internals.getConfig)({
113
- datamodel: schemas,
114
- ignoreEnvVarErrors: false
115
- });
116
- const wasDbCreated = await (0, import_chunk_DJMFXNR4.ensureDatabaseExists)("create", schemaPath);
111
+ (0, import_internals.validate)({ schemas: schemaContext.schemaFiles });
112
+ const wasDbCreated = await (0, import_chunk_74LUB4XX.ensureDatabaseExists)(schemaContext.primaryDatasource);
117
113
  if (wasDbCreated) {
118
114
  process.stdout.write(wasDbCreated + "\n\n");
119
115
  }
120
- const migrate = new import_chunk_VVP3QZ7Q.Migrate(schemaPath);
116
+ const migrate = new import_chunk_VVP3QZ7Q.Migrate(schemaContext.schemaPath);
121
117
  let devDiagnostic;
122
118
  try {
123
119
  devDiagnostic = await migrate.devDiagnostic();
@@ -26,16 +26,15 @@ 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_ZGR2WQ62_exports = {};
30
- __export(chunk_ZGR2WQ62_exports, {
29
+ var chunk_HPT54KSO_exports = {};
30
+ __export(chunk_HPT54KSO_exports, {
31
31
  DbDrop: () => DbDrop
32
32
  });
33
- module.exports = __toCommonJS(chunk_ZGR2WQ62_exports);
33
+ module.exports = __toCommonJS(chunk_HPT54KSO_exports);
34
34
  var import_chunk_IHDN3L3R = require("./chunk-IHDN3L3R.js");
35
35
  var import_chunk_3WC4XD74 = require("./chunk-3WC4XD74.js");
36
- var import_chunk_GKDFIHM2 = require("./chunk-GKDFIHM2.js");
37
36
  var import_chunk_QOPTDDIH = require("./chunk-QOPTDDIH.js");
38
- var import_chunk_DJMFXNR4 = require("./chunk-DJMFXNR4.js");
37
+ var import_chunk_74LUB4XX = require("./chunk-74LUB4XX.js");
39
38
  var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
40
39
  var import_internals = require("@prisma/internals");
41
40
  var import_prompts = __toESM(require("prompts"));
@@ -96,8 +95,11 @@ ${(0, import_chunk_SKRR5WT4.bold)("Examples")}
96
95
  throw new import_chunk_IHDN3L3R.PreviewFlagError();
97
96
  }
98
97
  await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true, config });
99
- const { schemaPath } = await (0, import_chunk_GKDFIHM2.getSchemaPathAndPrint)(args["--schema"], config.schema);
100
- const datasourceInfo = await (0, import_chunk_DJMFXNR4.getDatasourceInfo)({ schemaPath, throwIfEnvError: true });
98
+ const { primaryDatasource } = await (0, import_internals.loadSchemaContext)({
99
+ schemaPathFromArg: args["--schema"],
100
+ schemaPathFromConfig: config.schema
101
+ });
102
+ const datasourceInfo = (0, import_chunk_74LUB4XX.parseDatasourceInfo)(primaryDatasource);
101
103
  (0, import_chunk_QOPTDDIH.printDatasource)({ datasourceInfo });
102
104
  process.stdout.write("\n");
103
105
  if (!args["--force"]) {