@prisma/migrate 5.23.0-dev.11 → 5.23.0-dev.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,424 +0,0 @@
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_EFPE3Q7J_exports = {};
30
- __export(chunk_EFPE3Q7J_exports, {
31
- executeSeedCommand: () => executeSeedCommand,
32
- getSeedCommandFromPackageJson: () => getSeedCommandFromPackageJson,
33
- init_seed: () => init_seed,
34
- legacyTsNodeScriptWarning: () => legacyTsNodeScriptWarning,
35
- verifySeedConfigAndReturnMessage: () => verifySeedConfigAndReturnMessage
36
- });
37
- module.exports = __toCommonJS(chunk_EFPE3Q7J_exports);
38
- var import_chunk_WIZM7TFT = require("./chunk-WIZM7TFT.js");
39
- var import_chunk_6TE2RIPN = require("./chunk-6TE2RIPN.js");
40
- var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
41
- var import_debug = __toESM(require("@prisma/debug"));
42
- var import_internals = require("@prisma/internals");
43
- var import_fs = __toESM(require("fs"));
44
- var import_path = __toESM(require("path"));
45
- var require_has_yarn = (0, import_chunk_WWAWV7DQ.__commonJS)({
46
- "../../node_modules/.pnpm/has-yarn@2.1.0/node_modules/has-yarn/index.js"(exports, module2) {
47
- "use strict";
48
- var path2 = (0, import_chunk_WWAWV7DQ.__require)("path");
49
- var fs2 = (0, import_chunk_WWAWV7DQ.__require)("fs");
50
- var hasYarn2 = (cwd = process.cwd()) => fs2.existsSync(path2.resolve(cwd, "yarn.lock"));
51
- module2.exports = hasYarn2;
52
- module2.exports.default = hasYarn2;
53
- }
54
- });
55
- var require_path_exists = (0, import_chunk_WWAWV7DQ.__commonJS)({
56
- "../../node_modules/.pnpm/path-exists@3.0.0/node_modules/path-exists/index.js"(exports, module2) {
57
- "use strict";
58
- var fs2 = (0, import_chunk_WWAWV7DQ.__require)("fs");
59
- module2.exports = (fp) => new Promise((resolve) => {
60
- fs2.access(fp, (err) => {
61
- resolve(!err);
62
- });
63
- });
64
- module2.exports.sync = (fp) => {
65
- try {
66
- fs2.accessSync(fp);
67
- return true;
68
- } catch (err) {
69
- return false;
70
- }
71
- };
72
- }
73
- });
74
- var require_p_try = (0, import_chunk_WWAWV7DQ.__commonJS)({
75
- "../../node_modules/.pnpm/p-try@2.2.0/node_modules/p-try/index.js"(exports, module2) {
76
- "use strict";
77
- var pTry = (fn, ...arguments_) => new Promise((resolve) => {
78
- resolve(fn(...arguments_));
79
- });
80
- module2.exports = pTry;
81
- module2.exports.default = pTry;
82
- }
83
- });
84
- var require_p_limit = (0, import_chunk_WWAWV7DQ.__commonJS)({
85
- "../../node_modules/.pnpm/p-limit@2.3.0/node_modules/p-limit/index.js"(exports, module2) {
86
- "use strict";
87
- var pTry = require_p_try();
88
- var pLimit = (concurrency) => {
89
- if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
90
- return Promise.reject(new TypeError("Expected `concurrency` to be a number from 1 and up"));
91
- }
92
- const queue = [];
93
- let activeCount = 0;
94
- const next = () => {
95
- activeCount--;
96
- if (queue.length > 0) {
97
- queue.shift()();
98
- }
99
- };
100
- const run = (fn, resolve, ...args) => {
101
- activeCount++;
102
- const result = pTry(fn, ...args);
103
- resolve(result);
104
- result.then(next, next);
105
- };
106
- const enqueue = (fn, resolve, ...args) => {
107
- if (activeCount < concurrency) {
108
- run(fn, resolve, ...args);
109
- } else {
110
- queue.push(run.bind(null, fn, resolve, ...args));
111
- }
112
- };
113
- const generator = (fn, ...args) => new Promise((resolve) => enqueue(fn, resolve, ...args));
114
- Object.defineProperties(generator, {
115
- activeCount: {
116
- get: () => activeCount
117
- },
118
- pendingCount: {
119
- get: () => queue.length
120
- },
121
- clearQueue: {
122
- value: () => {
123
- queue.length = 0;
124
- }
125
- }
126
- });
127
- return generator;
128
- };
129
- module2.exports = pLimit;
130
- module2.exports.default = pLimit;
131
- }
132
- });
133
- var require_p_locate = (0, import_chunk_WWAWV7DQ.__commonJS)({
134
- "../../node_modules/.pnpm/p-locate@3.0.0/node_modules/p-locate/index.js"(exports, module2) {
135
- "use strict";
136
- var pLimit = require_p_limit();
137
- var EndError = class extends Error {
138
- constructor(value) {
139
- super();
140
- this.value = value;
141
- }
142
- };
143
- var testElement = (el, tester) => Promise.resolve(el).then(tester);
144
- var finder = (el) => Promise.all(el).then((val) => val[1] === true && Promise.reject(new EndError(val[0])));
145
- module2.exports = (iterable, tester, opts) => {
146
- opts = Object.assign({
147
- concurrency: Infinity,
148
- preserveOrder: true
149
- }, opts);
150
- const limit = pLimit(opts.concurrency);
151
- const items = [...iterable].map((el) => [el, limit(testElement, el, tester)]);
152
- const checkLimit = pLimit(opts.preserveOrder ? 1 : Infinity);
153
- return Promise.all(items.map((el) => checkLimit(finder, el))).then(() => {
154
- }).catch((err) => err instanceof EndError ? err.value : Promise.reject(err));
155
- };
156
- }
157
- });
158
- var require_locate_path = (0, import_chunk_WWAWV7DQ.__commonJS)({
159
- "../../node_modules/.pnpm/locate-path@3.0.0/node_modules/locate-path/index.js"(exports, module2) {
160
- "use strict";
161
- var path2 = (0, import_chunk_WWAWV7DQ.__require)("path");
162
- var pathExists = require_path_exists();
163
- var pLocate = require_p_locate();
164
- module2.exports = (iterable, options) => {
165
- options = Object.assign({
166
- cwd: process.cwd()
167
- }, options);
168
- return pLocate(iterable, (el) => pathExists(path2.resolve(options.cwd, el)), options);
169
- };
170
- module2.exports.sync = (iterable, options) => {
171
- options = Object.assign({
172
- cwd: process.cwd()
173
- }, options);
174
- for (const el of iterable) {
175
- if (pathExists.sync(path2.resolve(options.cwd, el))) {
176
- return el;
177
- }
178
- }
179
- };
180
- }
181
- });
182
- var require_find_up = (0, import_chunk_WWAWV7DQ.__commonJS)({
183
- "../../node_modules/.pnpm/find-up@3.0.0/node_modules/find-up/index.js"(exports, module2) {
184
- "use strict";
185
- var path2 = (0, import_chunk_WWAWV7DQ.__require)("path");
186
- var locatePath = require_locate_path();
187
- module2.exports = (filename, opts = {}) => {
188
- const startDir = path2.resolve(opts.cwd || "");
189
- const { root } = path2.parse(startDir);
190
- const filenames = [].concat(filename);
191
- return new Promise((resolve) => {
192
- (function find(dir) {
193
- locatePath(filenames, { cwd: dir }).then((file) => {
194
- if (file) {
195
- resolve(path2.join(dir, file));
196
- } else if (dir === root) {
197
- resolve(null);
198
- } else {
199
- find(path2.dirname(dir));
200
- }
201
- });
202
- })(startDir);
203
- });
204
- };
205
- module2.exports.sync = (filename, opts = {}) => {
206
- let dir = path2.resolve(opts.cwd || "");
207
- const { root } = path2.parse(dir);
208
- const filenames = [].concat(filename);
209
- while (true) {
210
- const file = locatePath.sync(filenames, { cwd: dir });
211
- if (file) {
212
- return path2.join(dir, file);
213
- }
214
- if (dir === root) {
215
- return null;
216
- }
217
- dir = path2.dirname(dir);
218
- }
219
- };
220
- }
221
- });
222
- var require_pkg_up = (0, import_chunk_WWAWV7DQ.__commonJS)({
223
- "../../node_modules/.pnpm/pkg-up@3.1.0/node_modules/pkg-up/index.js"(exports, module2) {
224
- "use strict";
225
- var findUp = require_find_up();
226
- module2.exports = async ({ cwd } = {}) => findUp("package.json", { cwd });
227
- module2.exports.sync = ({ cwd } = {}) => findUp.sync("package.json", { cwd });
228
- }
229
- });
230
- async function verifySeedConfigAndReturnMessage(schemaPath) {
231
- const cwd = process.cwd();
232
- const detected = detectSeedFiles(cwd, schemaPath);
233
- const prismaConfig = await (0, import_internals.getPrismaConfigFromPackageJson)(cwd);
234
- if (prismaConfig && prismaConfig.data?.seed) {
235
- return void 0;
236
- }
237
- const packageManager = (0, import_has_yarn.default)() ? "yarn add -D" : "npm i -D";
238
- let message = `${(0, import_chunk_6TE2RIPN.red)(
239
- 'To configure seeding in your project you need to add a "prisma.seed" property in your package.json with the command to execute it:'
240
- )}
241
-
242
- 1. Open the package.json of your project
243
- `;
244
- if (detected.numberOfSeedFiles) {
245
- await legacyTsNodeScriptWarning();
246
- message += `2. Add the following example to it:`;
247
- if (detected.js) {
248
- message += `
249
- \`\`\`
250
- "prisma": {
251
- "seed": "node ${detected.js}"
252
- }
253
- \`\`\`
254
- `;
255
- } else if (detected.ts) {
256
- message += `
257
- \`\`\`
258
- "prisma": {
259
- "seed": "ts-node ${detected.ts}"
260
- }
261
- \`\`\`
262
- If you are using ESM (ECMAScript modules):
263
- \`\`\`
264
- "prisma": {
265
- "seed": "node --loader ts-node/esm ${detected.ts}"
266
- }
267
- \`\`\`
268
-
269
- 3. Install the required dependencies by running:
270
- ${(0, import_chunk_6TE2RIPN.green)(`${packageManager} ts-node typescript @types/node`)}
271
- `;
272
- } else if (detected.sh) {
273
- message += `
274
- \`\`\`
275
- "prisma": {
276
- "seed": "${detected.sh}"
277
- }
278
- \`\`\`
279
- And run \`chmod +x ${detected.sh}\` to make it executable.`;
280
- }
281
- } else {
282
- message += `2. Add one of the following examples to your package.json:
283
-
284
- ${(0, import_chunk_6TE2RIPN.bold)("TypeScript:")}
285
- \`\`\`
286
- "prisma": {
287
- "seed": "ts-node ./prisma/seed.ts"
288
- }
289
- \`\`\`
290
- If you are using ESM (ECMAScript modules):
291
- \`\`\`
292
- "prisma": {
293
- "seed": "node --loader ts-node/esm ./prisma/seed.ts"
294
- }
295
- \`\`\`
296
-
297
- And install the required dependencies by running:
298
- ${packageManager} ts-node typescript @types/node
299
-
300
- ${(0, import_chunk_6TE2RIPN.bold)("JavaScript:")}
301
- \`\`\`
302
- "prisma": {
303
- "seed": "node ./prisma/seed.js"
304
- }
305
- \`\`\`
306
-
307
- ${(0, import_chunk_6TE2RIPN.bold)("Bash:")}
308
- \`\`\`
309
- "prisma": {
310
- "seed": "./prisma/seed.sh"
311
- }
312
- \`\`\`
313
- And run \`chmod +x prisma/seed.sh\` to make it executable.`;
314
- }
315
- message += `
316
- More information in our documentation:
317
- ${(0, import_internals.link)("https://pris.ly/d/seeding")}`;
318
- return message;
319
- }
320
- async function getSeedCommandFromPackageJson(cwd) {
321
- const prismaConfig = await (0, import_internals.getPrismaConfigFromPackageJson)(cwd);
322
- debug({ prismaConfig });
323
- if (!prismaConfig || !prismaConfig.data?.seed) {
324
- return null;
325
- }
326
- const seedCommandFromPkgJson = prismaConfig.data.seed;
327
- if (typeof seedCommandFromPkgJson !== "string") {
328
- throw new Error(
329
- `Provided seed command \`${seedCommandFromPkgJson}\` from \`${import_path.default.relative(
330
- cwd,
331
- prismaConfig.packagePath
332
- )}\` must be of type string`
333
- );
334
- }
335
- if (!seedCommandFromPkgJson) {
336
- throw new Error(
337
- `Provided seed command \`${seedCommandFromPkgJson}\` from \`${import_path.default.relative(
338
- cwd,
339
- prismaConfig.packagePath
340
- )}\` cannot be empty`
341
- );
342
- }
343
- return seedCommandFromPkgJson;
344
- }
345
- async function executeSeedCommand({
346
- commandFromConfig,
347
- extraArgs
348
- }) {
349
- const command = extraArgs ? `${commandFromConfig} ${extraArgs}` : commandFromConfig;
350
- process.stdout.write(`Running seed command \`${(0, import_chunk_6TE2RIPN.italic)(command)}\` ...
351
- `);
352
- try {
353
- await import_execa.default.command(command, {
354
- stdout: "inherit",
355
- stderr: "inherit"
356
- });
357
- } catch (_e) {
358
- const e = _e;
359
- debug({ e });
360
- console.error((0, import_chunk_6TE2RIPN.bold)((0, import_chunk_6TE2RIPN.red)(`
361
- An error occurred while running the seed command:`)));
362
- console.error((0, import_chunk_6TE2RIPN.red)(e.stderr || String(e)));
363
- return false;
364
- }
365
- return true;
366
- }
367
- function detectSeedFiles(cwd, schemaPath) {
368
- let parentDirectory = import_path.default.relative(cwd, import_path.default.join(cwd, "prisma"));
369
- if (schemaPath) {
370
- parentDirectory = import_path.default.relative(cwd, import_path.default.dirname(schemaPath));
371
- }
372
- const seedPath = import_path.default.join(parentDirectory, "seed.");
373
- const detected = {
374
- seedPath,
375
- numberOfSeedFiles: 0,
376
- js: "",
377
- ts: "",
378
- sh: ""
379
- };
380
- const extensions = ["js", "ts", "sh"];
381
- for (const extension of extensions) {
382
- const fullPath = seedPath + extension;
383
- if (!import_fs.default.existsSync(fullPath)) {
384
- continue;
385
- }
386
- detected[extension] = fullPath;
387
- detected.numberOfSeedFiles++;
388
- }
389
- debug({ detected });
390
- return detected;
391
- }
392
- async function legacyTsNodeScriptWarning() {
393
- const scripts = await getScriptsFromPackageJson();
394
- if (scripts?.["ts-node"]) {
395
- import_internals.logger.warn(
396
- (0, import_chunk_6TE2RIPN.yellow)(`The "ts-node" script in the package.json is not used anymore since version 3.0 and can now be removed.`)
397
- );
398
- }
399
- return void 0;
400
- }
401
- async function getScriptsFromPackageJson(cwd = process.cwd()) {
402
- try {
403
- const pkgJsonPath = await (0, import_pkg_up.default)({ cwd });
404
- if (!pkgJsonPath) {
405
- return null;
406
- }
407
- const pkgJsonString = await import_fs.default.promises.readFile(pkgJsonPath, "utf-8");
408
- const pkgJson = JSON.parse(pkgJsonString);
409
- const { "ts-node": tsnode } = pkgJson.scripts;
410
- return { "ts-node": tsnode };
411
- } catch {
412
- return null;
413
- }
414
- }
415
- var import_execa, import_has_yarn, import_pkg_up, debug;
416
- var init_seed = (0, import_chunk_WWAWV7DQ.__esm)({
417
- "src/utils/seed.ts"() {
418
- import_execa = (0, import_chunk_WWAWV7DQ.__toESM)((0, import_chunk_WIZM7TFT.require_execa)());
419
- import_has_yarn = (0, import_chunk_WWAWV7DQ.__toESM)(require_has_yarn());
420
- (0, import_chunk_6TE2RIPN.init_colors)();
421
- import_pkg_up = (0, import_chunk_WWAWV7DQ.__toESM)(require_pkg_up());
422
- debug = (0, import_debug.default)("prisma:migrate:seed");
423
- }
424
- });
@@ -1,9 +0,0 @@
1
- /**
2
- * Warn, if yarn is older than 1.19.2 because Yarn used to remove all dot
3
- * folders inside node_modules before. We use node_modules/.prisma/client
4
- * directory as default location for generated Prisma Client. Changelog
5
- * https://github.com/yarnpkg/yarn/blob/HEAD/CHANGELOG.md#1192
6
- * https://www.prisma.io/docs/reference/system-requirements#software-requirements
7
- * // TODO Maybe we replace this with the "engines" field in package.json
8
- */
9
- export declare function checkYarnVersion(): void;