Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
🐛 Init postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
Errorname committed Apr 21, 2020
1 parent 7d2d57c commit 52b0159
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cli/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chalk from 'chalk'

import { Command, CommandArguments } from '../../shared/types'
import { runLocalPrisma, runDistantPrisma, spawnShell } from '../../shared/shell'
import { setManagementProviderInSchema } from '../../shared/env'
import { setManagementProviderInSchema, setManagementProviderInMigration } from '../../shared/env'

class Generate implements Command {
name = 'generate'
Expand Down Expand Up @@ -47,6 +47,7 @@ class Generate implements Command {
async generateManagement(prismaArgs: string = '') {
// This is a workaround until Prisma allows for multi-provider datasources
await setManagementProviderInSchema()
await setManagementProviderInMigration()

await runLocalPrisma(`generate ${prismaArgs}`)
}
Expand Down
29 changes: 29 additions & 0 deletions src/shared/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,32 @@ export const setManagementProviderInSchema = async (): Promise<void> => {
// 4. Write content to file
return writeFile(schemaPath, content)
}

export const setManagementProviderInMigration = async (): Promise<void> => {
if (!process.env.MANAGEMENT_PROVIDER) {
throw new PmtError('missing-env', { name: 'MANAGEMENT_PROVIDER' })
}

const nodeModules = getNodeModules()

// 1. Find migration steps file
const stepsPath = path.join(
nodeModules,
'prisma-multi-tenant/build/cli/prisma/migrations/20200411135513-alpha/steps.json'
)

if (!(await fileExists(stepsPath))) {
throw new PmtError('management-migration-not-found')
}

// 2. Read content of file
const content = JSON.parse(await readFile(stepsPath))

// 3. Change provider of datasource
content.steps.find(
(step: any) => step.argument == 'provider'
).value = `\"${process.env.MANAGEMENT_PROVIDER}\"`

// 4. Write content to file
return writeFile(stepsPath, JSON.stringify(content, null, 2))
}

0 comments on commit 52b0159

Please sign in to comment.