🧑💻 Improve env variables type safety and management (#718)
Closes #679
This commit is contained in:
@@ -1 +0,0 @@
|
||||
DATABASE_URL=postgresql://postgres:typebot@localhost:5432/typebot
|
||||
@@ -6,11 +6,11 @@
|
||||
"types": "./index.ts",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "tsx scripts/studio.ts",
|
||||
"db:generate": "tsx scripts/db-generate.ts",
|
||||
"db:push": "tsx scripts/db-push.ts",
|
||||
"migrate:deploy": "tsx scripts/migrate-deploy.ts",
|
||||
"migrate:dev": "prisma migrate dev --create-only --schema postgresql/schema.prisma",
|
||||
"dev": "dotenv -e ./.env -e ../../.env -- tsx scripts/studio.ts",
|
||||
"db:generate": "dotenv -e ./.env -e ../../.env -- tsx scripts/db-generate.ts",
|
||||
"db:push": "dotenv -e ./.env -e ../../.env -- tsx scripts/db-push.ts",
|
||||
"migrate:deploy": "dotenv -e ./.env -e ../../.env -- tsx scripts/migrate-deploy.ts",
|
||||
"migrate:dev": "dotenv -e ./.env -e ../../.env -- prisma migrate dev --create-only --schema postgresql/schema.prisma",
|
||||
"db:migrate": "pnpm migrate:deploy"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -18,7 +18,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "20.4.2",
|
||||
"dotenv": "16.3.1",
|
||||
"dotenv-cli": "^7.2.1",
|
||||
"prisma": "5.0.0",
|
||||
"@typebot.io/tsconfig": "workspace:*",
|
||||
"tsx": "3.12.7",
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { exec } from 'child_process'
|
||||
import { join, relative } from 'path'
|
||||
|
||||
require('dotenv').config({
|
||||
override: true,
|
||||
path: join(__dirname, `../.env`),
|
||||
})
|
||||
|
||||
const postgesqlSchemaPath = relative(
|
||||
process.cwd(),
|
||||
join(__dirname, `../postgresql/schema.prisma`)
|
||||
@@ -34,13 +29,13 @@ export const executePrismaCommand = (command: string, options?: Options) => {
|
||||
executeCommand(`${command} --schema ${mysqlSchemaPath}`)
|
||||
}
|
||||
|
||||
if (databaseUrl?.startsWith('postgresql://')) {
|
||||
if (databaseUrl?.startsWith('postgres')) {
|
||||
console.log('Executing for PostgreSQL schema')
|
||||
executeCommand(`${command} --schema ${postgesqlSchemaPath}`)
|
||||
}
|
||||
|
||||
if (process.env.DATABASE_URL?.startsWith('postgres://')) {
|
||||
console.error('PostgreSQL `DATABASE_URL` should start with postgresql://')
|
||||
console.error('PostgreSQL `DATABASE_URL` should start with postgres')
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { executePrismaCommand } from './executeCommand'
|
||||
|
||||
if (process.env.DATABASE_URL?.startsWith('postgresql://'))
|
||||
if (process.env.DATABASE_URL?.startsWith('postgres'))
|
||||
executePrismaCommand('prisma migrate deploy')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { executePrismaCommand } from './executeCommand'
|
||||
|
||||
if (process.env.DATABASE_URL?.startsWith('postgresql://'))
|
||||
if (process.env.DATABASE_URL?.startsWith('postgres'))
|
||||
executePrismaCommand('prisma migrate dev --create-only')
|
||||
|
||||
Reference in New Issue
Block a user