@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
@@ -0,0 +1,889 @@
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 __export2 = (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_5Q5BJS5B_exports = {};
30
+ __export2(chunk_5Q5BJS5B_exports, {
31
+ Migrate: () => Migrate
32
+ });
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");
36
+ var import_chunk_URKH6SE2 = require("./chunk-URKH6SE2.js");
37
+ var import_chunk_GHZAN2PG = require("./chunk-GHZAN2PG.js");
38
+ var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
39
+ var import_chunk_2ESYSVXG = require("./chunk-2ESYSVXG.js");
40
+ var import_engines_version = require("@prisma/engines-version");
41
+ var import_internals = require("@prisma/internals");
42
+ var import_node_process = __toESM(require("node:process"));
43
+ var import_node_process2 = __toESM(require("node:process"));
44
+ var import_path = __toESM(require("path"));
45
+ var base_exports = {};
46
+ (0, import_chunk_2ESYSVXG.__export)(base_exports, {
47
+ beep: () => beep,
48
+ clearScreen: () => clearScreen,
49
+ clearTerminal: () => clearTerminal,
50
+ cursorBackward: () => cursorBackward,
51
+ cursorDown: () => cursorDown,
52
+ cursorForward: () => cursorForward,
53
+ cursorGetPosition: () => cursorGetPosition,
54
+ cursorHide: () => cursorHide,
55
+ cursorLeft: () => cursorLeft,
56
+ cursorMove: () => cursorMove,
57
+ cursorNextLine: () => cursorNextLine,
58
+ cursorPrevLine: () => cursorPrevLine,
59
+ cursorRestorePosition: () => cursorRestorePosition,
60
+ cursorSavePosition: () => cursorSavePosition,
61
+ cursorShow: () => cursorShow,
62
+ cursorTo: () => cursorTo,
63
+ cursorUp: () => cursorUp,
64
+ enterAlternativeScreen: () => enterAlternativeScreen,
65
+ eraseDown: () => eraseDown,
66
+ eraseEndLine: () => eraseEndLine,
67
+ eraseLine: () => eraseLine,
68
+ eraseLines: () => eraseLines,
69
+ eraseScreen: () => eraseScreen,
70
+ eraseStartLine: () => eraseStartLine,
71
+ eraseUp: () => eraseUp,
72
+ exitAlternativeScreen: () => exitAlternativeScreen,
73
+ iTerm: () => iTerm,
74
+ image: () => image,
75
+ link: () => link,
76
+ scrollDown: () => scrollDown,
77
+ scrollUp: () => scrollUp
78
+ });
79
+ var isBrowser = globalThis.window?.document !== void 0;
80
+ var isNode = globalThis.process?.versions?.node !== void 0;
81
+ var isBun = globalThis.process?.versions?.bun !== void 0;
82
+ var isDeno = globalThis.Deno?.version?.deno !== void 0;
83
+ var isElectron = globalThis.process?.versions?.electron !== void 0;
84
+ var isJsDom = globalThis.navigator?.userAgent?.includes("jsdom") === true;
85
+ var isWebWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
86
+ var isDedicatedWorker = typeof DedicatedWorkerGlobalScope !== "undefined" && globalThis instanceof DedicatedWorkerGlobalScope;
87
+ var isSharedWorker = typeof SharedWorkerGlobalScope !== "undefined" && globalThis instanceof SharedWorkerGlobalScope;
88
+ var isServiceWorker = typeof ServiceWorkerGlobalScope !== "undefined" && globalThis instanceof ServiceWorkerGlobalScope;
89
+ var platform = globalThis.navigator?.userAgentData?.platform;
90
+ var isMacOs = platform === "macOS" || globalThis.navigator?.platform === "MacIntel" || globalThis.navigator?.userAgent?.includes(" Mac ") === true || globalThis.process?.platform === "darwin";
91
+ var isWindows = platform === "Windows" || globalThis.navigator?.platform === "Win32" || globalThis.process?.platform === "win32";
92
+ var isLinux = platform === "Linux" || globalThis.navigator?.platform?.startsWith("Linux") === true || globalThis.navigator?.userAgent?.includes(" Linux ") === true || globalThis.process?.platform === "linux";
93
+ var isIos = platform === "iOS" || globalThis.navigator?.platform === "MacIntel" && globalThis.navigator?.maxTouchPoints > 1 || /iPad|iPhone|iPod/.test(globalThis.navigator?.platform);
94
+ var isAndroid = platform === "Android" || globalThis.navigator?.platform === "Android" || globalThis.navigator?.userAgent?.includes(" Android ") === true || globalThis.process?.platform === "android";
95
+ var ESC = "\x1B[";
96
+ var OSC = "\x1B]";
97
+ var BEL = "\x07";
98
+ var SEP = ";";
99
+ var isTerminalApp = !isBrowser && import_node_process2.default.env.TERM_PROGRAM === "Apple_Terminal";
100
+ var isWindows2 = !isBrowser && import_node_process2.default.platform === "win32";
101
+ var cwdFunction = isBrowser ? () => {
102
+ throw new Error("`process.cwd()` only works in Node.js, not the browser.");
103
+ } : import_node_process2.default.cwd;
104
+ var cursorTo = (x, y) => {
105
+ if (typeof x !== "number") {
106
+ throw new TypeError("The `x` argument is required");
107
+ }
108
+ if (typeof y !== "number") {
109
+ return ESC + (x + 1) + "G";
110
+ }
111
+ return ESC + (y + 1) + SEP + (x + 1) + "H";
112
+ };
113
+ var cursorMove = (x, y) => {
114
+ if (typeof x !== "number") {
115
+ throw new TypeError("The `x` argument is required");
116
+ }
117
+ let returnValue = "";
118
+ if (x < 0) {
119
+ returnValue += ESC + -x + "D";
120
+ } else if (x > 0) {
121
+ returnValue += ESC + x + "C";
122
+ }
123
+ if (y < 0) {
124
+ returnValue += ESC + -y + "A";
125
+ } else if (y > 0) {
126
+ returnValue += ESC + y + "B";
127
+ }
128
+ return returnValue;
129
+ };
130
+ var cursorUp = (count = 1) => ESC + count + "A";
131
+ var cursorDown = (count = 1) => ESC + count + "B";
132
+ var cursorForward = (count = 1) => ESC + count + "C";
133
+ var cursorBackward = (count = 1) => ESC + count + "D";
134
+ var cursorLeft = ESC + "G";
135
+ var cursorSavePosition = isTerminalApp ? "\x1B7" : ESC + "s";
136
+ var cursorRestorePosition = isTerminalApp ? "\x1B8" : ESC + "u";
137
+ var cursorGetPosition = ESC + "6n";
138
+ var cursorNextLine = ESC + "E";
139
+ var cursorPrevLine = ESC + "F";
140
+ var cursorHide = ESC + "?25l";
141
+ var cursorShow = ESC + "?25h";
142
+ var eraseLines = (count) => {
143
+ let clear = "";
144
+ for (let i = 0; i < count; i++) {
145
+ clear += eraseLine + (i < count - 1 ? cursorUp() : "");
146
+ }
147
+ if (count) {
148
+ clear += cursorLeft;
149
+ }
150
+ return clear;
151
+ };
152
+ var eraseEndLine = ESC + "K";
153
+ var eraseStartLine = ESC + "1K";
154
+ var eraseLine = ESC + "2K";
155
+ var eraseDown = ESC + "J";
156
+ var eraseUp = ESC + "1J";
157
+ var eraseScreen = ESC + "2J";
158
+ var scrollUp = ESC + "S";
159
+ var scrollDown = ESC + "T";
160
+ var clearScreen = "\x1Bc";
161
+ var clearTerminal = isWindows2 ? `${eraseScreen}${ESC}0f` : `${eraseScreen}${ESC}3J${ESC}H`;
162
+ var enterAlternativeScreen = ESC + "?1049h";
163
+ var exitAlternativeScreen = ESC + "?1049l";
164
+ var beep = BEL;
165
+ var link = (text, url) => [
166
+ OSC,
167
+ "8",
168
+ SEP,
169
+ SEP,
170
+ url,
171
+ BEL,
172
+ text,
173
+ OSC,
174
+ "8",
175
+ SEP,
176
+ SEP,
177
+ BEL
178
+ ].join("");
179
+ var image = (data, options = {}) => {
180
+ let returnValue = `${OSC}1337;File=inline=1`;
181
+ if (options.width) {
182
+ returnValue += `;width=${options.width}`;
183
+ }
184
+ if (options.height) {
185
+ returnValue += `;height=${options.height}`;
186
+ }
187
+ if (options.preserveAspectRatio === false) {
188
+ returnValue += ";preserveAspectRatio=0";
189
+ }
190
+ return returnValue + ":" + Buffer.from(data).toString("base64") + BEL;
191
+ };
192
+ var iTerm = {
193
+ setCwd: (cwd = cwdFunction()) => `${OSC}50;CurrentDir=${cwd}${BEL}`,
194
+ annotation(message, options = {}) {
195
+ let returnValue = `${OSC}1337;`;
196
+ const hasX = options.x !== void 0;
197
+ const hasY = options.y !== void 0;
198
+ if ((hasX || hasY) && !(hasX && hasY && options.length !== void 0)) {
199
+ throw new Error("`x`, `y` and `length` must be defined when `x` or `y` is defined");
200
+ }
201
+ message = message.replaceAll("|", "");
202
+ returnValue += options.isHidden ? "AddHiddenAnnotation=" : "AddAnnotation=";
203
+ if (options.length > 0) {
204
+ returnValue += (hasX ? [message, options.length, options.x, options.y] : [options.length, message]).join("|");
205
+ } else {
206
+ returnValue += message;
207
+ }
208
+ return returnValue + BEL;
209
+ }
210
+ };
211
+ var ANSI_BACKGROUND_OFFSET = 10;
212
+ var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
213
+ var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
214
+ var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
215
+ var styles = {
216
+ modifier: {
217
+ reset: [0, 0],
218
+ // 21 isn't widely supported and 22 does the same thing
219
+ bold: [1, 22],
220
+ dim: [2, 22],
221
+ italic: [3, 23],
222
+ underline: [4, 24],
223
+ overline: [53, 55],
224
+ inverse: [7, 27],
225
+ hidden: [8, 28],
226
+ strikethrough: [9, 29]
227
+ },
228
+ color: {
229
+ black: [30, 39],
230
+ red: [31, 39],
231
+ green: [32, 39],
232
+ yellow: [33, 39],
233
+ blue: [34, 39],
234
+ magenta: [35, 39],
235
+ cyan: [36, 39],
236
+ white: [37, 39],
237
+ // Bright color
238
+ blackBright: [90, 39],
239
+ gray: [90, 39],
240
+ // Alias of `blackBright`
241
+ grey: [90, 39],
242
+ // Alias of `blackBright`
243
+ redBright: [91, 39],
244
+ greenBright: [92, 39],
245
+ yellowBright: [93, 39],
246
+ blueBright: [94, 39],
247
+ magentaBright: [95, 39],
248
+ cyanBright: [96, 39],
249
+ whiteBright: [97, 39]
250
+ },
251
+ bgColor: {
252
+ bgBlack: [40, 49],
253
+ bgRed: [41, 49],
254
+ bgGreen: [42, 49],
255
+ bgYellow: [43, 49],
256
+ bgBlue: [44, 49],
257
+ bgMagenta: [45, 49],
258
+ bgCyan: [46, 49],
259
+ bgWhite: [47, 49],
260
+ // Bright color
261
+ bgBlackBright: [100, 49],
262
+ bgGray: [100, 49],
263
+ // Alias of `bgBlackBright`
264
+ bgGrey: [100, 49],
265
+ // Alias of `bgBlackBright`
266
+ bgRedBright: [101, 49],
267
+ bgGreenBright: [102, 49],
268
+ bgYellowBright: [103, 49],
269
+ bgBlueBright: [104, 49],
270
+ bgMagentaBright: [105, 49],
271
+ bgCyanBright: [106, 49],
272
+ bgWhiteBright: [107, 49]
273
+ }
274
+ };
275
+ var modifierNames = Object.keys(styles.modifier);
276
+ var foregroundColorNames = Object.keys(styles.color);
277
+ var backgroundColorNames = Object.keys(styles.bgColor);
278
+ var colorNames = [...foregroundColorNames, ...backgroundColorNames];
279
+ function assembleStyles() {
280
+ const codes = /* @__PURE__ */ new Map();
281
+ for (const [groupName, group] of Object.entries(styles)) {
282
+ for (const [styleName, style] of Object.entries(group)) {
283
+ styles[styleName] = {
284
+ open: `\x1B[${style[0]}m`,
285
+ close: `\x1B[${style[1]}m`
286
+ };
287
+ group[styleName] = styles[styleName];
288
+ codes.set(style[0], style[1]);
289
+ }
290
+ Object.defineProperty(styles, groupName, {
291
+ value: group,
292
+ enumerable: false
293
+ });
294
+ }
295
+ Object.defineProperty(styles, "codes", {
296
+ value: codes,
297
+ enumerable: false
298
+ });
299
+ styles.color.close = "\x1B[39m";
300
+ styles.bgColor.close = "\x1B[49m";
301
+ styles.color.ansi = wrapAnsi16();
302
+ styles.color.ansi256 = wrapAnsi256();
303
+ styles.color.ansi16m = wrapAnsi16m();
304
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
305
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
306
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
307
+ Object.defineProperties(styles, {
308
+ rgbToAnsi256: {
309
+ value: (red, green, blue) => {
310
+ if (red === green && green === blue) {
311
+ if (red < 8) {
312
+ return 16;
313
+ }
314
+ if (red > 248) {
315
+ return 231;
316
+ }
317
+ return Math.round((red - 8) / 247 * 24) + 232;
318
+ }
319
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
320
+ },
321
+ enumerable: false
322
+ },
323
+ hexToRgb: {
324
+ value: (hex) => {
325
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
326
+ if (!matches) {
327
+ return [0, 0, 0];
328
+ }
329
+ let [colorString] = matches;
330
+ if (colorString.length === 3) {
331
+ colorString = [...colorString].map((character) => character + character).join("");
332
+ }
333
+ const integer = Number.parseInt(colorString, 16);
334
+ return [
335
+ /* eslint-disable no-bitwise */
336
+ integer >> 16 & 255,
337
+ integer >> 8 & 255,
338
+ integer & 255
339
+ /* eslint-enable no-bitwise */
340
+ ];
341
+ },
342
+ enumerable: false
343
+ },
344
+ hexToAnsi256: {
345
+ value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
346
+ enumerable: false
347
+ },
348
+ ansi256ToAnsi: {
349
+ value: (code) => {
350
+ if (code < 8) {
351
+ return 30 + code;
352
+ }
353
+ if (code < 16) {
354
+ return 90 + (code - 8);
355
+ }
356
+ let red;
357
+ let green;
358
+ let blue;
359
+ if (code >= 232) {
360
+ red = ((code - 232) * 10 + 8) / 255;
361
+ green = red;
362
+ blue = red;
363
+ } else {
364
+ code -= 16;
365
+ const remainder = code % 36;
366
+ red = Math.floor(code / 36) / 5;
367
+ green = Math.floor(remainder / 6) / 5;
368
+ blue = remainder % 6 / 5;
369
+ }
370
+ const value = Math.max(red, green, blue) * 2;
371
+ if (value === 0) {
372
+ return 30;
373
+ }
374
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
375
+ if (value === 2) {
376
+ result += 60;
377
+ }
378
+ return result;
379
+ },
380
+ enumerable: false
381
+ },
382
+ rgbToAnsi: {
383
+ value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
384
+ enumerable: false
385
+ },
386
+ hexToAnsi: {
387
+ value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
388
+ enumerable: false
389
+ }
390
+ });
391
+ return styles;
392
+ }
393
+ var ansiStyles = assembleStyles();
394
+ var ansi_styles_default = ansiStyles;
395
+ var ESCAPES = /* @__PURE__ */ new Set([
396
+ "\x1B",
397
+ "\x9B"
398
+ ]);
399
+ var END_CODE = 39;
400
+ var ANSI_ESCAPE_BELL = "\x07";
401
+ var ANSI_CSI = "[";
402
+ var ANSI_OSC = "]";
403
+ var ANSI_SGR_TERMINATOR = "m";
404
+ var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
405
+ var wrapAnsiCode = (code) => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
406
+ var wrapAnsiHyperlink = (url) => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
407
+ var wordLengths = (string) => string.split(" ").map((character) => (0, import_chunk_URKH6SE2.stringWidth)(character));
408
+ var wrapWord = (rows, word, columns) => {
409
+ const characters = [...word];
410
+ let isInsideEscape = false;
411
+ let isInsideLinkEscape = false;
412
+ let visible = (0, import_chunk_URKH6SE2.stringWidth)((0, import_chunk_URKH6SE2.stripAnsi)(rows.at(-1)));
413
+ for (const [index, character] of characters.entries()) {
414
+ const characterLength = (0, import_chunk_URKH6SE2.stringWidth)(character);
415
+ if (visible + characterLength <= columns) {
416
+ rows[rows.length - 1] += character;
417
+ } else {
418
+ rows.push(character);
419
+ visible = 0;
420
+ }
421
+ if (ESCAPES.has(character)) {
422
+ isInsideEscape = true;
423
+ const ansiEscapeLinkCandidate = characters.slice(index + 1, index + 1 + ANSI_ESCAPE_LINK.length).join("");
424
+ isInsideLinkEscape = ansiEscapeLinkCandidate === ANSI_ESCAPE_LINK;
425
+ }
426
+ if (isInsideEscape) {
427
+ if (isInsideLinkEscape) {
428
+ if (character === ANSI_ESCAPE_BELL) {
429
+ isInsideEscape = false;
430
+ isInsideLinkEscape = false;
431
+ }
432
+ } else if (character === ANSI_SGR_TERMINATOR) {
433
+ isInsideEscape = false;
434
+ }
435
+ continue;
436
+ }
437
+ visible += characterLength;
438
+ if (visible === columns && index < characters.length - 1) {
439
+ rows.push("");
440
+ visible = 0;
441
+ }
442
+ }
443
+ if (!visible && rows.at(-1).length > 0 && rows.length > 1) {
444
+ rows[rows.length - 2] += rows.pop();
445
+ }
446
+ };
447
+ var stringVisibleTrimSpacesRight = (string) => {
448
+ const words = string.split(" ");
449
+ let last = words.length;
450
+ while (last > 0) {
451
+ if ((0, import_chunk_URKH6SE2.stringWidth)(words[last - 1]) > 0) {
452
+ break;
453
+ }
454
+ last--;
455
+ }
456
+ if (last === words.length) {
457
+ return string;
458
+ }
459
+ return words.slice(0, last).join(" ") + words.slice(last).join("");
460
+ };
461
+ var exec = (string, columns, options = {}) => {
462
+ if (options.trim !== false && string.trim() === "") {
463
+ return "";
464
+ }
465
+ let returnValue = "";
466
+ let escapeCode;
467
+ let escapeUrl;
468
+ const lengths = wordLengths(string);
469
+ let rows = [""];
470
+ for (const [index, word] of string.split(" ").entries()) {
471
+ if (options.trim !== false) {
472
+ rows[rows.length - 1] = rows.at(-1).trimStart();
473
+ }
474
+ let rowLength = (0, import_chunk_URKH6SE2.stringWidth)(rows.at(-1));
475
+ if (index !== 0) {
476
+ if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
477
+ rows.push("");
478
+ rowLength = 0;
479
+ }
480
+ if (rowLength > 0 || options.trim === false) {
481
+ rows[rows.length - 1] += " ";
482
+ rowLength++;
483
+ }
484
+ }
485
+ if (options.hard && lengths[index] > columns) {
486
+ const remainingColumns = columns - rowLength;
487
+ const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
488
+ const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
489
+ if (breaksStartingNextLine < breaksStartingThisLine) {
490
+ rows.push("");
491
+ }
492
+ wrapWord(rows, word, columns);
493
+ continue;
494
+ }
495
+ if (rowLength + lengths[index] > columns && rowLength > 0 && lengths[index] > 0) {
496
+ if (options.wordWrap === false && rowLength < columns) {
497
+ wrapWord(rows, word, columns);
498
+ continue;
499
+ }
500
+ rows.push("");
501
+ }
502
+ if (rowLength + lengths[index] > columns && options.wordWrap === false) {
503
+ wrapWord(rows, word, columns);
504
+ continue;
505
+ }
506
+ rows[rows.length - 1] += word;
507
+ }
508
+ if (options.trim !== false) {
509
+ rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
510
+ }
511
+ const preString = rows.join("\n");
512
+ const pre = [...preString];
513
+ let preStringIndex = 0;
514
+ for (const [index, character] of pre.entries()) {
515
+ returnValue += character;
516
+ if (ESCAPES.has(character)) {
517
+ const { groups } = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`).exec(preString.slice(preStringIndex)) || { groups: {} };
518
+ if (groups.code !== void 0) {
519
+ const code2 = Number.parseFloat(groups.code);
520
+ escapeCode = code2 === END_CODE ? void 0 : code2;
521
+ } else if (groups.uri !== void 0) {
522
+ escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
523
+ }
524
+ }
525
+ const code = ansi_styles_default.codes.get(Number(escapeCode));
526
+ if (pre[index + 1] === "\n") {
527
+ if (escapeUrl) {
528
+ returnValue += wrapAnsiHyperlink("");
529
+ }
530
+ if (escapeCode && code) {
531
+ returnValue += wrapAnsiCode(code);
532
+ }
533
+ } else if (character === "\n") {
534
+ if (escapeCode && code) {
535
+ returnValue += wrapAnsiCode(escapeCode);
536
+ }
537
+ if (escapeUrl) {
538
+ returnValue += wrapAnsiHyperlink(escapeUrl);
539
+ }
540
+ }
541
+ preStringIndex += character.length;
542
+ }
543
+ return returnValue;
544
+ };
545
+ function wrapAnsi(string, columns, options) {
546
+ return String(string).normalize().replaceAll("\r\n", "\n").split("\n").map((line) => exec(line, columns, options)).join("\n");
547
+ }
548
+ function isFullwidthCodePoint(codePoint) {
549
+ if (!Number.isInteger(codePoint)) {
550
+ return false;
551
+ }
552
+ return (0, import_chunk_URKH6SE2.eastAsianWidth)(codePoint) === 2;
553
+ }
554
+ var ESCAPES2 = /* @__PURE__ */ new Set([27, 155]);
555
+ var CODE_POINT_0 = "0".codePointAt(0);
556
+ var CODE_POINT_9 = "9".codePointAt(0);
557
+ var endCodesSet = /* @__PURE__ */ new Set();
558
+ var endCodesMap = /* @__PURE__ */ new Map();
559
+ for (const [start, end] of ansi_styles_default.codes) {
560
+ endCodesSet.add(ansi_styles_default.color.ansi(end));
561
+ endCodesMap.set(ansi_styles_default.color.ansi(start), ansi_styles_default.color.ansi(end));
562
+ }
563
+ function getEndCode(code) {
564
+ if (endCodesSet.has(code)) {
565
+ return code;
566
+ }
567
+ if (endCodesMap.has(code)) {
568
+ return endCodesMap.get(code);
569
+ }
570
+ code = code.slice(2);
571
+ if (code.includes(";")) {
572
+ code = code[0] + "0";
573
+ }
574
+ const returnValue = ansi_styles_default.codes.get(Number.parseInt(code, 10));
575
+ if (returnValue) {
576
+ return ansi_styles_default.color.ansi(returnValue);
577
+ }
578
+ return ansi_styles_default.reset.open;
579
+ }
580
+ function findNumberIndex(string) {
581
+ for (let index = 0; index < string.length; index++) {
582
+ const codePoint = string.codePointAt(index);
583
+ if (codePoint >= CODE_POINT_0 && codePoint <= CODE_POINT_9) {
584
+ return index;
585
+ }
586
+ }
587
+ return -1;
588
+ }
589
+ function parseAnsiCode(string, offset) {
590
+ string = string.slice(offset, offset + 19);
591
+ const startIndex = findNumberIndex(string);
592
+ if (startIndex !== -1) {
593
+ let endIndex = string.indexOf("m", startIndex);
594
+ if (endIndex === -1) {
595
+ endIndex = string.length;
596
+ }
597
+ return string.slice(0, endIndex + 1);
598
+ }
599
+ }
600
+ function tokenize(string, endCharacter = Number.POSITIVE_INFINITY) {
601
+ const returnValue = [];
602
+ let index = 0;
603
+ let visibleCount = 0;
604
+ while (index < string.length) {
605
+ const codePoint = string.codePointAt(index);
606
+ if (ESCAPES2.has(codePoint)) {
607
+ const code = parseAnsiCode(string, index);
608
+ if (code) {
609
+ returnValue.push({
610
+ type: "ansi",
611
+ code,
612
+ endCode: getEndCode(code)
613
+ });
614
+ index += code.length;
615
+ continue;
616
+ }
617
+ }
618
+ const isFullWidth = isFullwidthCodePoint(codePoint);
619
+ const character = String.fromCodePoint(codePoint);
620
+ returnValue.push({
621
+ type: "character",
622
+ value: character,
623
+ isFullWidth
624
+ });
625
+ index += character.length;
626
+ visibleCount += isFullWidth ? 2 : character.length;
627
+ if (visibleCount >= endCharacter) {
628
+ break;
629
+ }
630
+ }
631
+ return returnValue;
632
+ }
633
+ function reduceAnsiCodes(codes) {
634
+ let returnValue = [];
635
+ for (const code of codes) {
636
+ if (code.code === ansi_styles_default.reset.open) {
637
+ returnValue = [];
638
+ } else if (endCodesSet.has(code.code)) {
639
+ returnValue = returnValue.filter((returnValueCode) => returnValueCode.endCode !== code.code);
640
+ } else {
641
+ returnValue = returnValue.filter((returnValueCode) => returnValueCode.endCode !== code.endCode);
642
+ returnValue.push(code);
643
+ }
644
+ }
645
+ return returnValue;
646
+ }
647
+ function undoAnsiCodes(codes) {
648
+ const reduced = reduceAnsiCodes(codes);
649
+ const endCodes = reduced.map(({ endCode }) => endCode);
650
+ return endCodes.reverse().join("");
651
+ }
652
+ function sliceAnsi(string, start, end) {
653
+ const tokens = tokenize(string, end);
654
+ let activeCodes = [];
655
+ let position = 0;
656
+ let returnValue = "";
657
+ let include = false;
658
+ for (const token of tokens) {
659
+ if (end !== void 0 && position >= end) {
660
+ break;
661
+ }
662
+ if (token.type === "ansi") {
663
+ activeCodes.push(token);
664
+ if (include) {
665
+ returnValue += token.code;
666
+ }
667
+ } else {
668
+ if (!include && position >= start) {
669
+ include = true;
670
+ activeCodes = reduceAnsiCodes(activeCodes);
671
+ returnValue = activeCodes.map(({ code }) => code).join("");
672
+ }
673
+ if (include) {
674
+ returnValue += token.value;
675
+ }
676
+ position += token.isFullWidth ? 2 : token.value.length;
677
+ }
678
+ }
679
+ returnValue += undoAnsiCodes(activeCodes);
680
+ return returnValue;
681
+ }
682
+ var defaultTerminalHeight = 24;
683
+ var getWidth = ({ columns = 80 }) => columns;
684
+ var fitToTerminalHeight = (stream, text) => {
685
+ const terminalHeight = stream.rows ?? defaultTerminalHeight;
686
+ const lines = text.split("\n");
687
+ const toRemove = Math.max(0, lines.length - terminalHeight);
688
+ return toRemove ? sliceAnsi(text, (0, import_chunk_URKH6SE2.stripAnsi)(lines.slice(0, toRemove).join("\n")).length + 1) : text;
689
+ };
690
+ function createLogUpdate(stream, { showCursor = false } = {}) {
691
+ let previousLineCount = 0;
692
+ let previousWidth = getWidth(stream);
693
+ let previousOutput = "";
694
+ const reset = () => {
695
+ previousOutput = "";
696
+ previousWidth = getWidth(stream);
697
+ previousLineCount = 0;
698
+ };
699
+ const render = (...arguments_) => {
700
+ if (!showCursor) {
701
+ import_chunk_URKH6SE2.cli_cursor_default.hide();
702
+ }
703
+ let output = fitToTerminalHeight(stream, arguments_.join(" ") + "\n");
704
+ const width = getWidth(stream);
705
+ if (output === previousOutput && previousWidth === width) {
706
+ return;
707
+ }
708
+ previousOutput = output;
709
+ previousWidth = width;
710
+ output = wrapAnsi(output, width, { trim: false, hard: true, wordWrap: false });
711
+ stream.write(base_exports.eraseLines(previousLineCount) + output);
712
+ previousLineCount = output.split("\n").length;
713
+ };
714
+ render.clear = () => {
715
+ stream.write(base_exports.eraseLines(previousLineCount));
716
+ reset();
717
+ };
718
+ render.done = () => {
719
+ reset();
720
+ if (!showCursor) {
721
+ import_chunk_URKH6SE2.cli_cursor_default.show();
722
+ }
723
+ };
724
+ return render;
725
+ }
726
+ var logUpdate = createLogUpdate(import_node_process.default.stdout);
727
+ var log_update_default = logUpdate;
728
+ var logUpdateStderr = createLogUpdate(import_node_process.default.stderr);
729
+ var packageJson = eval(`require('../package.json')`);
730
+ var Migrate = class {
731
+ engine;
732
+ schemaPath;
733
+ migrationsDirectoryPath;
734
+ constructor(schemaPath, enabledPreviewFeatures) {
735
+ if (schemaPath) {
736
+ this.schemaPath = import_path.default.resolve(process.cwd(), schemaPath);
737
+ this.migrationsDirectoryPath = import_path.default.join(import_path.default.dirname(this.schemaPath), "migrations");
738
+ this.engine = new import_chunk_GHZAN2PG.SchemaEngine({
739
+ schemaPath: this.schemaPath,
740
+ enabledPreviewFeatures
741
+ });
742
+ } else {
743
+ this.engine = new import_chunk_GHZAN2PG.SchemaEngine({
744
+ enabledPreviewFeatures
745
+ });
746
+ }
747
+ }
748
+ stop() {
749
+ this.engine.stop();
750
+ }
751
+ getPrismaSchema() {
752
+ if (!this.schemaPath) throw new Error("this.schemaPath is undefined");
753
+ return (0, import_internals.getSchemaWithPath)(this.schemaPath);
754
+ }
755
+ reset() {
756
+ return this.engine.reset();
757
+ }
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
+ };
795
+ }
796
+ async diagnoseMigrationHistory({
797
+ optInToShadowDatabase
798
+ }) {
799
+ if (!this.migrationsDirectoryPath) throw new Error("this.migrationsDirectoryPath is undefined");
800
+ const migrationsList = await (0, import_chunk_V6PVGSDJ.listMigrations)(this.migrationsDirectoryPath);
801
+ return this.engine.diagnoseMigrationHistory({
802
+ migrationsList,
803
+ optInToShadowDatabase
804
+ });
805
+ }
806
+ async listMigrationDirectories() {
807
+ if (!this.migrationsDirectoryPath) throw new Error("this.migrationsDirectoryPath is undefined");
808
+ const migrationsList = await (0, import_chunk_V6PVGSDJ.listMigrations)(this.migrationsDirectoryPath);
809
+ return {
810
+ migrations: migrationsList.migrationDirectories.map((dir) => dir.path)
811
+ };
812
+ }
813
+ async devDiagnostic() {
814
+ if (!this.migrationsDirectoryPath) throw new Error("this.migrationsDirectoryPath is undefined");
815
+ const migrationsList = await (0, import_chunk_V6PVGSDJ.listMigrations)(this.migrationsDirectoryPath);
816
+ return this.engine.devDiagnostic({
817
+ migrationsList
818
+ });
819
+ }
820
+ async markMigrationApplied({ migrationId }) {
821
+ if (!this.migrationsDirectoryPath) throw new Error("this.migrationsDirectoryPath is undefined");
822
+ const migrationsList = await (0, import_chunk_V6PVGSDJ.listMigrations)(this.migrationsDirectoryPath);
823
+ return await this.engine.markMigrationApplied({
824
+ migrationsList,
825
+ migrationName: migrationId
826
+ });
827
+ }
828
+ markMigrationRolledBack({ migrationId }) {
829
+ return this.engine.markMigrationRolledBack({
830
+ migrationName: migrationId
831
+ });
832
+ }
833
+ async applyMigrations() {
834
+ if (!this.migrationsDirectoryPath) throw new Error("this.migrationsDirectoryPath is undefined");
835
+ const migrationsList = await (0, import_chunk_V6PVGSDJ.listMigrations)(this.migrationsDirectoryPath);
836
+ return this.engine.applyMigrations({
837
+ migrationsList
838
+ });
839
+ }
840
+ async evaluateDataLoss() {
841
+ if (!this.migrationsDirectoryPath) throw new Error("this.migrationsDirectoryPath is undefined");
842
+ const migrationsList = await (0, import_chunk_V6PVGSDJ.listMigrations)(this.migrationsDirectoryPath);
843
+ const schema = (0, import_internals.toSchemasContainer)((await this.getPrismaSchema()).schemas);
844
+ return this.engine.evaluateDataLoss({
845
+ migrationsList,
846
+ schema
847
+ });
848
+ }
849
+ async push({ force = false }) {
850
+ const schema = (0, import_internals.toSchemasContainer)((await this.getPrismaSchema()).schemas);
851
+ const { warnings, unexecutable, executedSteps } = await this.engine.schemaPush({
852
+ force,
853
+ schema
854
+ });
855
+ return {
856
+ executedSteps,
857
+ warnings,
858
+ unexecutable
859
+ };
860
+ }
861
+ async tryToRunGenerate(datasourceInfo) {
862
+ if (!this.schemaPath) throw new Error("this.schemaPath is undefined");
863
+ const skipEngines = (0, import_internals.isPrismaPostgres)(datasourceInfo.url);
864
+ const message = [];
865
+ process.stdout.write("\n");
866
+ log_update_default(`Running generate... ${(0, import_chunk_SKRR5WT4.dim)("(Use --skip-generate to skip the generators)")}`);
867
+ const generators = await (0, import_internals.getGenerators)({
868
+ schemaPath: this.schemaPath,
869
+ printDownloadProgress: true,
870
+ version: import_engines_version.enginesVersion,
871
+ cliVersion: packageJson.version,
872
+ noEngine: skipEngines
873
+ });
874
+ for (const generator of generators) {
875
+ log_update_default(`Running generate... - ${generator.getPrettyName()}`);
876
+ const before = Math.round(performance.now());
877
+ try {
878
+ await generator.generate();
879
+ const after = Math.round(performance.now());
880
+ message.push((0, import_internals.getGeneratorSuccessMessage)(generator, after - before));
881
+ generator.stop();
882
+ } catch (e) {
883
+ message.push(`${e.message}`);
884
+ generator.stop();
885
+ }
886
+ }
887
+ log_update_default(message.join("\n"));
888
+ }
889
+ };