Adrien Wald
04/07/2022, 11:40 PMconst response = require('cfn-response')
const path = require('path')
const schema = path.join(__dirname, '..', 'prisma', 'schema.prisma')
async function applyMigration() {
const execaCommand = (await import('execa')).execaCommand
const subprocess = execaCommand(`npx prisma migrate deploy --schema=${schema}`)
subprocess.stdout.pipe(process.stdout)
subprocess.stderr.pipe(process.stderr)
await subprocess
.catch((e) => {
console.error(e)
throw new Error('Migration failed!')
})
}
async function handler(event, context) {
console.log('Received event: ', JSON.stringify(event, null, 2))
if (event.RequestType === 'Delete') return
await applyMigration()
.then(() => response.send(event, context, response.SUCCESS, 'ok'))
.catch((error) => response.send(event, context, response.ERROR, error.message))
}
exports.handler = handler
janpio
npx prisma
and get output? If not, what about just npx
?Adrien Wald
05/24/2022, 10:53 PMAdrien Wald
06/15/2022, 5:29 PMnpx
that causes this problemAdrien Wald
06/15/2022, 5:30 PMjanpio
npm run scriptname
instead - that does not use npx
under he hood.Adrien Wald
06/16/2022, 4:50 PM// @ts-check
const response = require('cfn-response')
const prismaPath = require.resolve('prisma')
async function prisma(...arguments) {
console.log(`Running \`prisma ${arguments.join(' ')}\``)
const execaCommand = (await import('execa')).execaCommand
const subprocess = execaCommand(`${prismaPath} ${arguments.join(' ')}`)
subprocess.stdout?.pipe(process.stdout)
subprocess.stderr?.pipe(process.stderr)
await subprocess
}
async function handler(event, context) {
console.log('Received event: ', JSON.stringify(event, null, 2))
if (event.RequestType === 'Delete') return
try {
await prisma('migrate', 'deploy')
response.send(event, context, response.SUCCESS, { message: 'ok' })
} catch (error) {
console.error(error)
response.send(event, context, response.FAILED, { message: error.message })
}
}
exports.handler = handler
janpio
Adrien Wald
06/17/2022, 10:37 AMjanpio
prisma generate
internally.janpio
Adrien Wald
06/17/2022, 2:59 PMjanpio