Skip to content

Commit

Permalink
fix: disallow sqlite & createMany (#5389)
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Feb 1, 2021
1 parent 09c3f8f commit 88a3592
Show file tree
Hide file tree
Showing 3 changed files with 529 additions and 405 deletions.
28 changes: 28 additions & 0 deletions src/packages/sdk/src/__tests__/engineCommands.test.ts
Expand Up @@ -277,6 +277,34 @@ describe('getConfig', () => {
expect(config).toMatchSnapshot()
})

test('sqlite and createMany', async () => {
expect.assertions(1)
try {
await getConfig({
datamodel: `
datasource db {
provider = "sqlite"
url = "file:../hello.db"
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["createMany"]
}
model A {
id Int @id
name String
}`,
})
} catch (e) {
expect(stripAnsi(e.message)).toMatchInlineSnapshot(`
"Get config: Error: Database provider \\"sqlite\\" and the preview feature \\"createMany\\" can't be used at the same time.
Please either remove the \\"createMany\\" feature flag or use any other database type that Prisma supports: postgres, mysql or sqlserver."
`)
}
})

test('with generator and datasource', async () => {
const config = await getConfig({
datamodel: `
Expand Down
16 changes: 13 additions & 3 deletions src/packages/sdk/src/engineCommands.ts
Expand Up @@ -10,7 +10,7 @@ const debug = Debug('engineCommands')

const unlink = promisify(fs.unlink)

const MAX_BUFFER = 1000_000_000
const MAX_BUFFER = 1_000_000_000

export interface ConfigMetaFormat {
datasources: DataSource[]
Expand Down Expand Up @@ -242,7 +242,17 @@ export async function getConfig({
await unlink(tempDatamodelPath)
}

return JSON.parse(result.stdout)
const data: ConfigMetaFormat = JSON.parse(result.stdout)

if (
data.datasources?.[0]?.provider?.[0] === 'sqlite' &&
data.generators.some((g) => g.previewFeatures.includes('createMany'))
) {
throw new Error(`Database provider "sqlite" and the preview feature "createMany" can't be used at the same time.
Please either remove the "createMany" feature flag or use any other database type that Prisma supports: postgres, mysql or sqlserver.`)
}

return data
} catch (e) {
if (e.stderr || e.stdout) {
const error = e.stderr ? e.stderr : e.stout
Expand All @@ -269,7 +279,7 @@ export async function getConfig({
throw new Error(message)
}

throw new Error(chalk.redBright.bold('Get config ') + e)
throw new Error(chalk.redBright.bold('Get config: ') + e)
}
}

Expand Down

0 comments on commit 88a3592

Please sign in to comment.