@prisma/migrate 6.5.0-dev.1 → 6.5.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CLI.js +3 -4
- package/dist/Migrate.js +6 -7
- package/dist/SchemaEngine.js +6 -7
- package/dist/bin.js +116 -146
- package/dist/{chunk-WOOPRG54.js → chunk-255BRND3.js} +7 -14
- package/dist/{chunk-75EIHNAH.js → chunk-2NMFKGXM.js} +5 -6
- package/dist/chunk-3WC4XD74.js +98 -0
- package/dist/chunk-4EV2RVXY.js +226 -0
- package/dist/{chunk-YWWOSXMY.js → chunk-4JQIX6O7.js} +7 -15
- package/dist/{chunk-M5YNQ2NP.js → chunk-6DFJIBJX.js} +5 -12
- package/dist/{chunk-SGCF5OHF.js → chunk-7CQBDP4H.js} +6 -13
- package/dist/{chunk-7IT2ZO3D.js → chunk-AHJ2N6BJ.js} +3 -9
- package/dist/chunk-C2PR6JQR.js +266 -0
- package/dist/chunk-CTPONE6G.js +65 -0
- package/dist/{chunk-DUCG3NRP.js → chunk-D74DU52C.js} +633 -806
- package/dist/{chunk-UVNSK22K.js → chunk-DDHPSYC4.js} +122 -130
- package/dist/{chunk-CUDKD32S.js → chunk-DIAO4W7O.js} +11 -17
- package/dist/{chunk-XJQP3B4W.js → chunk-DJMFXNR4.js} +7 -15
- package/dist/{chunk-YD7GG4WS.js → chunk-FRTPDRF2.js} +66 -74
- package/dist/chunk-HIFVDK2U.js +96 -0
- package/dist/chunk-I4EY55DC.js +195 -0
- package/dist/{chunk-WLJHGKMK.js → chunk-IHDN3L3R.js} +7 -8
- package/dist/{chunk-V5LEZ5BX.js → chunk-IIBRYI63.js} +634 -807
- package/dist/{chunk-INC2OACE.js → chunk-JFKDSUIE.js} +3 -9
- package/dist/{chunk-V7DE6JTG.js → chunk-JZ75RIMZ.js} +3 -9
- package/dist/{chunk-AAATUOV6.js → chunk-L6KOIJJ5.js} +53 -59
- package/dist/{chunk-GN5BY5N2.js → chunk-LGYRZ6CV.js} +4 -10
- package/dist/chunk-LVLRGTYH.js +148 -0
- package/dist/{chunk-CQQQ436N.js → chunk-MATFO4ZW.js} +186 -200
- package/dist/{chunk-IFCV5MY4.js → chunk-OCQGHQED.js} +5 -11
- package/dist/chunk-ORL3LJOT.js +470 -0
- package/dist/{chunk-Q7ACZDDT.js → chunk-QOPTDDIH.js} +5 -12
- package/dist/chunk-QTAIWPLH.js +78 -0
- package/dist/{chunk-35LAJN5S.js → chunk-RP2N6UXA.js} +23 -29
- package/dist/chunk-RQFGRXJI.js +174 -0
- package/dist/{chunk-QBK5XTJE.js → chunk-RR6BKMNO.js} +3 -9
- package/dist/{chunk-ILJRJJ3S.js → chunk-RTGQXNX6.js} +3 -9
- package/dist/chunk-SKRR5WT4.js +76 -0
- package/dist/chunk-TM3ETZES.js +153 -0
- package/dist/{chunk-KPUNMK5W.js → chunk-TWPTG4XS.js} +5 -12
- package/dist/{chunk-6QFE3AWR.js → chunk-UP6FVCDK.js} +6 -13
- package/dist/{chunk-YKUZUAXA.js → chunk-V3ZMNXZC.js} +16 -23
- package/dist/chunk-WLPX3672.js +365 -0
- package/dist/chunk-WNH2ACJS.js +122 -0
- package/dist/chunk-XSNOKQTD.js +347 -0
- package/dist/{chunk-X6XGFLEF.js → chunk-YZVZCC3I.js} +25 -30
- package/dist/commands/DbCommand.js +3 -4
- package/dist/commands/DbDrop.js +9 -9
- package/dist/commands/DbExecute.js +7 -8
- package/dist/commands/DbPull.js +18 -19
- package/dist/commands/DbPush.js +12 -13
- package/dist/commands/DbSeed.js +4 -5
- package/dist/commands/MigrateCommand.js +3 -4
- package/dist/commands/MigrateDeploy.js +13 -14
- package/dist/commands/MigrateDev.js +17 -18
- package/dist/commands/MigrateDiff.js +8 -9
- package/dist/commands/MigrateReset.js +15 -16
- package/dist/commands/MigrateResolve.js +11 -12
- package/dist/commands/MigrateStatus.js +11 -12
- package/dist/index.js +60 -77
- package/dist/{multipart-parser-73VM3J4A.js → multipart-parser-NDLECNMN.js} +527 -561
- package/dist/utils/byline.js +5 -6
- package/dist/utils/captureStdout.js +2 -3
- package/dist/utils/countModelsAndTypes.js +2 -3
- package/dist/utils/ensureDatabaseExists.js +8 -9
- package/dist/utils/errors.js +8 -9
- package/dist/utils/flagErrors.js +5 -5
- package/dist/utils/getDatabaseVersionSafe.js +6 -7
- package/dist/utils/getSchemaPathAndPrint.js +4 -5
- package/dist/utils/handleEvaluateDataloss.js +3 -4
- package/dist/utils/introspectSql.js +6 -6
- package/dist/utils/isSchemaEmpty.js +2 -3
- package/dist/utils/printDatasource.js +3 -4
- package/dist/utils/printDatasources.js +3 -4
- package/dist/utils/printFiles.js +5 -6
- package/dist/utils/printIntrospectedSchema.js +2 -3
- package/dist/utils/printMigrationId.js +4 -5
- package/dist/utils/promptForMigrationName.js +2 -3
- package/dist/utils/removeSchemaFiles.js +2 -3
- package/dist/utils/replaceOrAddDatasource.js +2 -3
- package/dist/utils/replaceOrAddDatasource.test.js +7 -8
- package/dist/utils/saveSchemaFiles.js +2 -3
- package/dist/utils/seed.js +6 -7
- package/dist/utils/spinner.js +2 -3
- package/dist/utils/unixSocket.js +2 -3
- package/dist/views/handleViewsIO.js +2 -3
- package/package.json +6 -6
- package/dist/chunk-26XQQ4AG.js +0 -386
- package/dist/chunk-2RSEPJFX.js +0 -165
- package/dist/chunk-4B2LXK4R.js +0 -207
- package/dist/chunk-4UJBOCZJ.js +0 -130
- package/dist/chunk-5HZLCY6X.js +0 -161
- package/dist/chunk-6TE2RIPN.js +0 -80
- package/dist/chunk-7S3Q4MCN.js +0 -480
- package/dist/chunk-AOX7CJAS.js +0 -234
- package/dist/chunk-FF3526PX.js +0 -279
- package/dist/chunk-FUSFURVP.js +0 -86
- package/dist/chunk-GCTCQLOF.js +0 -365
- package/dist/chunk-K44VNAFW.js +0 -189
- package/dist/chunk-O4BT6W33.js +0 -104
- package/dist/chunk-TKAGMA5K.js +0 -72
- package/dist/chunk-U374EXYQ.js +0 -106
|
@@ -0,0 +1,470 @@
|
|
|
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_ORL3LJOT_exports = {};
|
|
30
|
+
__export(chunk_ORL3LJOT_exports, {
|
|
31
|
+
EngineError: () => EngineError,
|
|
32
|
+
SchemaEngine: () => SchemaEngine
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(chunk_ORL3LJOT_exports);
|
|
35
|
+
var import_chunk_MATFO4ZW = require("./chunk-MATFO4ZW.js");
|
|
36
|
+
var import_chunk_L6KOIJJ5 = require("./chunk-L6KOIJJ5.js");
|
|
37
|
+
var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
|
|
38
|
+
var import_node_path = __toESM(require("node:path"));
|
|
39
|
+
var import_debug = __toESM(require("@prisma/debug"));
|
|
40
|
+
var import_internals = require("@prisma/internals");
|
|
41
|
+
var import_child_process = require("child_process");
|
|
42
|
+
var debugRpc = (0, import_debug.default)("prisma:schemaEngine:rpc");
|
|
43
|
+
var debugStderr = (0, import_debug.default)("prisma:schemaEngine:stderr");
|
|
44
|
+
var debugStdin = (0, import_debug.default)("prisma:schemaEngine:stdin");
|
|
45
|
+
var EngineError = class extends Error {
|
|
46
|
+
constructor(message, code) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.code = code;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
(0, import_internals.setClassName)(EngineError, "EngineError");
|
|
52
|
+
var messageId = 1;
|
|
53
|
+
var SchemaEngine = class {
|
|
54
|
+
constructor({ debug = false, schemaPath, enabledPreviewFeatures }) {
|
|
55
|
+
this.listeners = {};
|
|
56
|
+
this.messages = [];
|
|
57
|
+
this.lastError = null;
|
|
58
|
+
this.isRunning = false;
|
|
59
|
+
this.schemaPath = schemaPath;
|
|
60
|
+
if (debug) {
|
|
61
|
+
import_debug.default.enable("SchemaEngine*");
|
|
62
|
+
}
|
|
63
|
+
this.debug = debug;
|
|
64
|
+
this.enabledPreviewFeatures = enabledPreviewFeatures;
|
|
65
|
+
}
|
|
66
|
+
//
|
|
67
|
+
// See JSON-RPC API definition:
|
|
68
|
+
// https://prisma.github.io/prisma-engines/doc/migration_core/json_rpc/index.html
|
|
69
|
+
//
|
|
70
|
+
/**
|
|
71
|
+
* Apply the migrations from the migrations directory to the database.
|
|
72
|
+
* This is the command behind prisma migrate deploy.
|
|
73
|
+
*/
|
|
74
|
+
applyMigrations(args) {
|
|
75
|
+
return this.runCommand(this.getRPCPayload("applyMigrations", args));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create the logical database from the Prisma schema.
|
|
79
|
+
*/
|
|
80
|
+
createDatabase(args) {
|
|
81
|
+
return this.runCommand(this.getRPCPayload("createDatabase", args));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create the next migration in the migrations history.
|
|
85
|
+
* If draft is false and there are no unexecutable steps, it will also apply the newly created migration.
|
|
86
|
+
* Note: This will use the shadow database on the connectors where we need one.
|
|
87
|
+
*/
|
|
88
|
+
createMigration(args) {
|
|
89
|
+
return this.runCommand(this.getRPCPayload("createMigration", args));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Execute a database script directly on the specified live database.
|
|
93
|
+
* Note that this may not be defined on all connectors.
|
|
94
|
+
*/
|
|
95
|
+
dbExecute(args) {
|
|
96
|
+
return this.runCommand(this.getRPCPayload("dbExecute", args));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Make the Schema engine panic. Only useful to test client error handling.
|
|
100
|
+
*/
|
|
101
|
+
debugPanic() {
|
|
102
|
+
return this.runCommand(this.getRPCPayload("debugPanic", void 0));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The method called at the beginning of migrate dev to decide the course of action,
|
|
106
|
+
* based on the current state of the workspace.
|
|
107
|
+
* It acts as a wrapper around diagnoseMigrationHistory.
|
|
108
|
+
* Its role is to interpret the diagnostic output,
|
|
109
|
+
* and translate it to a concrete action to be performed by the CLI.
|
|
110
|
+
*/
|
|
111
|
+
devDiagnostic(args) {
|
|
112
|
+
return this.runCommand(this.getRPCPayload("devDiagnostic", args));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Read the contents of the migrations directory and the migrations table, and returns their relative statuses.
|
|
116
|
+
* At this stage, the Schema engine only reads,
|
|
117
|
+
* it does not write to the database nor the migrations directory, nor does it use a shadow database.
|
|
118
|
+
*/
|
|
119
|
+
diagnoseMigrationHistory(args) {
|
|
120
|
+
return this.runCommand(this.getRPCPayload("diagnoseMigrationHistory", args));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Make sure the Schema engine can connect to the database from the Prisma schema.
|
|
124
|
+
*/
|
|
125
|
+
ensureConnectionValidity(args) {
|
|
126
|
+
return this.runCommand(this.getRPCPayload("ensureConnectionValidity", args));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Development command for migrations.
|
|
130
|
+
* Evaluate the data loss induced by the next migration the engine would generate on the main database.
|
|
131
|
+
*/
|
|
132
|
+
evaluateDataLoss(args) {
|
|
133
|
+
return this.runCommand(this.getRPCPayload("evaluateDataLoss", args));
|
|
134
|
+
}
|
|
135
|
+
getDatabaseDescription(schema) {
|
|
136
|
+
return this.runCommand(this.getRPCPayload("getDatabaseDescription", { schema }));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get the database version for error reporting.
|
|
140
|
+
* If no argument is given, the version of the database associated to the Prisma schema provided
|
|
141
|
+
* in the constructor will be returned.
|
|
142
|
+
*/
|
|
143
|
+
getDatabaseVersion(args) {
|
|
144
|
+
return this.runCommand(this.getRPCPayload("getDatabaseVersion", args));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Given a Prisma schema, introspect the database definitions and update the schema with the results.
|
|
148
|
+
* `compositeTypeDepth` is optional, and only required for MongoDB.
|
|
149
|
+
*/
|
|
150
|
+
async introspect({
|
|
151
|
+
schema,
|
|
152
|
+
force = false,
|
|
153
|
+
baseDirectoryPath,
|
|
154
|
+
compositeTypeDepth = -1,
|
|
155
|
+
// cannot be undefined
|
|
156
|
+
namespaces
|
|
157
|
+
}) {
|
|
158
|
+
this.latestSchema = schema;
|
|
159
|
+
try {
|
|
160
|
+
const introspectResult = await this.runCommand(
|
|
161
|
+
this.getRPCPayload("introspect", { schema, force, compositeTypeDepth, namespaces, baseDirectoryPath })
|
|
162
|
+
);
|
|
163
|
+
const { views } = introspectResult;
|
|
164
|
+
if (views) {
|
|
165
|
+
const schemaPath = this.schemaPath ?? import_node_path.default.join(process.cwd(), "prisma");
|
|
166
|
+
await (0, import_chunk_MATFO4ZW.handleViewsIO)({ views, schemaPath });
|
|
167
|
+
}
|
|
168
|
+
return introspectResult;
|
|
169
|
+
} finally {
|
|
170
|
+
this.stop();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Compares two databases schemas from two arbitrary sources,
|
|
175
|
+
* and display the difference as either a human-readable summary,
|
|
176
|
+
* or an executable script that can be passed to dbExecute.
|
|
177
|
+
* Connection to a shadow database is only necessary when either the from or the to params is a migrations directory.
|
|
178
|
+
* Diffs have a direction. Which source is from and which is to matters.
|
|
179
|
+
* The resulting diff should be thought of as a migration from the schema in `args.from` to the schema in `args.to`.
|
|
180
|
+
* By default, we output a human-readable diff. If you want an executable script, pass the "script": true param.
|
|
181
|
+
*/
|
|
182
|
+
migrateDiff(args) {
|
|
183
|
+
return this.runCommand(this.getRPCPayload("diff", args));
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* List the names of the migrations in the migrations directory.
|
|
187
|
+
*/
|
|
188
|
+
listMigrationDirectories(args) {
|
|
189
|
+
return this.runCommand(this.getRPCPayload("listMigrationDirectories", args));
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Mark a migration as applied in the migrations table.
|
|
193
|
+
* There are two possible outcomes:
|
|
194
|
+
* - The migration is already in the table, but in a failed state. In this case, we will mark it as rolled back, then create a new entry.
|
|
195
|
+
* - The migration is not in the table. We will create a new entry in the migrations table. The started_at and finished_at will be the same.
|
|
196
|
+
* If it is already applied, we return a user-facing error.
|
|
197
|
+
*/
|
|
198
|
+
markMigrationApplied(args) {
|
|
199
|
+
return this.runCommand(this.getRPCPayload("markMigrationApplied", args));
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Mark an existing failed migration as rolled back in the migrations table. It will still be there, but ignored for all purposes except as audit trail.
|
|
203
|
+
*/
|
|
204
|
+
markMigrationRolledBack(args) {
|
|
205
|
+
return this.runCommand(this.getRPCPayload("markMigrationRolledBack", args));
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Try to make the database empty: no data and no schema.
|
|
209
|
+
* On most connectors, this is implemented by dropping and recreating the database.
|
|
210
|
+
* If that fails (most likely because of insufficient permissions),
|
|
211
|
+
* the engine attempts a “best effort reset” by inspecting the contents of the database and dropping them individually.
|
|
212
|
+
* Drop and recreate the database. The migrations will not be applied, as it would overlap with applyMigrations.
|
|
213
|
+
*/
|
|
214
|
+
reset() {
|
|
215
|
+
return this.runCommand(this.getRPCPayload("reset", void 0));
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* The command behind db push.
|
|
219
|
+
*/
|
|
220
|
+
schemaPush(args) {
|
|
221
|
+
return this.runCommand(this.getRPCPayload("schemaPush", args));
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* SQL introspection that powers TypedSQL feature
|
|
225
|
+
* @param args
|
|
226
|
+
* @returns
|
|
227
|
+
*/
|
|
228
|
+
introspectSql(args) {
|
|
229
|
+
return this.runCommand(this.getRPCPayload("introspectSql", args));
|
|
230
|
+
}
|
|
231
|
+
stop() {
|
|
232
|
+
if (this.child) {
|
|
233
|
+
this.child.kill();
|
|
234
|
+
this.isRunning = false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
rejectAll(err) {
|
|
238
|
+
Object.entries(this.listeners).map(([id, listener]) => {
|
|
239
|
+
listener(null, err);
|
|
240
|
+
delete this.listeners[id];
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
registerCallback(id, callback) {
|
|
244
|
+
this.listeners[id] = callback;
|
|
245
|
+
}
|
|
246
|
+
handleResponse(response) {
|
|
247
|
+
let result;
|
|
248
|
+
try {
|
|
249
|
+
result = JSON.parse(response);
|
|
250
|
+
} catch (e) {
|
|
251
|
+
console.error(`Could not parse Schema engine response: ${response.slice(0, 200)}. Error: ${e.message}`);
|
|
252
|
+
}
|
|
253
|
+
if (result) {
|
|
254
|
+
if (result.id && (result.result !== void 0 || result.error !== void 0)) {
|
|
255
|
+
if (!this.listeners[result.id]) {
|
|
256
|
+
console.error(`Got result for unknown id ${result.id}`);
|
|
257
|
+
}
|
|
258
|
+
if (this.listeners[result.id]) {
|
|
259
|
+
this.listeners[result.id](result);
|
|
260
|
+
delete this.listeners[result.id];
|
|
261
|
+
}
|
|
262
|
+
} else if (result.method) {
|
|
263
|
+
if (result.id !== void 0) {
|
|
264
|
+
if (result.method === "print" && result.params?.content !== void 0) {
|
|
265
|
+
process.stdout.write(result.params.content + "\n");
|
|
266
|
+
const response2 = {
|
|
267
|
+
id: result.id,
|
|
268
|
+
jsonrpc: "2.0",
|
|
269
|
+
result: {}
|
|
270
|
+
};
|
|
271
|
+
this.child.stdin.write(JSON.stringify(response2) + "\n");
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
init() {
|
|
278
|
+
if (!this.initPromise) {
|
|
279
|
+
this.initPromise = this.internalInit();
|
|
280
|
+
}
|
|
281
|
+
return this.initPromise;
|
|
282
|
+
}
|
|
283
|
+
internalInit() {
|
|
284
|
+
return new Promise(async (resolve, reject) => {
|
|
285
|
+
try {
|
|
286
|
+
const { PWD, ...processEnv } = process.env;
|
|
287
|
+
const binaryPath = await (0, import_internals.resolveBinary)(import_internals.BinaryType.SchemaEngineBinary);
|
|
288
|
+
debugRpc("starting Schema engine with binary: " + binaryPath);
|
|
289
|
+
const args = [];
|
|
290
|
+
let projectDir = process.cwd();
|
|
291
|
+
if (this.schemaPath) {
|
|
292
|
+
const schema = await (0, import_internals.getSchema)(this.schemaPath);
|
|
293
|
+
const config = await (0, import_internals.getConfig)({ datamodel: schema });
|
|
294
|
+
projectDir = (0, import_internals.getMigrateConfigDir)(config, this.schemaPath);
|
|
295
|
+
const schemaArgs = schema.flatMap(([path2]) => ["-d", path2]);
|
|
296
|
+
args.push(...schemaArgs);
|
|
297
|
+
}
|
|
298
|
+
if (this.enabledPreviewFeatures && Array.isArray(this.enabledPreviewFeatures) && this.enabledPreviewFeatures.length > 0) {
|
|
299
|
+
args.push(...["--enabled-preview-features", this.enabledPreviewFeatures.join(",")]);
|
|
300
|
+
}
|
|
301
|
+
this.child = (0, import_child_process.spawn)(binaryPath, args, {
|
|
302
|
+
cwd: projectDir,
|
|
303
|
+
stdio: ["pipe", "pipe", this.debug ? process.stderr : "pipe"],
|
|
304
|
+
env: {
|
|
305
|
+
// The following environment variables can be overridden by the user.
|
|
306
|
+
RUST_LOG: "info",
|
|
307
|
+
RUST_BACKTRACE: "1",
|
|
308
|
+
// Take env values from process.env (will override values set before)
|
|
309
|
+
...processEnv
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
this.isRunning = true;
|
|
313
|
+
this.child.on("error", (err) => {
|
|
314
|
+
console.error("[schema-engine] error: %s", err);
|
|
315
|
+
this.rejectAll(err);
|
|
316
|
+
reject(err);
|
|
317
|
+
});
|
|
318
|
+
this.child.on("exit", (code) => {
|
|
319
|
+
const exitWithErr = (err) => {
|
|
320
|
+
this.rejectAll(err);
|
|
321
|
+
reject(err);
|
|
322
|
+
};
|
|
323
|
+
const processMessages = this.messages.join("\n");
|
|
324
|
+
const engineMessage = this.lastError?.message || processMessages;
|
|
325
|
+
const handlePanic = () => {
|
|
326
|
+
const stackTrace = `[EXIT_PANIC]
|
|
327
|
+
${processMessages}
|
|
328
|
+
${this.lastError?.backtrace ?? ""}`;
|
|
329
|
+
exitWithErr(
|
|
330
|
+
new import_internals.RustPanic(
|
|
331
|
+
serializePanic(engineMessage),
|
|
332
|
+
stackTrace,
|
|
333
|
+
this.lastRequest,
|
|
334
|
+
import_internals.ErrorArea.LIFT_CLI,
|
|
335
|
+
/* schemaPath */
|
|
336
|
+
this.schemaPath,
|
|
337
|
+
/* schema */
|
|
338
|
+
this.latestSchema?.files.map((schema) => [schema.path, schema.content])
|
|
339
|
+
)
|
|
340
|
+
);
|
|
341
|
+
};
|
|
342
|
+
switch (code) {
|
|
343
|
+
case import_internals.SchemaEngineExitCode.Success:
|
|
344
|
+
break;
|
|
345
|
+
case import_internals.SchemaEngineExitCode.Error:
|
|
346
|
+
exitWithErr(new Error(`Error in Schema engine: ${engineMessage}`));
|
|
347
|
+
break;
|
|
348
|
+
case import_internals.SchemaEngineExitCode.Panic:
|
|
349
|
+
handlePanic();
|
|
350
|
+
break;
|
|
351
|
+
// treat unknown error codes as panics
|
|
352
|
+
default:
|
|
353
|
+
handlePanic();
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
this.child.stdin.on("error", (err) => {
|
|
357
|
+
debugStdin(err);
|
|
358
|
+
});
|
|
359
|
+
(0, import_chunk_L6KOIJJ5.byline)(this.child.stderr).on("data", (msg) => {
|
|
360
|
+
const data = String(msg);
|
|
361
|
+
debugStderr(data);
|
|
362
|
+
try {
|
|
363
|
+
const json = JSON.parse(data);
|
|
364
|
+
this.messages.push(json.fields.message);
|
|
365
|
+
if (json.level === "ERROR") {
|
|
366
|
+
this.lastError = json.fields;
|
|
367
|
+
}
|
|
368
|
+
} catch (e) {
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
(0, import_chunk_L6KOIJJ5.byline)(this.child.stdout).on("data", (line) => {
|
|
372
|
+
this.handleResponse(String(line));
|
|
373
|
+
});
|
|
374
|
+
setImmediate(() => {
|
|
375
|
+
resolve();
|
|
376
|
+
});
|
|
377
|
+
} catch (e) {
|
|
378
|
+
reject(e);
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
async runCommand(request) {
|
|
383
|
+
if (process.env.FORCE_PANIC_SCHEMA_ENGINE && request.method !== "getDatabaseVersion") {
|
|
384
|
+
request = this.getRPCPayload("debugPanic", void 0);
|
|
385
|
+
}
|
|
386
|
+
await this.init();
|
|
387
|
+
if (this.child?.killed) {
|
|
388
|
+
throw new Error(`Can't execute ${JSON.stringify(request)} because Schema engine already exited.`);
|
|
389
|
+
}
|
|
390
|
+
return new Promise((resolve, reject) => {
|
|
391
|
+
this.registerCallback(request.id, (response, err) => {
|
|
392
|
+
if (err) {
|
|
393
|
+
return reject(err);
|
|
394
|
+
}
|
|
395
|
+
if (response.result !== void 0) {
|
|
396
|
+
resolve(response.result);
|
|
397
|
+
} else {
|
|
398
|
+
if (response.error) {
|
|
399
|
+
debugRpc(response);
|
|
400
|
+
if (response.error.data?.is_panic) {
|
|
401
|
+
const message = response.error.data?.error?.message ?? response.error.message;
|
|
402
|
+
const stackTrace = `[RESPONSE_ERROR_PANIC]
|
|
403
|
+
${response.error.data?.message ?? ""}`;
|
|
404
|
+
reject(
|
|
405
|
+
// Handle error and displays the interactive dialog to send panic error
|
|
406
|
+
new import_internals.RustPanic(
|
|
407
|
+
message,
|
|
408
|
+
stackTrace,
|
|
409
|
+
this.lastRequest,
|
|
410
|
+
import_internals.ErrorArea.LIFT_CLI,
|
|
411
|
+
/* schemaPath */
|
|
412
|
+
this.schemaPath,
|
|
413
|
+
/* schema */
|
|
414
|
+
this.latestSchema?.files.map((schema) => [schema.path, schema.content])
|
|
415
|
+
)
|
|
416
|
+
);
|
|
417
|
+
} else if (response.error.data?.message) {
|
|
418
|
+
let message = `${(0, import_chunk_SKRR5WT4.red)((0, import_internals.relativizePathInPSLError)(response.error.data.message))}
|
|
419
|
+
`;
|
|
420
|
+
if (response.error.data?.error_code) {
|
|
421
|
+
message = (0, import_chunk_SKRR5WT4.red)(`${response.error.data.error_code}
|
|
422
|
+
|
|
423
|
+
`) + message;
|
|
424
|
+
reject(new EngineError(message, response.error.data.error_code));
|
|
425
|
+
} else {
|
|
426
|
+
reject(new Error(message));
|
|
427
|
+
}
|
|
428
|
+
} else {
|
|
429
|
+
reject(
|
|
430
|
+
new Error(
|
|
431
|
+
`${(0, import_chunk_SKRR5WT4.red)("Error in RPC")}
|
|
432
|
+
Request: ${JSON.stringify(request, null, 2)}
|
|
433
|
+
Response: ${JSON.stringify(
|
|
434
|
+
response,
|
|
435
|
+
null,
|
|
436
|
+
2
|
|
437
|
+
)}
|
|
438
|
+
${response.error.message}
|
|
439
|
+
`
|
|
440
|
+
)
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
} else {
|
|
444
|
+
reject(new Error(`Got invalid RPC response without .result property: ${JSON.stringify(response)}`));
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
if (this.child.stdin.destroyed) {
|
|
449
|
+
throw new Error(`Can't execute ${JSON.stringify(request)} because Schema engine is destroyed.`);
|
|
450
|
+
}
|
|
451
|
+
debugRpc("SENDING RPC CALL", JSON.stringify(request));
|
|
452
|
+
this.child.stdin.write(JSON.stringify(request) + "\n");
|
|
453
|
+
this.lastRequest = request;
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
getRPCPayload(method, params) {
|
|
457
|
+
return {
|
|
458
|
+
id: messageId++,
|
|
459
|
+
jsonrpc: "2.0",
|
|
460
|
+
method,
|
|
461
|
+
params: params ? {
|
|
462
|
+
...params
|
|
463
|
+
} : void 0
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
function serializePanic(log) {
|
|
468
|
+
return `${(0, import_chunk_SKRR5WT4.red)((0, import_chunk_SKRR5WT4.bold)("Error in Schema engine.\nReason: "))}${log}
|
|
469
|
+
`;
|
|
470
|
+
}
|
|
@@ -16,14 +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
|
|
20
|
-
__export(
|
|
21
|
-
init_printDatasource: () => init_printDatasource,
|
|
19
|
+
var chunk_QOPTDDIH_exports = {};
|
|
20
|
+
__export(chunk_QOPTDDIH_exports, {
|
|
22
21
|
printDatasource: () => printDatasource
|
|
23
22
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
25
|
-
var
|
|
26
|
-
var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
|
|
23
|
+
module.exports = __toCommonJS(chunk_QOPTDDIH_exports);
|
|
24
|
+
var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
|
|
27
25
|
function printDatasource({ datasourceInfo }) {
|
|
28
26
|
if (!datasourceInfo.name || !datasourceInfo.prettyProvider) return;
|
|
29
27
|
let message = `Datasource "${datasourceInfo.name}": ${datasourceInfo.prettyProvider} database`;
|
|
@@ -38,10 +36,5 @@ function printDatasource({ datasourceInfo }) {
|
|
|
38
36
|
if (datasourceInfo.dbLocation) {
|
|
39
37
|
message += ` at "${datasourceInfo.dbLocation}"`;
|
|
40
38
|
}
|
|
41
|
-
process.stdout.write((0,
|
|
39
|
+
process.stdout.write((0, import_chunk_SKRR5WT4.dim)(message) + "\n");
|
|
42
40
|
}
|
|
43
|
-
var init_printDatasource = (0, import_chunk_WWAWV7DQ.__esm)({
|
|
44
|
-
"src/utils/printDatasource.ts"() {
|
|
45
|
-
(0, import_chunk_6TE2RIPN.init_colors)();
|
|
46
|
-
}
|
|
47
|
-
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var chunk_QTAIWPLH_exports = {};
|
|
20
|
+
__export(chunk_QTAIWPLH_exports, {
|
|
21
|
+
CLI: () => CLI
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(chunk_QTAIWPLH_exports);
|
|
24
|
+
var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
|
|
25
|
+
var import_internals = require("@prisma/internals");
|
|
26
|
+
var _CLI = class _CLI2 {
|
|
27
|
+
constructor(cmds) {
|
|
28
|
+
this.cmds = cmds;
|
|
29
|
+
}
|
|
30
|
+
static new(cmds) {
|
|
31
|
+
return new _CLI2(cmds);
|
|
32
|
+
}
|
|
33
|
+
async parse(argv, config) {
|
|
34
|
+
const args = (0, import_internals.arg)(argv, {
|
|
35
|
+
"--help": Boolean,
|
|
36
|
+
"-h": "--help",
|
|
37
|
+
"--config": String,
|
|
38
|
+
"--json": Boolean,
|
|
39
|
+
// for -v
|
|
40
|
+
"--experimental": Boolean,
|
|
41
|
+
"--preview-feature": Boolean,
|
|
42
|
+
"--early-access": Boolean,
|
|
43
|
+
"--telemetry-information": String
|
|
44
|
+
});
|
|
45
|
+
if ((0, import_internals.isError)(args)) {
|
|
46
|
+
return this.help(args.message);
|
|
47
|
+
}
|
|
48
|
+
if (args._.length === 0 || args["--help"]) {
|
|
49
|
+
return this.help();
|
|
50
|
+
}
|
|
51
|
+
const cmdName = args._[0];
|
|
52
|
+
const cmd = this.cmds[cmdName];
|
|
53
|
+
if (cmd) {
|
|
54
|
+
let argsForCmd;
|
|
55
|
+
if (args["--experimental"]) {
|
|
56
|
+
argsForCmd = [...args._.slice(1), `--experimental=${args["--experimental"]}`];
|
|
57
|
+
} else if (args["--preview-feature"]) {
|
|
58
|
+
argsForCmd = [...args._.slice(1), `--preview-feature=${args["--preview-feature"]}`];
|
|
59
|
+
} else if (args["--early-access"]) {
|
|
60
|
+
argsForCmd = [...args._.slice(1), `--early-access=${args["--early-access"]}`];
|
|
61
|
+
} else {
|
|
62
|
+
argsForCmd = args._.slice(1);
|
|
63
|
+
}
|
|
64
|
+
return cmd.parse(argsForCmd, config);
|
|
65
|
+
}
|
|
66
|
+
return (0, import_internals.unknownCommand)(this.help(), args._[0]);
|
|
67
|
+
}
|
|
68
|
+
help(error) {
|
|
69
|
+
if (error) {
|
|
70
|
+
return new import_internals.HelpError(`
|
|
71
|
+
${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
|
|
72
|
+
${_CLI2.help}`);
|
|
73
|
+
}
|
|
74
|
+
return _CLI2.help;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
_CLI.help = (0, import_internals.format)(`This is the internal CLI for @prisma/migrate`);
|
|
78
|
+
var CLI = _CLI;
|
|
@@ -16,46 +16,40 @@ 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
|
|
20
|
-
__export(
|
|
21
|
-
init_printDatasources: () => init_printDatasources,
|
|
19
|
+
var chunk_RP2N6UXA_exports = {};
|
|
20
|
+
__export(chunk_RP2N6UXA_exports, {
|
|
22
21
|
printDatamodelObject: () => printDatamodelObject,
|
|
23
22
|
printDatasources: () => printDatasources
|
|
24
23
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
24
|
+
module.exports = __toCommonJS(chunk_RP2N6UXA_exports);
|
|
26
25
|
var import_chunk_LKTTJWFT = require("./chunk-LKTTJWFT.js");
|
|
27
26
|
var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
|
|
27
|
+
var import_indent_string = (0, import_chunk_WWAWV7DQ.__toESM)((0, import_chunk_LKTTJWFT.require_indent_string)());
|
|
28
28
|
function printDatasources(internalDatasources) {
|
|
29
29
|
return internalDatasources.map((d) => String(new InternalDataSourceClass(d))).join("\n\n");
|
|
30
30
|
}
|
|
31
|
+
var tab = 2;
|
|
32
|
+
var InternalDataSourceClass = class {
|
|
33
|
+
constructor(dataSource) {
|
|
34
|
+
this.dataSource = dataSource;
|
|
35
|
+
}
|
|
36
|
+
toString() {
|
|
37
|
+
const { dataSource } = this;
|
|
38
|
+
const obj = {
|
|
39
|
+
provider: dataSource.provider,
|
|
40
|
+
url: dataSource.url
|
|
41
|
+
};
|
|
42
|
+
if (dataSource.config && typeof dataSource.config === "object") {
|
|
43
|
+
Object.assign(obj, dataSource.config);
|
|
44
|
+
}
|
|
45
|
+
return `datasource ${dataSource.name} {
|
|
46
|
+
${(0, import_indent_string.default)(printDatamodelObject(obj), tab)}
|
|
47
|
+
}`;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
31
50
|
function printDatamodelObject(obj) {
|
|
32
51
|
const maxLength = Object.keys(obj).reduce((max, curr) => Math.max(max, curr.length), 0);
|
|
33
52
|
return Object.entries(obj).map(
|
|
34
53
|
([key, value]) => `${key.padEnd(maxLength)} = ${typeof value === "object" && value && value.value ? JSON.stringify(value.value) : JSON.stringify(value)}`
|
|
35
54
|
).join("\n");
|
|
36
55
|
}
|
|
37
|
-
var import_indent_string, tab, InternalDataSourceClass;
|
|
38
|
-
var init_printDatasources = (0, import_chunk_WWAWV7DQ.__esm)({
|
|
39
|
-
"src/utils/printDatasources.ts"() {
|
|
40
|
-
import_indent_string = (0, import_chunk_WWAWV7DQ.__toESM)((0, import_chunk_LKTTJWFT.require_indent_string)());
|
|
41
|
-
tab = 2;
|
|
42
|
-
InternalDataSourceClass = class {
|
|
43
|
-
constructor(dataSource) {
|
|
44
|
-
this.dataSource = dataSource;
|
|
45
|
-
}
|
|
46
|
-
toString() {
|
|
47
|
-
const { dataSource } = this;
|
|
48
|
-
const obj = {
|
|
49
|
-
provider: dataSource.provider,
|
|
50
|
-
url: dataSource.url
|
|
51
|
-
};
|
|
52
|
-
if (dataSource.config && typeof dataSource.config === "object") {
|
|
53
|
-
Object.assign(obj, dataSource.config);
|
|
54
|
-
}
|
|
55
|
-
return `datasource ${dataSource.name} {
|
|
56
|
-
${(0, import_indent_string.default)(printDatamodelObject(obj), tab)}
|
|
57
|
-
}`;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
});
|