forked from prisma/prisma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(config): fix issue with --config cli arg (prisma#26336)
The arg had to be "allowlisted" for each command individually.
- Loading branch information
Showing
31 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { jestConsoleContext, jestContext } from '@prisma/get-platform' | ||
|
||
const ctx = jestContext.new().add(jestConsoleContext()).assemble() | ||
|
||
function cleanSnapshot(str: string): string { | ||
str = str.replace(/\\/g, '/').replace(/"\/.*(\/config\/prisma.config.ts)"/g, '"REDACTED_ROOT$1"') | ||
str = str.replace(/\\/g, '/').replace(/"\/.*(\/prisma.config.ts)"/g, '"REDACTED_ROOT$1"') | ||
return str | ||
} | ||
|
||
const COMMANDS = [ | ||
['validate'], | ||
['migrate', 'dev'], | ||
['migrate', 'status'], | ||
['migrate', 'resolve'], | ||
['migrate', 'reset'], | ||
['migrate', 'deploy'], | ||
['migrate', 'diff'], | ||
['db', 'execute'], | ||
['db', 'pull'], | ||
['db', 'push'], | ||
['db', 'seed'], | ||
['studio'], | ||
['generate'], | ||
['version'], | ||
['validate'], | ||
['format'], | ||
['debug'], | ||
] | ||
|
||
COMMANDS.forEach((command) => { | ||
it(`test 'prisma ${command.join(' ')}' automatically detects config file`, async () => { | ||
ctx.fixture('prisma-config') | ||
|
||
// Running with --help to not run further actions beyond config loading | ||
const res = await ctx.cli(...command, '--help') | ||
expect(cleanSnapshot(res.stdout)).toContain(`Loaded Prisma config from "REDACTED_ROOT/prisma.config.ts".`) | ||
}) | ||
|
||
it(`test 'prisma ${command.join(' ')}' picks up custom --config option`, async () => { | ||
ctx.fixture('prisma-config-nested') | ||
|
||
// Running with --help to not run further actions beyond config loading | ||
const res = await ctx.cli(...command, '--config=./config/prisma.config.ts', '--help') | ||
console.log(res.stdout) | ||
expect(cleanSnapshot(res.stdout)).toContain(`Loaded Prisma config from "REDACTED_ROOT/config/prisma.config.ts".`) | ||
}) | ||
}) |
5 changes: 5 additions & 0 deletions
5
packages/cli/src/__tests__/fixtures/prisma-config-nested/config/prisma.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { defineConfig } from '@prisma/config/src' | ||
|
||
export default defineConfig({ | ||
earlyAccess: true, | ||
}) |
13 changes: 13 additions & 0 deletions
13
packages/cli/src/__tests__/fixtures/prisma-config-nested/config/schema.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "postgres" | ||
url = "postgresql://foo:[email protected]" | ||
} | ||
|
||
model User { | ||
id Int @id @default(autoincrement()) | ||
name String | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/cli/src/__tests__/fixtures/prisma-config/schema.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "postgres" | ||
url = "postgresql://foo:[email protected]" | ||
} | ||
|
||
model User { | ||
id Int @id @default(autoincrement()) | ||
name String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { jestConsoleContext, jestContext } from '@prisma/get-platform' | ||
import execa from 'execa' | ||
import path from 'path' | ||
|
||
const ctx = jestContext.new().add(jestConsoleContext()).assemble() | ||
|
||
function cleanSnapshot(str: string): string { | ||
str = str.replace(/\\/g, '/').replace(/"\/.*(\/config\/prisma.config.ts)"/g, '"REDACTED_ROOT$1"') | ||
str = str.replace(/\\/g, '/').replace(/"\/.*(\/prisma.config.ts)"/g, '"REDACTED_ROOT$1"') | ||
return str | ||
} | ||
|
||
const originalCwd = process.cwd() | ||
|
||
const migrateCli = (...input: string[]) => { | ||
return execa.node(path.join(originalCwd, '../migrate/dist/bin.js'), input, { | ||
cwd: ctx.fs.cwd(), | ||
stdio: 'pipe', | ||
all: true, | ||
}) | ||
} | ||
|
||
const COMMANDS = [ | ||
['migrate', 'dev'], | ||
['migrate', 'status'], | ||
['migrate', 'resolve'], | ||
['migrate', 'reset'], | ||
['migrate', 'deploy'], | ||
['migrate', 'diff'], | ||
['db', 'execute'], | ||
['db', 'pull'], | ||
['db', 'push'], | ||
['db', 'seed'], | ||
] | ||
|
||
COMMANDS.forEach((command) => { | ||
it(`test 'prisma ${command.join(' ')}' automatically detects config file`, async () => { | ||
ctx.fixture('prisma-config') | ||
|
||
// Running with --help to not run further actions beyond config loading | ||
const res = await migrateCli(...command, '--help') | ||
expect(cleanSnapshot(res.stdout)).toContain(`Loaded Prisma config from "REDACTED_ROOT/prisma.config.ts".`) | ||
}) | ||
|
||
it(`test 'prisma ${command.join(' ')}' picks up custom --config option`, async () => { | ||
ctx.fixture('prisma-config-nested') | ||
|
||
// Running with --help to not run further actions beyond config loading | ||
const res = await migrateCli(...command, '--config=./config/prisma.config.ts', '--help') | ||
expect(cleanSnapshot(res.stdout)).toContain(`Loaded Prisma config from "REDACTED_ROOT/config/prisma.config.ts".`) | ||
}) | ||
}) |
5 changes: 5 additions & 0 deletions
5
packages/migrate/src/__tests__/fixtures/prisma-config-nested/config/prisma.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { defineConfig } from '@prisma/config/src' | ||
|
||
export default defineConfig({ | ||
earlyAccess: true, | ||
}) |
13 changes: 13 additions & 0 deletions
13
packages/migrate/src/__tests__/fixtures/prisma-config-nested/config/schema.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "postgres" | ||
url = "postgresql://foo:[email protected]" | ||
} | ||
|
||
model User { | ||
id Int @id @default(autoincrement()) | ||
name String | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/migrate/src/__tests__/fixtures/prisma-config/prisma.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { defineConfig } from '@prisma/config/src' | ||
|
||
export default defineConfig({ | ||
earlyAccess: true, | ||
}) |
13 changes: 13 additions & 0 deletions
13
packages/migrate/src/__tests__/fixtures/prisma-config/schema.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "postgres" | ||
url = "postgresql://foo:[email protected]" | ||
} | ||
|
||
model User { | ||
id Int @id @default(autoincrement()) | ||
name String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters