#Making prisma use different file than .env

5 messages · Page 1 of 1 (latest)

coarse ledge
#

Im having all my credentials including database url's and such in typescript file in my project, would it be possible for prisma to somehow use that? because i have in it production and dev variable which changes which database is used.

manic sage
#

Hey 👋

You could try doing something like this:

If your config looks like this:

// config.ts
export const databaseConfig = {
  development: 'postgresql://localhost/dev_db',
  production: 'postgresql://localhost/prod_db',
};

You could initialise PrismaClient dynamically like this:

import { PrismaClient } from '@prisma/client';
import { databaseConfig } from './config';

const isProd = true ;// or false;
const connectionString = isProd ? databaseConfig.production : databaseConfig.development;

const prisma = new PrismaClient({
  datasources: {
    db: {
      url: connectionString,
    },
  },
});

export default prisma;
coarse ledge
manic sage
#

Hmm, for prisma migrate it could be an issue 🤔