♻️ Re-organize workspace folders
This commit is contained in:
3
packages/prisma/scripts/db-generate.ts
Normal file
3
packages/prisma/scripts/db-generate.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { executePrismaCommand } from './executeCommand'
|
||||
|
||||
executePrismaCommand('prisma generate', { force: true })
|
||||
3
packages/prisma/scripts/db-push.ts
Normal file
3
packages/prisma/scripts/db-push.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { executePrismaCommand } from './executeCommand'
|
||||
|
||||
executePrismaCommand('prisma db push --skip-generate')
|
||||
48
packages/prisma/scripts/executeCommand.ts
Normal file
48
packages/prisma/scripts/executeCommand.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { exec } from 'child_process'
|
||||
import { join } from 'path'
|
||||
|
||||
require('dotenv').config({
|
||||
override: true,
|
||||
path: join(__dirname, `../.env`),
|
||||
})
|
||||
|
||||
const postgesqlSchemaPath = join(__dirname, '../postgresql/schema.prisma')
|
||||
const mysqlSchemaPath = join(__dirname, '../mysql/schema.prisma')
|
||||
|
||||
type Options = {
|
||||
force?: boolean
|
||||
}
|
||||
|
||||
export const executePrismaCommand = (command: string, options?: Options) => {
|
||||
const databaseUrl =
|
||||
process.env.DATABASE_URL ?? (options?.force ? 'postgresql://' : undefined)
|
||||
|
||||
if (!databaseUrl) {
|
||||
console.error('Could not find DATABASE_URL in environment')
|
||||
return
|
||||
}
|
||||
|
||||
if (databaseUrl?.startsWith('mysql://')) {
|
||||
console.log('Executing for MySQL schema')
|
||||
executeCommand(`${command} --schema ${mysqlSchemaPath}`)
|
||||
}
|
||||
|
||||
if (databaseUrl?.startsWith('postgresql://')) {
|
||||
console.log('Executing for PostgreSQL schema')
|
||||
executeCommand(`${command} --schema ${postgesqlSchemaPath}`)
|
||||
}
|
||||
}
|
||||
|
||||
const executeCommand = (command: string) => {
|
||||
exec(command, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.log(error.message)
|
||||
return
|
||||
}
|
||||
if (stderr) {
|
||||
console.log(stderr)
|
||||
return
|
||||
}
|
||||
console.log(stdout)
|
||||
})
|
||||
}
|
||||
4
packages/prisma/scripts/migrate-deploy.ts
Normal file
4
packages/prisma/scripts/migrate-deploy.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { executePrismaCommand } from './executeCommand'
|
||||
|
||||
if (process.env.DATABASE_URL?.startsWith('postgresql://'))
|
||||
executePrismaCommand('prisma migrate deploy')
|
||||
4
packages/prisma/scripts/migrate-dev.ts
Normal file
4
packages/prisma/scripts/migrate-dev.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { executePrismaCommand } from './executeCommand'
|
||||
|
||||
if (process.env.DATABASE_URL?.startsWith('postgresql://'))
|
||||
executePrismaCommand('prisma migrate dev --create-only')
|
||||
3
packages/prisma/scripts/studio.ts
Normal file
3
packages/prisma/scripts/studio.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { executePrismaCommand } from './executeCommand'
|
||||
|
||||
executePrismaCommand('cross-env BROWSER=none prisma studio')
|
||||
Reference in New Issue
Block a user