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

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 (48) hide show
  1. package/dist/Migrate.js +5 -3
  2. package/dist/SchemaEngine.js +3 -3
  3. package/dist/bin.js +29 -28
  4. package/dist/chunk-23DZXSTI.js +62 -0
  5. package/dist/{chunk-VVP3QZ7Q.js → chunk-5Q5BJS5B.js} +63 -20
  6. package/dist/{chunk-YBNDKPPO.js → chunk-63ZT25OL.js} +12 -10
  7. package/dist/{chunk-DJMFXNR4.js → chunk-74LUB4XX.js} +56 -57
  8. package/dist/{chunk-IWC5MH4R.js → chunk-ABQZ5J74.js} +5 -5
  9. package/dist/{chunk-324Z6HS7.js → chunk-AM7BRZFD.js} +12 -10
  10. package/dist/{chunk-HJFSTAJX.js → chunk-BUAYZ4KA.js} +12 -10
  11. package/dist/{chunk-K43RXWQY.js → chunk-GHZAN2PG.js} +3 -9
  12. package/dist/{chunk-ZGR2WQ62.js → chunk-HPT54KSO.js} +9 -7
  13. package/dist/{chunk-KMHFSDY6.js → chunk-HQJ7FIWN.js} +14 -12
  14. package/dist/{chunk-GPNGRJAR.js → chunk-IRYXRMQC.js} +12 -10
  15. package/dist/{chunk-FBWTUBJC.js → chunk-LAEOX7QH.js} +12 -8
  16. package/dist/{chunk-MKS2ZJJ5.js → chunk-MTJFLQI4.js} +5 -5
  17. package/dist/{chunk-NJYZPNB4.js → chunk-SCH55BRJ.js} +36 -37
  18. package/dist/{chunk-DQMYH4YE.js → chunk-U6ZL4ORM.js} +10 -9
  19. package/dist/chunk-V6PVGSDJ.js +76 -0
  20. package/dist/{chunk-RI5NUPOB.js → chunk-WX6S3QMO.js} +11 -10
  21. package/dist/{chunk-BURHAP6O.js → chunk-ZCR4PTT3.js} +13 -18
  22. package/dist/commands/DbDrop.js +3 -4
  23. package/dist/commands/DbExecute.js +6 -4
  24. package/dist/commands/DbPull.js +6 -6
  25. package/dist/commands/DbPush.js +7 -6
  26. package/dist/commands/MigrateDeploy.js +7 -6
  27. package/dist/commands/MigrateDev.js +7 -6
  28. package/dist/commands/MigrateDiff.js +7 -5
  29. package/dist/commands/MigrateReset.js +7 -6
  30. package/dist/commands/MigrateResolve.js +7 -6
  31. package/dist/commands/MigrateStatus.js +7 -6
  32. package/dist/index.js +35 -33
  33. package/dist/internals/src/cli/schemaContext.d.ts +43 -0
  34. package/dist/internals/src/index.d.ts +1 -0
  35. package/dist/internals/src/migrateTypes.d.ts +63 -0
  36. package/dist/migrate/src/Migrate.d.ts +3 -1
  37. package/dist/migrate/src/SchemaEngine.d.ts +0 -4
  38. package/dist/migrate/src/types.d.ts +13 -10
  39. package/dist/migrate/src/utils/createMigration.d.ts +21 -0
  40. package/dist/migrate/src/utils/ensureDatabaseExists.d.ts +4 -6
  41. package/dist/migrate/src/utils/listMigrations.d.ts +9 -0
  42. package/dist/utils/createMigration.js +27 -0
  43. package/dist/utils/ensureDatabaseExists.js +6 -6
  44. package/dist/utils/getDatabaseVersionSafe.js +3 -3
  45. package/dist/utils/introspectSql.js +3 -3
  46. package/dist/utils/listMigrations.js +25 -0
  47. package/dist/utils/setupMSSQL.js +1 -1
  48. package/package.json +7 -7
package/dist/Migrate.js CHANGED
@@ -18,12 +18,14 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var Migrate_exports = {};
20
20
  __export(Migrate_exports, {
21
- Migrate: () => import_chunk_VVP3QZ7Q.Migrate
21
+ Migrate: () => import_chunk_5Q5BJS5B.Migrate
22
22
  });
23
23
  module.exports = __toCommonJS(Migrate_exports);
24
- var import_chunk_VVP3QZ7Q = require("./chunk-VVP3QZ7Q.js");
24
+ var import_chunk_5Q5BJS5B = require("./chunk-5Q5BJS5B.js");
25
+ var import_chunk_V6PVGSDJ = require("./chunk-V6PVGSDJ.js");
26
+ var import_chunk_23DZXSTI = require("./chunk-23DZXSTI.js");
25
27
  var import_chunk_URKH6SE2 = require("./chunk-URKH6SE2.js");
26
- var import_chunk_K43RXWQY = require("./chunk-K43RXWQY.js");
28
+ var import_chunk_GHZAN2PG = require("./chunk-GHZAN2PG.js");
27
29
  var import_chunk_G7PJKEOV = require("./chunk-G7PJKEOV.js");
28
30
  var import_chunk_L6KOIJJ5 = require("./chunk-L6KOIJJ5.js");
29
31
  var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
@@ -18,11 +18,11 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var SchemaEngine_exports = {};
20
20
  __export(SchemaEngine_exports, {
21
- EngineError: () => import_chunk_K43RXWQY.EngineError,
22
- SchemaEngine: () => import_chunk_K43RXWQY.SchemaEngine
21
+ EngineError: () => import_chunk_GHZAN2PG.EngineError,
22
+ SchemaEngine: () => import_chunk_GHZAN2PG.SchemaEngine
23
23
  });
24
24
  module.exports = __toCommonJS(SchemaEngine_exports);
25
- var import_chunk_K43RXWQY = require("./chunk-K43RXWQY.js");
25
+ var import_chunk_GHZAN2PG = require("./chunk-GHZAN2PG.js");
26
26
  var import_chunk_G7PJKEOV = require("./chunk-G7PJKEOV.js");
27
27
  var import_chunk_L6KOIJJ5 = require("./chunk-L6KOIJJ5.js");
28
28
  var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
package/dist/bin.js CHANGED
@@ -23,45 +23,46 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  mod
24
24
  ));
25
25
  var import_chunk_NGQA5JTN = require("./chunk-NGQA5JTN.js");
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");
26
+ var import_chunk_MTJFLQI4 = require("./chunk-MTJFLQI4.js");
27
+ var import_chunk_AM7BRZFD = require("./chunk-AM7BRZFD.js");
28
+ var import_chunk_HQJ7FIWN = require("./chunk-HQJ7FIWN.js");
29
+ var import_chunk_BUAYZ4KA = require("./chunk-BUAYZ4KA.js");
30
+ var import_chunk_LAEOX7QH = require("./chunk-LAEOX7QH.js");
31
+ var import_chunk_SCH55BRJ = require("./chunk-SCH55BRJ.js");
32
32
  var import_chunk_IINN7QUV = require("./chunk-IINN7QUV.js");
33
+ var import_chunk_JZ75RIMZ = require("./chunk-JZ75RIMZ.js");
34
+ var import_chunk_RR6BKMNO = require("./chunk-RR6BKMNO.js");
33
35
  var import_chunk_RTGQXNX6 = require("./chunk-RTGQXNX6.js");
34
36
  var import_chunk_AI6DH66U = require("./chunk-AI6DH66U.js");
35
37
  var import_chunk_AHJ2N6BJ = require("./chunk-AHJ2N6BJ.js");
36
- var import_chunk_JZ75RIMZ = require("./chunk-JZ75RIMZ.js");
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_63ZT25OL = require("./chunk-63ZT25OL.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_IRYXRMQC = require("./chunk-IRYXRMQC.js");
44
+ var import_chunk_ZCR4PTT3 = require("./chunk-ZCR4PTT3.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");
52
- var import_chunk_ZB5NPOJW = require("./chunk-ZB5NPOJW.js");
51
+ var import_chunk_WX6S3QMO = require("./chunk-WX6S3QMO.js");
53
52
  var import_chunk_33LPBNDX = require("./chunk-33LPBNDX.js");
53
+ var import_chunk_ZB5NPOJW = require("./chunk-ZB5NPOJW.js");
54
54
  var import_chunk_VAJ4VX67 = require("./chunk-VAJ4VX67.js");
55
- var import_chunk_VVP3QZ7Q = require("./chunk-VVP3QZ7Q.js");
55
+ var import_chunk_5Q5BJS5B = require("./chunk-5Q5BJS5B.js");
56
+ var import_chunk_V6PVGSDJ = require("./chunk-V6PVGSDJ.js");
57
+ var import_chunk_23DZXSTI = require("./chunk-23DZXSTI.js");
56
58
  var import_chunk_URKH6SE2 = require("./chunk-URKH6SE2.js");
57
- var import_chunk_K43RXWQY = require("./chunk-K43RXWQY.js");
59
+ var import_chunk_GHZAN2PG = require("./chunk-GHZAN2PG.js");
58
60
  var import_chunk_G7PJKEOV = require("./chunk-G7PJKEOV.js");
59
61
  var import_chunk_L6KOIJJ5 = require("./chunk-L6KOIJJ5.js");
60
62
  var import_chunk_EJG7GKM7 = require("./chunk-EJG7GKM7.js");
61
63
  var import_chunk_3WC4XD74 = require("./chunk-3WC4XD74.js");
62
- var import_chunk_GKDFIHM2 = require("./chunk-GKDFIHM2.js");
63
64
  var import_chunk_QOPTDDIH = require("./chunk-QOPTDDIH.js");
64
- var import_chunk_DJMFXNR4 = require("./chunk-DJMFXNR4.js");
65
+ var import_chunk_74LUB4XX = require("./chunk-74LUB4XX.js");
65
66
  var import_chunk_TWPTG4XS = require("./chunk-TWPTG4XS.js");
66
67
  var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
67
68
  var import_chunk_2ESYSVXG = require("./chunk-2ESYSVXG.js");
@@ -69,7 +70,7 @@ var import_config = require("@prisma/config");
69
70
  var import_debug = __toESM(require("@prisma/debug"));
70
71
  var import_engines_version = require("@prisma/engines-version");
71
72
  var import_internals = require("@prisma/internals");
72
- var version = "6.6.0-dev.27";
73
+ var version = "6.6.0-dev.29";
73
74
  process.on("uncaughtException", (e) => {
74
75
  console.log(e);
75
76
  });
@@ -91,17 +92,17 @@ var args = (0, import_internals.arg)(
91
92
  async function main() {
92
93
  const cli = import_chunk_NGQA5JTN.CLI.new({
93
94
  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()
95
+ dev: import_chunk_ZCR4PTT3.MigrateDev.new(),
96
+ status: import_chunk_BUAYZ4KA.MigrateStatus.new(),
97
+ resolve: import_chunk_HQJ7FIWN.MigrateResolve.new(),
98
+ reset: import_chunk_AM7BRZFD.MigrateReset.new(),
99
+ deploy: import_chunk_IRYXRMQC.MigrateDeploy.new(),
100
+ diff: import_chunk_WX6S3QMO.MigrateDiff.new()
100
101
  }),
101
102
  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(),
103
+ execute: import_chunk_LAEOX7QH.DbExecute.new(),
104
+ pull: import_chunk_SCH55BRJ.DbPull.new(),
105
+ push: import_chunk_63ZT25OL.DbPush.new(),
105
106
  // drop: DbDrop.new(),
106
107
  seed: import_chunk_B4SUSDC2.DbSeed.new()
107
108
  })
@@ -133,7 +134,7 @@ main().then((code) => {
133
134
  cliVersion: version,
134
135
  enginesVersion: import_engines_version.enginesVersion,
135
136
  command: commandArray.join(" "),
136
- getDatabaseVersionSafe: import_chunk_MKS2ZJJ5.getDatabaseVersionSafe
137
+ getDatabaseVersionSafe: import_chunk_MTJFLQI4.getDatabaseVersionSafe
137
138
  }).catch((e) => {
138
139
  if (import_debug.default.enabled("migrate")) {
139
140
  console.error((0, import_chunk_SKRR5WT4.red)((0, import_chunk_SKRR5WT4.bold)("Error: ")) + e.stack);
@@ -0,0 +1,62 @@
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_23DZXSTI_exports = {};
30
+ __export(chunk_23DZXSTI_exports, {
31
+ createMigration: () => createMigration,
32
+ writeMigrationLockfile: () => writeMigrationLockfile,
33
+ writeMigrationScript: () => writeMigrationScript
34
+ });
35
+ module.exports = __toCommonJS(chunk_23DZXSTI_exports);
36
+ var import_node_fs = __toESM(require("node:fs"));
37
+ var import_node_path = __toESM(require("node:path"));
38
+ async function createMigration({ baseDir, generatedMigrationName }) {
39
+ const directoryPath = import_node_path.default.join(baseDir, generatedMigrationName);
40
+ if (import_node_fs.default.existsSync(directoryPath)) {
41
+ throw new Error(`The migration directory already exists at ${directoryPath}`);
42
+ }
43
+ await import_node_fs.default.promises.mkdir(directoryPath, { recursive: true, mode: 511 });
44
+ return directoryPath;
45
+ }
46
+ async function writeMigrationScript({
47
+ baseDir,
48
+ extension,
49
+ migrationName,
50
+ script
51
+ }) {
52
+ await import_node_fs.default.promises.writeFile(import_node_path.default.join(baseDir, migrationName, `migration.${extension}`), script, {
53
+ encoding: "utf-8"
54
+ });
55
+ }
56
+ async function writeMigrationLockfile({ baseDir, connectorType, lockfile }) {
57
+ const lockfileContent = `# Please do not edit this file manually
58
+ # It should be added in your version-control system (e.g., Git)
59
+ provider = "${connectorType}"
60
+ `;
61
+ await import_node_fs.default.promises.writeFile(import_node_path.default.join(baseDir, lockfile.path), lockfileContent, { encoding: "utf-8" });
62
+ }
@@ -26,13 +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_VVP3QZ7Q_exports = {};
30
- __export2(chunk_VVP3QZ7Q_exports, {
29
+ var chunk_5Q5BJS5B_exports = {};
30
+ __export2(chunk_5Q5BJS5B_exports, {
31
31
  Migrate: () => Migrate
32
32
  });
33
- module.exports = __toCommonJS(chunk_VVP3QZ7Q_exports);
33
+ module.exports = __toCommonJS(chunk_5Q5BJS5B_exports);
34
+ var import_chunk_V6PVGSDJ = require("./chunk-V6PVGSDJ.js");
35
+ var import_chunk_23DZXSTI = require("./chunk-23DZXSTI.js");
34
36
  var import_chunk_URKH6SE2 = require("./chunk-URKH6SE2.js");
35
- var import_chunk_K43RXWQY = require("./chunk-K43RXWQY.js");
37
+ var import_chunk_GHZAN2PG = require("./chunk-GHZAN2PG.js");
36
38
  var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
37
39
  var import_chunk_2ESYSVXG = require("./chunk-2ESYSVXG.js");
38
40
  var import_engines_version = require("@prisma/engines-version");
@@ -733,12 +735,12 @@ var Migrate = class {
733
735
  if (schemaPath) {
734
736
  this.schemaPath = import_path.default.resolve(process.cwd(), schemaPath);
735
737
  this.migrationsDirectoryPath = import_path.default.join(import_path.default.dirname(this.schemaPath), "migrations");
736
- this.engine = new import_chunk_K43RXWQY.SchemaEngine({
738
+ this.engine = new import_chunk_GHZAN2PG.SchemaEngine({
737
739
  schemaPath: this.schemaPath,
738
740
  enabledPreviewFeatures
739
741
  });
740
742
  } else {
741
- this.engine = new import_chunk_K43RXWQY.SchemaEngine({
743
+ this.engine = new import_chunk_GHZAN2PG.SchemaEngine({
742
744
  enabledPreviewFeatures
743
745
  });
744
746
  }
@@ -753,34 +755,73 @@ var Migrate = class {
753
755
  reset() {
754
756
  return this.engine.reset();
755
757
  }
756
- createMigration(params) {
757
- return this.engine.createMigration(params);
758
+ async createMigration(params) {
759
+ if (!this.migrationsDirectoryPath) throw new Error("this.migrationsDirectoryPath is undefined");
760
+ const migrationsList = await (0, import_chunk_V6PVGSDJ.listMigrations)(this.migrationsDirectoryPath);
761
+ const { connectorType, generatedMigrationName, extension, migrationScript } = await this.engine.createMigration({
762
+ ...params,
763
+ migrationsList
764
+ });
765
+ const { baseDir, lockfile } = migrationsList;
766
+ if (migrationScript === null) {
767
+ return {
768
+ generatedMigrationName: void 0
769
+ };
770
+ }
771
+ const directoryPath = await (0, import_chunk_23DZXSTI.createMigration)({
772
+ baseDir,
773
+ generatedMigrationName
774
+ }).catch((e) => {
775
+ throw new Error(`Failed to create a new migration directory: ${e.message}`);
776
+ });
777
+ await (0, import_chunk_23DZXSTI.writeMigrationScript)({
778
+ baseDir,
779
+ extension,
780
+ migrationName: generatedMigrationName,
781
+ script: migrationScript
782
+ }).catch((e) => {
783
+ throw new Error(`Failed to write migration script to ${directoryPath}: ${e.message}`);
784
+ });
785
+ await (0, import_chunk_23DZXSTI.writeMigrationLockfile)({
786
+ baseDir,
787
+ connectorType,
788
+ lockfile
789
+ }).catch((e) => {
790
+ throw new Error(`Failed to write the migration lock file to ${baseDir}: ${e.message}`);
791
+ });
792
+ return {
793
+ generatedMigrationName
794
+ };
758
795
  }
759
- diagnoseMigrationHistory({
796
+ async diagnoseMigrationHistory({
760
797
  optInToShadowDatabase
761
798
  }) {
762
799
  if (!this.migrationsDirectoryPath) throw new Error("this.migrationsDirectoryPath is undefined");
800
+ const migrationsList = await (0, import_chunk_V6PVGSDJ.listMigrations)(this.migrationsDirectoryPath);
763
801
  return this.engine.diagnoseMigrationHistory({
764
- migrationsDirectoryPath: this.migrationsDirectoryPath,
802
+ migrationsList,
765
803
  optInToShadowDatabase
766
804
  });
767
805
  }
768
- listMigrationDirectories() {
806
+ async listMigrationDirectories() {
769
807
  if (!this.migrationsDirectoryPath) throw new Error("this.migrationsDirectoryPath is undefined");
770
- return this.engine.listMigrationDirectories({
771
- migrationsDirectoryPath: this.migrationsDirectoryPath
772
- });
808
+ const migrationsList = await (0, import_chunk_V6PVGSDJ.listMigrations)(this.migrationsDirectoryPath);
809
+ return {
810
+ migrations: migrationsList.migrationDirectories.map((dir) => dir.path)
811
+ };
773
812
  }
774
- devDiagnostic() {
813
+ async devDiagnostic() {
775
814
  if (!this.migrationsDirectoryPath) throw new Error("this.migrationsDirectoryPath is undefined");
815
+ const migrationsList = await (0, import_chunk_V6PVGSDJ.listMigrations)(this.migrationsDirectoryPath);
776
816
  return this.engine.devDiagnostic({
777
- migrationsDirectoryPath: this.migrationsDirectoryPath
817
+ migrationsList
778
818
  });
779
819
  }
780
820
  async markMigrationApplied({ migrationId }) {
781
821
  if (!this.migrationsDirectoryPath) throw new Error("this.migrationsDirectoryPath is undefined");
822
+ const migrationsList = await (0, import_chunk_V6PVGSDJ.listMigrations)(this.migrationsDirectoryPath);
782
823
  return await this.engine.markMigrationApplied({
783
- migrationsDirectoryPath: this.migrationsDirectoryPath,
824
+ migrationsList,
784
825
  migrationName: migrationId
785
826
  });
786
827
  }
@@ -789,17 +830,19 @@ var Migrate = class {
789
830
  migrationName: migrationId
790
831
  });
791
832
  }
792
- applyMigrations() {
833
+ async applyMigrations() {
793
834
  if (!this.migrationsDirectoryPath) throw new Error("this.migrationsDirectoryPath is undefined");
835
+ const migrationsList = await (0, import_chunk_V6PVGSDJ.listMigrations)(this.migrationsDirectoryPath);
794
836
  return this.engine.applyMigrations({
795
- migrationsDirectoryPath: this.migrationsDirectoryPath
837
+ migrationsList
796
838
  });
797
839
  }
798
840
  async evaluateDataLoss() {
799
841
  if (!this.migrationsDirectoryPath) throw new Error("this.migrationsDirectoryPath is undefined");
842
+ const migrationsList = await (0, import_chunk_V6PVGSDJ.listMigrations)(this.migrationsDirectoryPath);
800
843
  const schema = (0, import_internals.toSchemasContainer)((await this.getPrismaSchema()).schemas);
801
844
  return this.engine.evaluateDataLoss({
802
- migrationsDirectoryPath: this.migrationsDirectoryPath,
845
+ migrationsList,
803
846
  schema
804
847
  });
805
848
  }
@@ -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_63ZT25OL_exports = {};
30
+ __export(chunk_63ZT25OL_exports, {
31
31
  DbPush: () => DbPush
32
32
  });
33
- module.exports = __toCommonJS(chunk_YBNDKPPO_exports);
34
- var import_chunk_VVP3QZ7Q = require("./chunk-VVP3QZ7Q.js");
33
+ module.exports = __toCommonJS(chunk_63ZT25OL_exports);
34
+ var import_chunk_5Q5BJS5B = require("./chunk-5Q5BJS5B.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_5Q5BJS5B.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
+ }
@@ -16,12 +16,12 @@ 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_IWC5MH4R_exports = {};
20
- __export(chunk_IWC5MH4R_exports, {
19
+ var chunk_ABQZ5J74_exports = {};
20
+ __export(chunk_ABQZ5J74_exports, {
21
21
  introspectSql: () => introspectSql
22
22
  });
23
- module.exports = __toCommonJS(chunk_IWC5MH4R_exports);
24
- var import_chunk_K43RXWQY = require("./chunk-K43RXWQY.js");
23
+ module.exports = __toCommonJS(chunk_ABQZ5J74_exports);
24
+ var import_chunk_GHZAN2PG = require("./chunk-GHZAN2PG.js");
25
25
  var import_internals = require("@prisma/internals");
26
26
  var supportedProviders = ["postgresql", "cockroachdb", "mysql", "sqlite"];
27
27
  async function introspectSql(schemaPath, queries) {
@@ -41,7 +41,7 @@ async function introspectSql(schemaPath, queries) {
41
41
  if (!url) {
42
42
  throw new Error(`Could not get url from datasource ${firstDatasource.name} in ${schema.schemaPath}`);
43
43
  }
44
- const schemaEngine = new import_chunk_K43RXWQY.SchemaEngine({ schemaPath: schema.schemaPath });
44
+ const schemaEngine = new import_chunk_GHZAN2PG.SchemaEngine({ schemaPath: schema.schemaPath });
45
45
  const results = [];
46
46
  const errors = [];
47
47
  try {