@prisma/migrate 6.4.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-WZT5FFN4.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/internals/src/index.d.ts +0 -3
- 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
- package/dist/internals/src/utils/isInContainer.d.ts +0 -5
- package/dist/internals/src/utils/isInNpmLifecycleHook.d.ts +0 -4
- package/dist/internals/src/utils/maybeInGitHook.d.ts +0 -9
|
@@ -0,0 +1,365 @@
|
|
|
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_WLPX3672_exports = {};
|
|
30
|
+
__export(chunk_WLPX3672_exports, {
|
|
31
|
+
DbPull: () => DbPull
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(chunk_WLPX3672_exports);
|
|
34
|
+
var import_chunk_DIAO4W7O = require("./chunk-DIAO4W7O.js");
|
|
35
|
+
var import_chunk_RTGQXNX6 = require("./chunk-RTGQXNX6.js");
|
|
36
|
+
var import_chunk_RP2N6UXA = require("./chunk-RP2N6UXA.js");
|
|
37
|
+
var import_chunk_AHJ2N6BJ = require("./chunk-AHJ2N6BJ.js");
|
|
38
|
+
var import_chunk_JZ75RIMZ = require("./chunk-JZ75RIMZ.js");
|
|
39
|
+
var import_chunk_RR6BKMNO = require("./chunk-RR6BKMNO.js");
|
|
40
|
+
var import_chunk_JFKDSUIE = require("./chunk-JFKDSUIE.js");
|
|
41
|
+
var import_chunk_LGYRZ6CV = require("./chunk-LGYRZ6CV.js");
|
|
42
|
+
var import_chunk_ORL3LJOT = require("./chunk-ORL3LJOT.js");
|
|
43
|
+
var import_chunk_MATFO4ZW = require("./chunk-MATFO4ZW.js");
|
|
44
|
+
var import_chunk_3WC4XD74 = require("./chunk-3WC4XD74.js");
|
|
45
|
+
var import_chunk_QOPTDDIH = require("./chunk-QOPTDDIH.js");
|
|
46
|
+
var import_chunk_DJMFXNR4 = require("./chunk-DJMFXNR4.js");
|
|
47
|
+
var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
|
|
48
|
+
var import_debug = __toESM(require("@prisma/debug"));
|
|
49
|
+
var import_internals = require("@prisma/internals");
|
|
50
|
+
var import_path = __toESM(require("path"));
|
|
51
|
+
var debug = (0, import_debug.default)("prisma:db:pull");
|
|
52
|
+
var _DbPull = class _DbPull2 {
|
|
53
|
+
static new() {
|
|
54
|
+
return new _DbPull2();
|
|
55
|
+
}
|
|
56
|
+
urlToDatasource(url, defaultProvider) {
|
|
57
|
+
const provider = defaultProvider || (0, import_internals.protocolToConnectorType)(`${url.split(":")[0]}:`);
|
|
58
|
+
return (0, import_chunk_RP2N6UXA.printDatasources)([
|
|
59
|
+
{
|
|
60
|
+
config: {},
|
|
61
|
+
provider,
|
|
62
|
+
name: "db",
|
|
63
|
+
url
|
|
64
|
+
}
|
|
65
|
+
]);
|
|
66
|
+
}
|
|
67
|
+
async parse(argv, config) {
|
|
68
|
+
const args = (0, import_internals.arg)(argv, {
|
|
69
|
+
"--help": Boolean,
|
|
70
|
+
"-h": "--help",
|
|
71
|
+
"--url": String,
|
|
72
|
+
"--print": Boolean,
|
|
73
|
+
"--schema": String,
|
|
74
|
+
"--config": String,
|
|
75
|
+
"--schemas": String,
|
|
76
|
+
"--force": Boolean,
|
|
77
|
+
"--composite-type-depth": Number,
|
|
78
|
+
// optional, only on mongodb
|
|
79
|
+
"--local-d1": Boolean
|
|
80
|
+
// optional, only on cloudflare D1
|
|
81
|
+
});
|
|
82
|
+
const spinnerFactory = (0, import_chunk_DIAO4W7O.createSpinner)(!args["--print"]);
|
|
83
|
+
if (args instanceof Error) {
|
|
84
|
+
return this.help(args.message);
|
|
85
|
+
}
|
|
86
|
+
await (0, import_internals.checkUnsupportedDataProxy)("db pull", args, config.schema, !args["--url"]);
|
|
87
|
+
if (args["--help"]) {
|
|
88
|
+
return this.help();
|
|
89
|
+
}
|
|
90
|
+
const url = args["--url"];
|
|
91
|
+
const schemaPathResult = await (0, import_internals.getSchemaWithPathOptional)(args["--schema"], config.schema);
|
|
92
|
+
let schemaPath = schemaPathResult?.schemaPath ?? null;
|
|
93
|
+
const rootDir = schemaPathResult?.schemaRootDir ?? process.cwd();
|
|
94
|
+
debug("schemaPathResult", schemaPathResult);
|
|
95
|
+
if (schemaPath && !args["--print"]) {
|
|
96
|
+
process.stdout.write((0, import_chunk_SKRR5WT4.dim)(`Prisma schema loaded from ${import_path.default.relative(process.cwd(), schemaPath)}`) + "\n");
|
|
97
|
+
await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true, config });
|
|
98
|
+
(0, import_chunk_QOPTDDIH.printDatasource)({ datasourceInfo: await (0, import_chunk_DJMFXNR4.getDatasourceInfo)({ schemaPath }) });
|
|
99
|
+
} else {
|
|
100
|
+
await (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: false, config });
|
|
101
|
+
}
|
|
102
|
+
const fromD1 = Boolean(args["--local-d1"]);
|
|
103
|
+
if (!url && !schemaPath && !fromD1) {
|
|
104
|
+
throw new import_chunk_3WC4XD74.NoSchemaFoundError();
|
|
105
|
+
}
|
|
106
|
+
const { firstDatasource, schema, validationWarning } = await (0, import_chunk_MATFO4ZW.z)({ url, schemaPath, fromD1 }).when(
|
|
107
|
+
(input) => input.schemaPath !== null,
|
|
108
|
+
async (input) => {
|
|
109
|
+
const rawSchema = await (0, import_internals.getSchema)(input.schemaPath, config.schema);
|
|
110
|
+
const engineConfig = await (0, import_internals.getConfig)({
|
|
111
|
+
datamodel: rawSchema,
|
|
112
|
+
ignoreEnvVarErrors: true
|
|
113
|
+
});
|
|
114
|
+
const previewFeatures = engineConfig.generators.find(({ name }) => name === "client")?.previewFeatures;
|
|
115
|
+
const firstDatasource2 = engineConfig.datasources[0] ? engineConfig.datasources[0] : void 0;
|
|
116
|
+
if (input.url) {
|
|
117
|
+
let providerFromSchema = firstDatasource2?.provider;
|
|
118
|
+
if (providerFromSchema === "postgres") {
|
|
119
|
+
providerFromSchema = "postgresql";
|
|
120
|
+
}
|
|
121
|
+
const providerFromUrl = (0, import_internals.protocolToConnectorType)(`${input.url.split(":")[0]}:`);
|
|
122
|
+
const schema2 = (0, import_chunk_RR6BKMNO.replaceOrAddDatasource)(this.urlToDatasource(input.url, providerFromSchema), rawSchema);
|
|
123
|
+
if (providerFromSchema && providerFromUrl && providerFromSchema !== providerFromUrl && Boolean(providerFromSchema === "cockroachdb" && providerFromUrl === "postgresql") === false) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
`The database provider found in --url (${providerFromUrl}) is different from the provider found in the Prisma schema (${providerFromSchema}).`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
return { firstDatasource: firstDatasource2, schema: schema2, validationWarning: void 0 };
|
|
129
|
+
} else if (input.fromD1) {
|
|
130
|
+
const d1Database = await (0, import_internals.locateLocalCloudflareD1)({ arg: "--from-local-d1" });
|
|
131
|
+
const pathToSQLiteFile = import_path.default.relative(import_path.default.dirname(input.schemaPath), d1Database);
|
|
132
|
+
const schema2 = [
|
|
133
|
+
["schema.prisma", this.urlToDatasource(`file:${pathToSQLiteFile}`, "sqlite")]
|
|
134
|
+
];
|
|
135
|
+
const config2 = await (0, import_internals.getConfig)({
|
|
136
|
+
datamodel: schema2,
|
|
137
|
+
ignoreEnvVarErrors: true
|
|
138
|
+
});
|
|
139
|
+
const result = { firstDatasource: config2.datasources[0], schema: schema2, validationWarning: void 0 };
|
|
140
|
+
const hasDriverAdaptersPreviewFeature = (previewFeatures || []).includes("driverAdapters");
|
|
141
|
+
const validationWarning2 = `Without the ${(0, import_chunk_SKRR5WT4.bold)(
|
|
142
|
+
"driverAdapters"
|
|
143
|
+
)} preview feature, the schema introspected via the ${(0, import_chunk_SKRR5WT4.bold)("--local-d1")} flag will not work with ${(0, import_chunk_SKRR5WT4.bold)(
|
|
144
|
+
"@prisma/client"
|
|
145
|
+
)}.`;
|
|
146
|
+
if (hasDriverAdaptersPreviewFeature) {
|
|
147
|
+
return result;
|
|
148
|
+
} else {
|
|
149
|
+
return { ...result, validationWarning: validationWarning2 };
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
await (0, import_internals.getConfig)({
|
|
153
|
+
datamodel: rawSchema,
|
|
154
|
+
ignoreEnvVarErrors: false
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return { firstDatasource: firstDatasource2, schema: rawSchema, validationWarning: void 0 };
|
|
158
|
+
}
|
|
159
|
+
).when(
|
|
160
|
+
(input) => input.fromD1 === true,
|
|
161
|
+
async (_) => {
|
|
162
|
+
const d1Database = await (0, import_internals.locateLocalCloudflareD1)({ arg: "--from-local-d1" });
|
|
163
|
+
const pathToSQLiteFile = import_path.default.relative(process.cwd(), d1Database);
|
|
164
|
+
const schemaContent = `generator client {
|
|
165
|
+
provider = "prisma-client-js"
|
|
166
|
+
previewFeatures = ["driverAdapters"]
|
|
167
|
+
}
|
|
168
|
+
${this.urlToDatasource(`file:${pathToSQLiteFile}`, "sqlite")}`;
|
|
169
|
+
const schema2 = [["schema.prisma", schemaContent]];
|
|
170
|
+
const config2 = await (0, import_internals.getConfig)({
|
|
171
|
+
datamodel: schema2,
|
|
172
|
+
ignoreEnvVarErrors: true
|
|
173
|
+
});
|
|
174
|
+
return { firstDatasource: config2.datasources[0], schema: schema2, validationWarning: void 0 };
|
|
175
|
+
}
|
|
176
|
+
).when(
|
|
177
|
+
(input) => input.url !== void 0,
|
|
178
|
+
async (input) => {
|
|
179
|
+
(0, import_internals.protocolToConnectorType)(`${input.url.split(":")[0]}:`);
|
|
180
|
+
const schema2 = [["schema.prisma", this.urlToDatasource(input.url)]];
|
|
181
|
+
const config2 = await (0, import_internals.getConfig)({
|
|
182
|
+
datamodel: schema2,
|
|
183
|
+
ignoreEnvVarErrors: true
|
|
184
|
+
});
|
|
185
|
+
return { firstDatasource: config2.datasources[0], schema: schema2, validationWarning: void 0 };
|
|
186
|
+
}
|
|
187
|
+
).run();
|
|
188
|
+
if (schemaPath) {
|
|
189
|
+
const schemas = await (0, import_internals.getSchema)(args["--schema"], config.schema);
|
|
190
|
+
const modelRegex = /\s*model\s*(\w+)\s*{/;
|
|
191
|
+
const isReintrospection = schemas.some(([_, schema2]) => !!modelRegex.exec(schema2));
|
|
192
|
+
if (isReintrospection && !args["--force"] && firstDatasource?.provider === "mongodb") {
|
|
193
|
+
throw new Error(`Iterating on one schema using re-introspection with db pull is currently not supported with MongoDB provider.
|
|
194
|
+
You can explicitly ignore and override your current local schema file with ${(0, import_chunk_SKRR5WT4.green)(
|
|
195
|
+
(0, import_internals.getCommandWithExecutor)("prisma db pull --force")
|
|
196
|
+
)}
|
|
197
|
+
Some information will be lost (relations, comments, mapped fields, @ignore...), follow ${(0, import_internals.link)(
|
|
198
|
+
"https://github.com/prisma/prisma/issues/9585"
|
|
199
|
+
)} for more info.`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const engine = new import_chunk_ORL3LJOT.SchemaEngine({
|
|
203
|
+
schemaPath: schemaPath ?? void 0
|
|
204
|
+
});
|
|
205
|
+
const basedOn = !args["--url"] && schemaPath ? ` based on datasource defined in ${(0, import_chunk_SKRR5WT4.underline)(import_path.default.relative(process.cwd(), schemaPath))}` : "";
|
|
206
|
+
const introspectionSpinner = spinnerFactory(`Introspecting${basedOn}`);
|
|
207
|
+
const before = Math.round(performance.now());
|
|
208
|
+
let introspectionSchema = void 0;
|
|
209
|
+
let introspectionWarnings;
|
|
210
|
+
try {
|
|
211
|
+
const introspectionResult = await engine.introspect({
|
|
212
|
+
schema: (0, import_internals.toSchemasContainer)(schema),
|
|
213
|
+
baseDirectoryPath: rootDir,
|
|
214
|
+
force: args["--force"],
|
|
215
|
+
compositeTypeDepth: args["--composite-type-depth"],
|
|
216
|
+
namespaces: args["--schemas"]?.split(",")
|
|
217
|
+
});
|
|
218
|
+
introspectionSchema = introspectionResult.schema;
|
|
219
|
+
introspectionWarnings = introspectionResult.warnings;
|
|
220
|
+
debug(`Introspection warnings`, introspectionWarnings);
|
|
221
|
+
} catch (e) {
|
|
222
|
+
introspectionSpinner.failure();
|
|
223
|
+
if (e.code === "P4001" && (0, import_chunk_JFKDSUIE.isSchemaEmpty)(introspectionSchema)) {
|
|
224
|
+
throw new Error(`
|
|
225
|
+
${(0, import_chunk_SKRR5WT4.red)((0, import_chunk_SKRR5WT4.bold)(`${e.code} `))}${(0, import_chunk_SKRR5WT4.red)("The introspected database was empty:")}
|
|
226
|
+
|
|
227
|
+
${(0, import_chunk_SKRR5WT4.bold)("prisma db pull")} could not create any models in your ${(0, import_chunk_SKRR5WT4.bold)(
|
|
228
|
+
"schema.prisma"
|
|
229
|
+
)} file and you will not be able to generate Prisma Client with the ${(0, import_chunk_SKRR5WT4.bold)(
|
|
230
|
+
(0, import_internals.getCommandWithExecutor)("prisma generate")
|
|
231
|
+
)} command.
|
|
232
|
+
|
|
233
|
+
${(0, import_chunk_SKRR5WT4.bold)("To fix this, you have two options:")}
|
|
234
|
+
|
|
235
|
+
- manually create a table in your database.
|
|
236
|
+
- make sure the database connection URL inside the ${(0, import_chunk_SKRR5WT4.bold)("datasource")} block in ${(0, import_chunk_SKRR5WT4.bold)(
|
|
237
|
+
"schema.prisma"
|
|
238
|
+
)} points to a database that is not empty (it must contain at least one table).
|
|
239
|
+
|
|
240
|
+
Then you can run ${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExecutor)("prisma db pull"))} again.
|
|
241
|
+
`);
|
|
242
|
+
} else if (e.code === "P1003") {
|
|
243
|
+
throw new Error(`
|
|
244
|
+
${(0, import_chunk_SKRR5WT4.red)((0, import_chunk_SKRR5WT4.bold)(`${e.code} `))}${(0, import_chunk_SKRR5WT4.red)("The introspected database does not exist:")}
|
|
245
|
+
|
|
246
|
+
${(0, import_chunk_SKRR5WT4.bold)("prisma db pull")} could not create any models in your ${(0, import_chunk_SKRR5WT4.bold)(
|
|
247
|
+
"schema.prisma"
|
|
248
|
+
)} file and you will not be able to generate Prisma Client with the ${(0, import_chunk_SKRR5WT4.bold)(
|
|
249
|
+
(0, import_internals.getCommandWithExecutor)("prisma generate")
|
|
250
|
+
)} command.
|
|
251
|
+
|
|
252
|
+
${(0, import_chunk_SKRR5WT4.bold)("To fix this, you have two options:")}
|
|
253
|
+
|
|
254
|
+
- manually create a database.
|
|
255
|
+
- make sure the database connection URL inside the ${(0, import_chunk_SKRR5WT4.bold)("datasource")} block in ${(0, import_chunk_SKRR5WT4.bold)(
|
|
256
|
+
"schema.prisma"
|
|
257
|
+
)} points to an existing database.
|
|
258
|
+
|
|
259
|
+
Then you can run ${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExecutor)("prisma db pull"))} again.
|
|
260
|
+
`);
|
|
261
|
+
} else if (e.code === "P1012") {
|
|
262
|
+
process.stdout.write("\n");
|
|
263
|
+
const message = (0, import_internals.relativizePathInPSLError)(e.message);
|
|
264
|
+
throw new Error(`${(0, import_chunk_SKRR5WT4.red)(message)}
|
|
265
|
+
Introspection failed as your current Prisma schema file is invalid
|
|
266
|
+
|
|
267
|
+
Please fix your current schema manually (using either ${(0, import_chunk_SKRR5WT4.green)(
|
|
268
|
+
(0, import_internals.getCommandWithExecutor)("prisma validate")
|
|
269
|
+
)} or the Prisma VS Code extension to understand what's broken and confirm you fixed it), and then run this command again.
|
|
270
|
+
Or run this command with the ${(0, import_chunk_SKRR5WT4.green)(
|
|
271
|
+
"--force"
|
|
272
|
+
)} flag to ignore your current schema and overwrite it. All local modifications will be lost.
|
|
273
|
+
`);
|
|
274
|
+
}
|
|
275
|
+
process.stdout.write("\n");
|
|
276
|
+
throw e;
|
|
277
|
+
}
|
|
278
|
+
const introspectionWarningsMessage = this.getWarningMessage(introspectionWarnings);
|
|
279
|
+
if (args["--print"]) {
|
|
280
|
+
(0, import_chunk_AHJ2N6BJ.printIntrospectedSchema)(introspectionSchema, process.stdout);
|
|
281
|
+
if (introspectionWarningsMessage.trim().length > 0) {
|
|
282
|
+
console.error(introspectionWarningsMessage.replace(/(\n)/gm, "\n// "));
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
schemaPath = schemaPath || "schema.prisma";
|
|
286
|
+
if (args["--force"]) {
|
|
287
|
+
await (0, import_chunk_JZ75RIMZ.removeSchemaFiles)(schema);
|
|
288
|
+
}
|
|
289
|
+
await (0, import_chunk_RTGQXNX6.saveSchemaFiles)(introspectionSchema);
|
|
290
|
+
const { modelsCount, typesCount } = (0, import_chunk_LGYRZ6CV.countModelsAndTypes)(introspectionSchema);
|
|
291
|
+
const modelsCountMessage = `${modelsCount} ${modelsCount > 1 ? "models" : "model"}`;
|
|
292
|
+
const typesCountMessage = `${typesCount} ${typesCount > 1 ? "embedded documents" : "embedded document"}`;
|
|
293
|
+
let modelsAndTypesMessage;
|
|
294
|
+
if (typesCount > 0) {
|
|
295
|
+
modelsAndTypesMessage = `${modelsCountMessage} and ${typesCountMessage}`;
|
|
296
|
+
} else {
|
|
297
|
+
modelsAndTypesMessage = `${modelsCountMessage}`;
|
|
298
|
+
}
|
|
299
|
+
const modelsAndTypesCountMessage = modelsCount + typesCount > 1 ? `${modelsAndTypesMessage} and wrote them` : `${modelsAndTypesMessage} and wrote it`;
|
|
300
|
+
const renderValidationWarning = validationWarning ? `
|
|
301
|
+
${(0, import_chunk_SKRR5WT4.yellow)(validationWarning)}` : "";
|
|
302
|
+
introspectionSpinner.success(`Introspected ${modelsAndTypesCountMessage} into ${(0, import_chunk_SKRR5WT4.underline)(
|
|
303
|
+
import_path.default.relative(process.cwd(), schemaPath)
|
|
304
|
+
)} in ${(0, import_chunk_SKRR5WT4.bold)((0, import_internals.formatms)(Math.round(performance.now()) - before))}
|
|
305
|
+
${(0, import_chunk_SKRR5WT4.yellow)(introspectionWarningsMessage)}
|
|
306
|
+
${`Run ${(0, import_chunk_SKRR5WT4.green)((0, import_internals.getCommandWithExecutor)("prisma generate"))} to generate Prisma Client.`}${renderValidationWarning}`);
|
|
307
|
+
}
|
|
308
|
+
return "";
|
|
309
|
+
}
|
|
310
|
+
getWarningMessage(warnings) {
|
|
311
|
+
if (warnings) {
|
|
312
|
+
return `
|
|
313
|
+
${warnings}`;
|
|
314
|
+
}
|
|
315
|
+
return "";
|
|
316
|
+
}
|
|
317
|
+
help(error) {
|
|
318
|
+
if (error) {
|
|
319
|
+
return new import_internals.HelpError(`
|
|
320
|
+
${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
|
|
321
|
+
${_DbPull2.help}`);
|
|
322
|
+
}
|
|
323
|
+
return _DbPull2.help;
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
_DbPull.help = (0, import_internals.format)(`
|
|
327
|
+
Pull the state from the database to the Prisma schema using introspection
|
|
328
|
+
|
|
329
|
+
${(0, import_chunk_SKRR5WT4.bold)("Usage")}
|
|
330
|
+
|
|
331
|
+
${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull [flags/options]
|
|
332
|
+
|
|
333
|
+
${(0, import_chunk_SKRR5WT4.bold)("Flags")}
|
|
334
|
+
|
|
335
|
+
-h, --help Display this help message
|
|
336
|
+
--force Ignore current Prisma schema file
|
|
337
|
+
--print Print the introspected Prisma schema to stdout
|
|
338
|
+
|
|
339
|
+
${(0, import_chunk_SKRR5WT4.bold)("Options")}
|
|
340
|
+
|
|
341
|
+
--config Custom path to your Prisma config file
|
|
342
|
+
--schema Custom path to your Prisma schema
|
|
343
|
+
--composite-type-depth Specify the depth for introspecting composite types (e.g. Embedded Documents in MongoDB)
|
|
344
|
+
Number, default is -1 for infinite depth, 0 = off
|
|
345
|
+
--schemas Specify the database schemas to introspect. This overrides the schemas defined in the datasource block of your Prisma schema.
|
|
346
|
+
--local-d1 Generate a Prisma schema from a local Cloudflare D1 database
|
|
347
|
+
${(0, import_chunk_SKRR5WT4.bold)("Examples")}
|
|
348
|
+
|
|
349
|
+
With an existing Prisma schema
|
|
350
|
+
${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull
|
|
351
|
+
|
|
352
|
+
Or specify a Prisma schema path
|
|
353
|
+
${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --schema=./schema.prisma
|
|
354
|
+
|
|
355
|
+
Instead of saving the result to the filesystem, you can also print it to stdout
|
|
356
|
+
${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --print
|
|
357
|
+
|
|
358
|
+
Overwrite the current schema with the introspected schema instead of enriching it
|
|
359
|
+
${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --force
|
|
360
|
+
|
|
361
|
+
Set composite types introspection depth to 2 levels
|
|
362
|
+
${(0, import_chunk_SKRR5WT4.dim)("$")} prisma db pull --composite-type-depth=2
|
|
363
|
+
|
|
364
|
+
`);
|
|
365
|
+
var DbPull = _DbPull;
|
|
@@ -0,0 +1,122 @@
|
|
|
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_WNH2ACJS_exports = {};
|
|
20
|
+
__export(chunk_WNH2ACJS_exports, {
|
|
21
|
+
MigrateCommand: () => MigrateCommand
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(chunk_WNH2ACJS_exports);
|
|
24
|
+
var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
|
|
25
|
+
var import_internals = require("@prisma/internals");
|
|
26
|
+
var _MigrateCommand = class _MigrateCommand2 {
|
|
27
|
+
constructor(cmds) {
|
|
28
|
+
this.cmds = cmds;
|
|
29
|
+
}
|
|
30
|
+
static new(cmds) {
|
|
31
|
+
return new _MigrateCommand2(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
|
+
"--preview-feature": Boolean,
|
|
39
|
+
"--telemetry-information": String
|
|
40
|
+
});
|
|
41
|
+
if ((0, import_internals.isError)(args)) {
|
|
42
|
+
return this.help(args.message);
|
|
43
|
+
}
|
|
44
|
+
if (args._.length === 0 || args["--help"]) {
|
|
45
|
+
return this.help();
|
|
46
|
+
}
|
|
47
|
+
const commandName = args._[0];
|
|
48
|
+
const cmd = this.cmds[commandName];
|
|
49
|
+
if (cmd) {
|
|
50
|
+
let argsForCmd;
|
|
51
|
+
if (commandName === "diff") {
|
|
52
|
+
argsForCmd = args["--preview-feature"] ? [...args._.slice(1), `--preview-feature`] : args._.slice(1);
|
|
53
|
+
} else {
|
|
54
|
+
const filteredArgs = args._.filter((item) => item !== "--preview-feature");
|
|
55
|
+
argsForCmd = filteredArgs.slice(1);
|
|
56
|
+
}
|
|
57
|
+
return cmd.parse(argsForCmd, config);
|
|
58
|
+
}
|
|
59
|
+
return (0, import_internals.unknownCommand)(_MigrateCommand2.help, commandName);
|
|
60
|
+
}
|
|
61
|
+
help(error) {
|
|
62
|
+
if (error) {
|
|
63
|
+
return new import_internals.HelpError(`
|
|
64
|
+
${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
|
|
65
|
+
${_MigrateCommand2.help}`);
|
|
66
|
+
}
|
|
67
|
+
return _MigrateCommand2.help;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
_MigrateCommand.help = (0, import_internals.format)(`
|
|
71
|
+
Update the database schema with migrations
|
|
72
|
+
|
|
73
|
+
${(0, import_chunk_SKRR5WT4.bold)("Usage")}
|
|
74
|
+
|
|
75
|
+
${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate [command] [options]
|
|
76
|
+
|
|
77
|
+
${(0, import_chunk_SKRR5WT4.bold)("Commands for development")}
|
|
78
|
+
|
|
79
|
+
dev Create a migration from changes in Prisma schema, apply it to the database
|
|
80
|
+
trigger generators (e.g. Prisma Client)
|
|
81
|
+
reset Reset your database and apply all migrations, all data will be lost
|
|
82
|
+
|
|
83
|
+
${(0, import_chunk_SKRR5WT4.bold)("Commands for production/staging")}
|
|
84
|
+
|
|
85
|
+
deploy Apply pending migrations to the database
|
|
86
|
+
status Check the status of your database migrations
|
|
87
|
+
resolve Resolve issues with database migrations, i.e. baseline, failed migration, hotfix
|
|
88
|
+
|
|
89
|
+
${(0, import_chunk_SKRR5WT4.bold)("Command for any stage")}
|
|
90
|
+
|
|
91
|
+
diff Compare the database schema from two arbitrary sources
|
|
92
|
+
|
|
93
|
+
${(0, import_chunk_SKRR5WT4.bold)("Options")}
|
|
94
|
+
|
|
95
|
+
-h, --help Display this help message
|
|
96
|
+
--config Custom path to your Prisma config file
|
|
97
|
+
--schema Custom path to your Prisma schema
|
|
98
|
+
|
|
99
|
+
${(0, import_chunk_SKRR5WT4.bold)("Examples")}
|
|
100
|
+
|
|
101
|
+
Create a migration from changes in Prisma schema, apply it to the database, trigger generators (e.g. Prisma Client)
|
|
102
|
+
${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate dev
|
|
103
|
+
|
|
104
|
+
Reset your database and apply all migrations
|
|
105
|
+
${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate reset
|
|
106
|
+
|
|
107
|
+
Apply pending migrations to the database in production/staging
|
|
108
|
+
${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate deploy
|
|
109
|
+
|
|
110
|
+
Check the status of migrations in the production/staging database
|
|
111
|
+
${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate status
|
|
112
|
+
|
|
113
|
+
Specify a schema
|
|
114
|
+
${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate status --schema=./schema.prisma
|
|
115
|
+
|
|
116
|
+
Compare the database schema from two databases and render the diff as a SQL script
|
|
117
|
+
${(0, import_chunk_SKRR5WT4.dim)("$")} prisma migrate diff \\
|
|
118
|
+
--from-url "$DATABASE_URL" \\
|
|
119
|
+
--to-url "postgresql://login:password@localhost:5432/db" \\
|
|
120
|
+
--script
|
|
121
|
+
`);
|
|
122
|
+
var MigrateCommand = _MigrateCommand;
|