@augment-vir/node 31.41.0 → 31.43.0
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/augments/terminal/shell.js +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/package.json +6 -6
- package/src/augments/terminal/shell.ts +1 -0
- package/src/index.ts +0 -1
- package/dist/augments/prisma.d.ts +0 -157
- package/dist/augments/prisma.js +0 -156
- package/dist/prisma/disable-ci-env.mock.d.ts +0 -2
- package/dist/prisma/disable-ci-env.mock.js +0 -81
- package/dist/prisma/model-data.d.ts +0 -88
- package/dist/prisma/model-data.js +0 -84
- package/dist/prisma/prisma-client.d.ts +0 -5
- package/dist/prisma/prisma-client.js +0 -25
- package/dist/prisma/prisma-database.d.ts +0 -11
- package/dist/prisma/prisma-database.js +0 -30
- package/dist/prisma/prisma-database.mock.d.ts +0 -1
- package/dist/prisma/prisma-database.mock.js +0 -25
- package/dist/prisma/prisma-errors.d.ts +0 -37
- package/dist/prisma/prisma-errors.js +0 -43
- package/dist/prisma/prisma-migrations.d.ts +0 -24
- package/dist/prisma/prisma-migrations.js +0 -98
- package/dist/prisma/run-prisma-command.d.ts +0 -29
- package/dist/prisma/run-prisma-command.js +0 -67
- package/src/augments/prisma.ts +0 -177
- package/src/prisma/disable-ci-env.mock.ts +0 -88
- package/src/prisma/model-data.ts +0 -252
- package/src/prisma/prisma-client.ts +0 -45
- package/src/prisma/prisma-database.mock.ts +0 -31
- package/src/prisma/prisma-database.ts +0 -60
- package/src/prisma/prisma-errors.ts +0 -45
- package/src/prisma/prisma-migrations.ts +0 -153
- package/src/prisma/run-prisma-command.ts +0 -94
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-deprecated */
|
|
2
|
-
import { collapseWhiteSpace } from '@augment-vir/common';
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
4
|
-
import { readFile } from 'node:fs/promises';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import { runPrismaCommand } from './run-prisma-command.js';
|
|
7
|
-
export async function generatePrismaClient(schemaFilePath, env = {}) {
|
|
8
|
-
await runPrismaCommand({ command: 'generate' }, schemaFilePath, env);
|
|
9
|
-
}
|
|
10
|
-
async function areSchemasEqual(originalSchema, generatedClientSchema) {
|
|
11
|
-
if (!existsSync(originalSchema)) {
|
|
12
|
-
throw new Error(`Schema file does not exist: '${originalSchema}'`);
|
|
13
|
-
}
|
|
14
|
-
else if (!existsSync(generatedClientSchema)) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
const originalSchemaContents = String(await readFile(originalSchema));
|
|
18
|
-
const generatedClientSchemaContents = String(await readFile(generatedClientSchema));
|
|
19
|
-
return (collapseWhiteSpace(originalSchemaContents, { keepNewLines: true }) ===
|
|
20
|
-
collapseWhiteSpace(generatedClientSchemaContents, { keepNewLines: true }));
|
|
21
|
-
}
|
|
22
|
-
export async function isGeneratedPrismaClientCurrent({ jsClientOutputDir, schemaFilePath, }) {
|
|
23
|
-
const clientSchemaFilePath = join(jsClientOutputDir, 'schema.prisma');
|
|
24
|
-
return areSchemasEqual(schemaFilePath, clientSchemaFilePath);
|
|
25
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare function getPrismaDiff(schemaFilePath: string, env?: Record<string, string>): Promise<string>;
|
|
2
|
-
export declare function doesPrismaDiffExist(schemaFilePath: string, env?: Record<string, string>): Promise<boolean>;
|
|
3
|
-
export declare function resetDevPrismaDatabase(schemaFilePath: string, options: {
|
|
4
|
-
/**
|
|
5
|
-
* If you already have migrations created, set this to `true`. If you don't, set it to
|
|
6
|
-
* `false`. If you don't know which one to use, try both, see which one creates a valid
|
|
7
|
-
* database for you (try querying it with PrismaClient after running this; if it errors,
|
|
8
|
-
* this didn't create a valid database).
|
|
9
|
-
*/
|
|
10
|
-
withMigrations: boolean;
|
|
11
|
-
}, env?: Record<string, string>): Promise<void>;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-deprecated */
|
|
2
|
-
import { runPrismaCommand } from './run-prisma-command.js';
|
|
3
|
-
export async function getPrismaDiff(schemaFilePath, env = {}) {
|
|
4
|
-
const command = [
|
|
5
|
-
'migrate',
|
|
6
|
-
'diff',
|
|
7
|
-
`--from-schema-datamodel='${schemaFilePath}'`,
|
|
8
|
-
`--to-schema-datasource='${schemaFilePath}'`,
|
|
9
|
-
].join(' ');
|
|
10
|
-
const results = await runPrismaCommand({ command }, undefined, env);
|
|
11
|
-
if (results.stdout.trim() === 'No difference detected.') {
|
|
12
|
-
return '';
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
return results.stdout.trim();
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export async function doesPrismaDiffExist(schemaFilePath, env = {}) {
|
|
19
|
-
return !!(await getPrismaDiff(schemaFilePath, env));
|
|
20
|
-
}
|
|
21
|
-
export async function resetDevPrismaDatabase(schemaFilePath, options, env = {}) {
|
|
22
|
-
if (options.withMigrations) {
|
|
23
|
-
await runPrismaCommand({ command: 'migrate reset --force --skip-generate --skip-seed' }, schemaFilePath, env);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
await runPrismaCommand({
|
|
27
|
-
command: 'db push --accept-data-loss --skip-generate',
|
|
28
|
-
}, schemaFilePath, env);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function clearTestDatabaseOutputs(): Promise<void>;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { awaitedForEach, retry, wait } from '@augment-vir/common';
|
|
2
|
-
import { interpolationSafeWindowsPath } from '../augments/path/os-path.js';
|
|
3
|
-
import { runShellCommand } from '../augments/terminal/shell.js';
|
|
4
|
-
import { generatedPrismaClientDirPath, notCommittedDirPath, testPrismaMigrationsDirPath, } from '../file-paths.mock.js';
|
|
5
|
-
const pathsToDelete = [
|
|
6
|
-
generatedPrismaClientDirPath,
|
|
7
|
-
notCommittedDirPath,
|
|
8
|
-
testPrismaMigrationsDirPath,
|
|
9
|
-
];
|
|
10
|
-
export async function clearTestDatabaseOutputs() {
|
|
11
|
-
await retry(10, async () => {
|
|
12
|
-
await wait({ seconds: 1 });
|
|
13
|
-
await awaitedForEach(pathsToDelete, async (pathToDelete) => {
|
|
14
|
-
/**
|
|
15
|
-
* This way of deleting files is required for Windows tests running on GitHub Actions.
|
|
16
|
-
* Otherwise, we get the following error:
|
|
17
|
-
*
|
|
18
|
-
* EPERM: operation not permitted, unlink 'D:\a\augment-vir\augment-vir\packages\node\node_modules\.prisma\query_engine-windows.dll.node'
|
|
19
|
-
*/
|
|
20
|
-
await runShellCommand(`rm -rf ${interpolationSafeWindowsPath(pathToDelete)}`, {
|
|
21
|
-
rejectOnError: true,
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An error thrown by the Prisma API that indicates that something is wrong with the given Prisma
|
|
3
|
-
* schema. See the error message for more details.
|
|
4
|
-
*
|
|
5
|
-
* @category Prisma : Node : Util
|
|
6
|
-
* @category Package : @augment-vir/node
|
|
7
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
8
|
-
*/
|
|
9
|
-
export declare class PrismaSchemaError extends Error {
|
|
10
|
-
readonly name = "PrismaSchemaError";
|
|
11
|
-
constructor(message: string);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* An error thrown by the Prisma API that indicates that applying migrations in dev failed such that
|
|
15
|
-
* a new migration is needed. You can do that by prompting user for a new migration name and passing
|
|
16
|
-
* it to `prisma.migration.create`.
|
|
17
|
-
*
|
|
18
|
-
* @category Prisma : Node : Util
|
|
19
|
-
* @category Package : @augment-vir/node
|
|
20
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
21
|
-
*/
|
|
22
|
-
export declare class PrismaMigrationNeededError extends Error {
|
|
23
|
-
readonly name = "PrismaMigrationNeededError";
|
|
24
|
-
constructor(schemaFilePath: string);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* An error thrown by the Prisma API that indicates that applying migrations in dev failed such that
|
|
28
|
-
* the entire database needs to be reset. You can do that by calling `prisma.database.resetDev`.
|
|
29
|
-
*
|
|
30
|
-
* @category Prisma : Node : Util
|
|
31
|
-
* @category Package : @augment-vir/node
|
|
32
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
33
|
-
*/
|
|
34
|
-
export declare class PrismaResetNeededError extends Error {
|
|
35
|
-
readonly name = "PrismaResetNeededError";
|
|
36
|
-
constructor(schemaFilePath: string);
|
|
37
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An error thrown by the Prisma API that indicates that something is wrong with the given Prisma
|
|
3
|
-
* schema. See the error message for more details.
|
|
4
|
-
*
|
|
5
|
-
* @category Prisma : Node : Util
|
|
6
|
-
* @category Package : @augment-vir/node
|
|
7
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
8
|
-
*/
|
|
9
|
-
export class PrismaSchemaError extends Error {
|
|
10
|
-
name = 'PrismaSchemaError';
|
|
11
|
-
constructor(message) {
|
|
12
|
-
super(message);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* An error thrown by the Prisma API that indicates that applying migrations in dev failed such that
|
|
17
|
-
* a new migration is needed. You can do that by prompting user for a new migration name and passing
|
|
18
|
-
* it to `prisma.migration.create`.
|
|
19
|
-
*
|
|
20
|
-
* @category Prisma : Node : Util
|
|
21
|
-
* @category Package : @augment-vir/node
|
|
22
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
23
|
-
*/
|
|
24
|
-
export class PrismaMigrationNeededError extends Error {
|
|
25
|
-
name = 'PrismaMigrationNeededError';
|
|
26
|
-
constructor(schemaFilePath) {
|
|
27
|
-
super(`A new Prisma migration is needed for '${schemaFilePath}'`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* An error thrown by the Prisma API that indicates that applying migrations in dev failed such that
|
|
32
|
-
* the entire database needs to be reset. You can do that by calling `prisma.database.resetDev`.
|
|
33
|
-
*
|
|
34
|
-
* @category Prisma : Node : Util
|
|
35
|
-
* @category Package : @augment-vir/node
|
|
36
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
37
|
-
*/
|
|
38
|
-
export class PrismaResetNeededError extends Error {
|
|
39
|
-
name = 'PrismaResetNeededError';
|
|
40
|
-
constructor(schemaFilePath) {
|
|
41
|
-
super(`A database reset is needed for '${schemaFilePath}'`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output of `prisma.migration.status`.
|
|
3
|
-
*
|
|
4
|
-
* @deprecated Use the `prisma-vir` package instead.
|
|
5
|
-
* @category Prisma : Node : Util
|
|
6
|
-
* @category Package : @augment-vir/node
|
|
7
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
8
|
-
*/
|
|
9
|
-
export type PrismaMigrationStatus = {
|
|
10
|
-
totalMigrations: number;
|
|
11
|
-
unappliedMigrations: string[];
|
|
12
|
-
};
|
|
13
|
-
export declare function applyPrismaMigrationsToProd(schemaFilePath: string, env?: Record<string, string>): Promise<void>;
|
|
14
|
-
export declare function applyPrismaMigrationsToDev(schemaFilePath: string, env?: Record<string, string>): Promise<void>;
|
|
15
|
-
export declare function getMigrationStatus(schemaFilePath: string, env?: Record<string, string>): Promise<PrismaMigrationStatus>;
|
|
16
|
-
export declare function createPrismaMigration({ migrationName, createOnly, }: {
|
|
17
|
-
migrationName: string;
|
|
18
|
-
/**
|
|
19
|
-
* Set this to `true` to create a new migration without applying it to the database.
|
|
20
|
-
*
|
|
21
|
-
* @default false
|
|
22
|
-
*/
|
|
23
|
-
createOnly?: boolean | undefined;
|
|
24
|
-
}, schemaFilePath: string, env?: Record<string, string>): Promise<void>;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-deprecated */
|
|
2
|
-
import { check } from '@augment-vir/assert';
|
|
3
|
-
import { log, safeMatch, toEnsuredNumber } from '@augment-vir/common';
|
|
4
|
-
import terminate from 'terminate';
|
|
5
|
-
import { runShellCommand } from '../augments/terminal/shell.js';
|
|
6
|
-
import { PrismaMigrationNeededError, PrismaResetNeededError } from './prisma-errors.js';
|
|
7
|
-
import { runPrismaCommand, verifyOutput } from './run-prisma-command.js';
|
|
8
|
-
export async function applyPrismaMigrationsToProd(schemaFilePath, env = {}) {
|
|
9
|
-
await runPrismaCommand({ command: 'migrate deploy' }, schemaFilePath, env);
|
|
10
|
-
}
|
|
11
|
-
var DbChangeRequired;
|
|
12
|
-
(function (DbChangeRequired) {
|
|
13
|
-
DbChangeRequired["MigrationNeeded"] = "migration-needed";
|
|
14
|
-
DbChangeRequired["ResetNeeded"] = "reset-needed";
|
|
15
|
-
})(DbChangeRequired || (DbChangeRequired = {}));
|
|
16
|
-
export async function applyPrismaMigrationsToDev(schemaFilePath, env = {}) {
|
|
17
|
-
const command = [
|
|
18
|
-
'prisma',
|
|
19
|
-
'migrate',
|
|
20
|
-
'dev',
|
|
21
|
-
`--schema='${schemaFilePath}'`,
|
|
22
|
-
].join(' ');
|
|
23
|
-
log.faint(`> ${command}`);
|
|
24
|
-
let dbRequirement = undefined;
|
|
25
|
-
const result = await runShellCommand(command, {
|
|
26
|
-
env: {
|
|
27
|
-
...process.env,
|
|
28
|
-
...env,
|
|
29
|
-
},
|
|
30
|
-
stdoutCallback(stdout, childProcess) {
|
|
31
|
-
if (stdout.includes('Enter a name for the new migration')) {
|
|
32
|
-
if (childProcess.pid) {
|
|
33
|
-
terminate(childProcess.pid);
|
|
34
|
-
}
|
|
35
|
-
dbRequirement = DbChangeRequired.MigrationNeeded;
|
|
36
|
-
}
|
|
37
|
-
else if (stdout.includes('We need to reset the SQLite database')) {
|
|
38
|
-
if (childProcess.pid) {
|
|
39
|
-
terminate(childProcess.pid);
|
|
40
|
-
}
|
|
41
|
-
dbRequirement = DbChangeRequired.ResetNeeded;
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
if (dbRequirement === DbChangeRequired.MigrationNeeded) {
|
|
46
|
-
throw new PrismaMigrationNeededError(schemaFilePath);
|
|
47
|
-
}
|
|
48
|
-
else if (dbRequirement === DbChangeRequired.ResetNeeded) {
|
|
49
|
-
throw new PrismaResetNeededError(schemaFilePath);
|
|
50
|
-
}
|
|
51
|
-
verifyOutput(schemaFilePath, result, false);
|
|
52
|
-
}
|
|
53
|
-
export async function getMigrationStatus(schemaFilePath, env = {}) {
|
|
54
|
-
const output = await runPrismaCommand({
|
|
55
|
-
command: 'migrate status',
|
|
56
|
-
ignoreExitCode: true,
|
|
57
|
-
}, schemaFilePath, env);
|
|
58
|
-
const listedMigrations = {
|
|
59
|
-
totalMigrations: 0,
|
|
60
|
-
unappliedMigrations: [],
|
|
61
|
-
};
|
|
62
|
-
let foundNotAppliedMigrations = false;
|
|
63
|
-
output.stdout.split('\n').some((rawLine) => {
|
|
64
|
-
const line = rawLine.trim();
|
|
65
|
-
if (foundNotAppliedMigrations) {
|
|
66
|
-
if (line) {
|
|
67
|
-
listedMigrations.unappliedMigrations.push(line);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
/** We're done parsing. */
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
else if (line.endsWith('not yet been applied:')) {
|
|
75
|
-
foundNotAppliedMigrations = true;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
const [, countMatch,] = safeMatch(line, /^([\d,]+) migrations? found in/);
|
|
79
|
-
if (countMatch) {
|
|
80
|
-
listedMigrations.totalMigrations = toEnsuredNumber(countMatch);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/** Still need to keep parsing. */
|
|
84
|
-
return false;
|
|
85
|
-
});
|
|
86
|
-
return listedMigrations;
|
|
87
|
-
}
|
|
88
|
-
export async function createPrismaMigration({ migrationName, createOnly = false, }, schemaFilePath, env = {}) {
|
|
89
|
-
const command = [
|
|
90
|
-
'migrate',
|
|
91
|
-
'dev',
|
|
92
|
-
`--name='${migrationName}'`,
|
|
93
|
-
createOnly ? '--create-only' : '',
|
|
94
|
-
]
|
|
95
|
-
.filter(check.isTruthy)
|
|
96
|
-
.join(' ');
|
|
97
|
-
await runPrismaCommand({ command }, schemaFilePath, env);
|
|
98
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type PartialWithUndefined } from '@augment-vir/common';
|
|
2
|
-
import { type ShellOutput } from '../augments/terminal/shell.js';
|
|
3
|
-
/**
|
|
4
|
-
* All commands in the Prisma CLI that support the `--no-hints` flag, used to turn off ads.
|
|
5
|
-
*
|
|
6
|
-
* @deprecated Use the `prisma-vir` package instead.
|
|
7
|
-
* @category Prisma : Node : Util
|
|
8
|
-
* @category Package : @augment-vir/node
|
|
9
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
10
|
-
*/
|
|
11
|
-
export declare const prismaCommandsThatSupportNoHints: string[];
|
|
12
|
-
/**
|
|
13
|
-
* Directly run a Prisma command.
|
|
14
|
-
*
|
|
15
|
-
* @deprecated Use the `prisma-vir` package instead.
|
|
16
|
-
* @category Prisma : Node : Util
|
|
17
|
-
* @category Package : @augment-vir/node
|
|
18
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
19
|
-
*/
|
|
20
|
-
export declare function runPrismaCommand({ command, ignoreExitCode, hideLogs, }: {
|
|
21
|
-
command: string;
|
|
22
|
-
} & PartialWithUndefined<{
|
|
23
|
-
/** If `true`, prevents errors from being thrown if this command exits with a non-0 status. */
|
|
24
|
-
ignoreExitCode: boolean;
|
|
25
|
-
hideLogs: boolean;
|
|
26
|
-
}>,
|
|
27
|
-
/** Set to `undefined` to omit the `--schema` flag. */
|
|
28
|
-
schemaFilePath: string | undefined, env?: Record<string, string> | undefined): Promise<Readonly<ShellOutput>>;
|
|
29
|
-
export declare function verifyOutput(schemaFilePath: string, shellOutput: Readonly<ShellOutput>, ignoreExitCode: boolean): Readonly<ShellOutput>;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-deprecated */
|
|
2
|
-
import { log, wrapString } from '@augment-vir/common';
|
|
3
|
-
import { dirname } from 'node:path';
|
|
4
|
-
import { interpolationSafeWindowsPath } from '../augments/path/os-path.js';
|
|
5
|
-
import { runShellCommand } from '../augments/terminal/shell.js';
|
|
6
|
-
import { PrismaSchemaError } from './prisma-errors.js';
|
|
7
|
-
/**
|
|
8
|
-
* All commands in the Prisma CLI that support the `--no-hints` flag, used to turn off ads.
|
|
9
|
-
*
|
|
10
|
-
* @deprecated Use the `prisma-vir` package instead.
|
|
11
|
-
* @category Prisma : Node : Util
|
|
12
|
-
* @category Package : @augment-vir/node
|
|
13
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
14
|
-
*/
|
|
15
|
-
export const prismaCommandsThatSupportNoHints = ['generate'];
|
|
16
|
-
/**
|
|
17
|
-
* Directly run a Prisma command.
|
|
18
|
-
*
|
|
19
|
-
* @deprecated Use the `prisma-vir` package instead.
|
|
20
|
-
* @category Prisma : Node : Util
|
|
21
|
-
* @category Package : @augment-vir/node
|
|
22
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
23
|
-
*/
|
|
24
|
-
export async function runPrismaCommand({ command, ignoreExitCode = false, hideLogs = false, },
|
|
25
|
-
/** Set to `undefined` to omit the `--schema` flag. */
|
|
26
|
-
schemaFilePath, env = {}) {
|
|
27
|
-
const schemaFileArgs = schemaFilePath
|
|
28
|
-
? [
|
|
29
|
-
'--schema',
|
|
30
|
-
wrapString({ value: schemaFilePath, wrapper: "'" }),
|
|
31
|
-
]
|
|
32
|
-
: [];
|
|
33
|
-
/** Disable Prisma's in-CLI ads. */
|
|
34
|
-
const noHintsArg = prismaCommandsThatSupportNoHints.some((commandName) => command.startsWith(commandName))
|
|
35
|
-
? '--no-hints'
|
|
36
|
-
: '';
|
|
37
|
-
const fullCommand = [
|
|
38
|
-
'prisma',
|
|
39
|
-
command,
|
|
40
|
-
...schemaFileArgs,
|
|
41
|
-
noHintsArg,
|
|
42
|
-
].join(' ');
|
|
43
|
-
log.faint(`> ${fullCommand}`);
|
|
44
|
-
const result = await runShellCommand(interpolationSafeWindowsPath(fullCommand), {
|
|
45
|
-
env: {
|
|
46
|
-
...process.env,
|
|
47
|
-
...env,
|
|
48
|
-
},
|
|
49
|
-
hookUpToConsole: !hideLogs,
|
|
50
|
-
cwd: schemaFilePath ? dirname(schemaFilePath) : process.cwd(),
|
|
51
|
-
});
|
|
52
|
-
return verifyOutput(schemaFilePath || '', result, ignoreExitCode);
|
|
53
|
-
}
|
|
54
|
-
export function verifyOutput(schemaFilePath, shellOutput, ignoreExitCode) {
|
|
55
|
-
if (shellOutput.stderr.includes('Validation Error Count')) {
|
|
56
|
-
throw new PrismaSchemaError(`Invalid schema file at '${schemaFilePath}':\n\n${shellOutput.stderr}`);
|
|
57
|
-
}
|
|
58
|
-
else if (shellOutput.stderr.includes('does not exist')) {
|
|
59
|
-
throw new PrismaSchemaError(`Database does not exist: ${shellOutput.stderr}`);
|
|
60
|
-
}
|
|
61
|
-
else if (shellOutput.exitCode === 0 || ignoreExitCode) {
|
|
62
|
-
return shellOutput;
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
throw new Error(shellOutput.stdout + shellOutput.stderr);
|
|
66
|
-
}
|
|
67
|
-
}
|
package/src/augments/prisma.ts
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-deprecated */
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
4
|
-
import {PrismaMigrationNeededError, PrismaResetNeededError} from '../prisma/prisma-errors.js';
|
|
5
|
-
|
|
6
|
-
import {addData, dumpData} from '../prisma/model-data.js';
|
|
7
|
-
import {generatePrismaClient, isGeneratedPrismaClientCurrent} from '../prisma/prisma-client.js';
|
|
8
|
-
import {
|
|
9
|
-
doesPrismaDiffExist,
|
|
10
|
-
getPrismaDiff,
|
|
11
|
-
resetDevPrismaDatabase,
|
|
12
|
-
} from '../prisma/prisma-database.js';
|
|
13
|
-
import {
|
|
14
|
-
applyPrismaMigrationsToDev,
|
|
15
|
-
applyPrismaMigrationsToProd,
|
|
16
|
-
createPrismaMigration,
|
|
17
|
-
getMigrationStatus,
|
|
18
|
-
} from '../prisma/prisma-migrations.js';
|
|
19
|
-
|
|
20
|
-
export type {
|
|
21
|
-
PrismaAddDataData as PrismaAddModelData,
|
|
22
|
-
PrismaDataDumpOptions,
|
|
23
|
-
PrismaDumpOutput,
|
|
24
|
-
} from '../prisma/model-data.js';
|
|
25
|
-
export * from '../prisma/prisma-errors.js';
|
|
26
|
-
export type {PrismaMigrationStatus} from '../prisma/prisma-migrations.js';
|
|
27
|
-
export {prismaCommandsThatSupportNoHints, runPrismaCommand} from '../prisma/run-prisma-command.js';
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Centralized Prisma API from `@augment-vir/node`.
|
|
31
|
-
*
|
|
32
|
-
* ## Prisma flows
|
|
33
|
-
*
|
|
34
|
-
* - Deploy to production
|
|
35
|
-
*
|
|
36
|
-
* - `prisma.migration.applyProd()`
|
|
37
|
-
* - Update dev environment
|
|
38
|
-
*
|
|
39
|
-
* - Apply migrations: `prisma.migration.applyDev`
|
|
40
|
-
*
|
|
41
|
-
* - If throws {@link PrismaMigrationNeededError}, prompt user for a new migration name and pass it to
|
|
42
|
-
* `prisma.migration.create`
|
|
43
|
-
* - If throws {@link PrismaResetNeededError}, reset the database with `prisma.database.resetDev`
|
|
44
|
-
* - Generate client: `prisma.client.isCurrent`
|
|
45
|
-
*
|
|
46
|
-
* - If `false`, run `prisma.client.generate`
|
|
47
|
-
*
|
|
48
|
-
* @deprecated Use the `prisma-vir` package instead.
|
|
49
|
-
* @category Prisma : Node
|
|
50
|
-
* @category Package : @augment-vir/node
|
|
51
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
52
|
-
*/
|
|
53
|
-
export const prisma = {
|
|
54
|
-
migration: {
|
|
55
|
-
/**
|
|
56
|
-
* Get current migration status.
|
|
57
|
-
*
|
|
58
|
-
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-status
|
|
59
|
-
*/
|
|
60
|
-
status: getMigrationStatus,
|
|
61
|
-
/**
|
|
62
|
-
* Creates a new migration.
|
|
63
|
-
*
|
|
64
|
-
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-dev
|
|
65
|
-
*/
|
|
66
|
-
create: createPrismaMigration,
|
|
67
|
-
/**
|
|
68
|
-
* Apply all migrations. Meant for a production environment.
|
|
69
|
-
*
|
|
70
|
-
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-deploy
|
|
71
|
-
*/
|
|
72
|
-
applyProd: applyPrismaMigrationsToProd,
|
|
73
|
-
/**
|
|
74
|
-
* Apply all migrations. Meant for a development environment, with less protections than
|
|
75
|
-
* `prisma.migration.applyProd()`
|
|
76
|
-
*
|
|
77
|
-
* @throws `PrismaMigrationNeededError` when a new migration is required so the user needs
|
|
78
|
-
* to input a name.
|
|
79
|
-
* @throws `PrismaResetNeededError` when there's a migration mismatch with the database and
|
|
80
|
-
* it needs to be reset.
|
|
81
|
-
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-dev
|
|
82
|
-
*/
|
|
83
|
-
applyDev: applyPrismaMigrationsToDev,
|
|
84
|
-
},
|
|
85
|
-
database: {
|
|
86
|
-
/**
|
|
87
|
-
* Force resets a dev database to match the current Prisma schema and migrations.
|
|
88
|
-
*
|
|
89
|
-
* **This will destroy all data. Do not use in production.**
|
|
90
|
-
*
|
|
91
|
-
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-reset
|
|
92
|
-
*/
|
|
93
|
-
resetDev: resetDevPrismaDatabase,
|
|
94
|
-
/**
|
|
95
|
-
* Uses `prisma.database.diff` to detect if there are any differences between the current
|
|
96
|
-
* database and the Prisma schema that should control it.
|
|
97
|
-
*/
|
|
98
|
-
hasDiff: doesPrismaDiffExist,
|
|
99
|
-
/**
|
|
100
|
-
* Gets a string list of all differences between the current database and the Prisma schema
|
|
101
|
-
* that should control it.
|
|
102
|
-
*
|
|
103
|
-
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-diff
|
|
104
|
-
*/
|
|
105
|
-
diff: getPrismaDiff,
|
|
106
|
-
},
|
|
107
|
-
client: {
|
|
108
|
-
/**
|
|
109
|
-
* Runs Prisma generators included in the given Prisma schema (which usually includes the
|
|
110
|
-
* Prisma JS client). This will work even if the database doesn't exist yet.
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
*
|
|
114
|
-
* ```ts
|
|
115
|
-
* import {prisma} from '@augment-vir/node';
|
|
116
|
-
*
|
|
117
|
-
* prisma.client.generate('../../prisma/schema.prisma');
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
generate: generatePrismaClient,
|
|
121
|
-
/**
|
|
122
|
-
* Detects if the current generated Prisma JS Client was generated from the current Prisma
|
|
123
|
-
* schema.
|
|
124
|
-
*/
|
|
125
|
-
isCurrent: isGeneratedPrismaClientCurrent,
|
|
126
|
-
/**
|
|
127
|
-
* Adds a collection of create data entries to a database through a `PrismaClient` instance.
|
|
128
|
-
* This is particularly useful for setting up mocks in a mock PrismaClient.
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
*
|
|
132
|
-
* ```ts
|
|
133
|
-
* import {addPrismaModelData} from '@augment-vir/common';
|
|
134
|
-
* import {PrismaClient} from '@prisma/client';
|
|
135
|
-
*
|
|
136
|
-
* await addPrismaModelData(new PrismaClient(), [
|
|
137
|
-
* {
|
|
138
|
-
* user: {
|
|
139
|
-
* mockUser1: {
|
|
140
|
-
* first_name: 'one',
|
|
141
|
-
* id: 123,
|
|
142
|
-
* // etc.
|
|
143
|
-
* },
|
|
144
|
-
* mockUser2: {
|
|
145
|
-
* first_name: 'two',
|
|
146
|
-
* id: 124,
|
|
147
|
-
* authRole: 'user',
|
|
148
|
-
* // etc.
|
|
149
|
-
* },
|
|
150
|
-
* },
|
|
151
|
-
* },
|
|
152
|
-
* {
|
|
153
|
-
* region: [
|
|
154
|
-
* {
|
|
155
|
-
* id: 1,
|
|
156
|
-
* name: 'North America',
|
|
157
|
-
* // etc.
|
|
158
|
-
* },
|
|
159
|
-
* {
|
|
160
|
-
* id: 2,
|
|
161
|
-
* name: 'Europe',
|
|
162
|
-
* // etc.
|
|
163
|
-
* },
|
|
164
|
-
* ],
|
|
165
|
-
* },
|
|
166
|
-
* ]);
|
|
167
|
-
* ```
|
|
168
|
-
*/
|
|
169
|
-
addData,
|
|
170
|
-
/**
|
|
171
|
-
* Dump data from the current database through a `PrismaClient` instance.
|
|
172
|
-
*
|
|
173
|
-
* @see {@link PrismaDataDumpOptions}
|
|
174
|
-
*/
|
|
175
|
-
dumpData,
|
|
176
|
-
},
|
|
177
|
-
};
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// cspell:disable
|
|
2
|
-
|
|
3
|
-
import {arrayToObject, type MaybePromise} from '@augment-vir/common';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* These are all the env flags that Prisma reads for determining if it's being executed within a CI
|
|
7
|
-
* environment. This list was retrieved from
|
|
8
|
-
* https://github.com/prisma/prisma/blob/075d31287c90b757fd9bd8d9b36032e6349fa671/packages/internals/src/utils/isCi.ts.
|
|
9
|
-
*/
|
|
10
|
-
const prismaCiFlags = [
|
|
11
|
-
'CI',
|
|
12
|
-
'CONTINUOUS_INTEGRATION',
|
|
13
|
-
'BUILD_NUMBER',
|
|
14
|
-
'RUN_ID',
|
|
15
|
-
'AGOLA_GIT_REF',
|
|
16
|
-
'AC_APPCIRCLE',
|
|
17
|
-
'APPVEYOR',
|
|
18
|
-
'CODEBUILD',
|
|
19
|
-
'TF_BUILD',
|
|
20
|
-
'bamboo_planKey',
|
|
21
|
-
'BITBUCKET_COMMIT',
|
|
22
|
-
'BITRISE_IO',
|
|
23
|
-
'BUDDY_WORKSPACE_ID',
|
|
24
|
-
'BUILDKITE',
|
|
25
|
-
'CIRCLECI',
|
|
26
|
-
'CIRRUS_CI',
|
|
27
|
-
'CF_BUILD_ID',
|
|
28
|
-
'CM_BUILD_ID',
|
|
29
|
-
'CI_NAME',
|
|
30
|
-
'DRONE',
|
|
31
|
-
'DSARI',
|
|
32
|
-
'EARTHLY_CI',
|
|
33
|
-
'EAS_BUILD',
|
|
34
|
-
'GERRIT_PROJECT',
|
|
35
|
-
'GITEA_ACTIONS',
|
|
36
|
-
'GITHUB_ACTIONS',
|
|
37
|
-
'GITLAB_CI',
|
|
38
|
-
'GOCD',
|
|
39
|
-
'BUILDER_OUTPUT',
|
|
40
|
-
'HARNESS_BUILD_ID',
|
|
41
|
-
'JENKINS_URL',
|
|
42
|
-
'BUILD_ID',
|
|
43
|
-
'LAYERCI',
|
|
44
|
-
'MAGNUM',
|
|
45
|
-
'NETLIFY',
|
|
46
|
-
'NEVERCODE',
|
|
47
|
-
'PROW_JOB_ID',
|
|
48
|
-
'RELEASE_BUILD_ID',
|
|
49
|
-
'RENDER',
|
|
50
|
-
'SAILCI',
|
|
51
|
-
'HUDSON',
|
|
52
|
-
'JENKINS_URL',
|
|
53
|
-
'BUILD_ID',
|
|
54
|
-
'SCREWDRIVER',
|
|
55
|
-
'SEMAPHORE',
|
|
56
|
-
'SOURCEHUT',
|
|
57
|
-
'STRIDER',
|
|
58
|
-
'TASK_ID',
|
|
59
|
-
'RUN_ID',
|
|
60
|
-
'TEAMCITY_VERSION',
|
|
61
|
-
'TRAVIS',
|
|
62
|
-
'VELA',
|
|
63
|
-
'NOW_BUILDER',
|
|
64
|
-
'APPCENTER_BUILD_ID',
|
|
65
|
-
'CI_XCODE_PROJECT',
|
|
66
|
-
'XCS',
|
|
67
|
-
];
|
|
68
|
-
|
|
69
|
-
export function testWithNonCiEnv(callback: () => MaybePromise<void>) {
|
|
70
|
-
return async () => {
|
|
71
|
-
const usedKeys = prismaCiFlags.filter((ciFlag) => ciFlag in process.env);
|
|
72
|
-
|
|
73
|
-
/** For already non-CI environments. */
|
|
74
|
-
/* node:coverage ignore next 6 */
|
|
75
|
-
const originalEnvValues = arrayToObject(usedKeys, (key) => {
|
|
76
|
-
return {
|
|
77
|
-
key,
|
|
78
|
-
value: process.env[key],
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
usedKeys.forEach((key) => delete process.env[key]);
|
|
83
|
-
|
|
84
|
-
await callback();
|
|
85
|
-
|
|
86
|
-
usedKeys.forEach((key) => (process.env[key] = originalEnvValues[key]));
|
|
87
|
-
};
|
|
88
|
-
}
|