(url: string | undefined, debug = false, comments = true)
| 112 | } |
| 113 | |
| 114 | export const defaultEnv = async (url: string | undefined, debug = false, comments = true) => { |
| 115 | if (url === undefined) { |
| 116 | // TODO: bundle the CLI to ESM instead of CommonJS and make these module-level imports |
| 117 | const [{ startPrismaDevServer }, { ServerState }] = await Promise.all([ |
| 118 | import('@prisma/dev'), |
| 119 | import('@prisma/dev/internal/state'), |
| 120 | ]) |
| 121 | |
| 122 | let created = false |
| 123 | const state = |
| 124 | (await ServerState.fromServerDump({ debug })) || |
| 125 | ((created = true), await ServerState.createExclusively({ debug, persistenceMode: 'stateful' })) |
| 126 | |
| 127 | if (created) { |
| 128 | await state.close() |
| 129 | } |
| 130 | |
| 131 | const server = await startPrismaDevServer({ |
| 132 | databasePort: state.databasePort, |
| 133 | dryRun: true, |
| 134 | name: state.name, |
| 135 | persistenceMode: 'stateful', |
| 136 | port: state.port, |
| 137 | shadowDatabasePort: state.shadowDatabasePort, |
| 138 | debug, |
| 139 | }) |
| 140 | |
| 141 | url = server.ppg.url |
| 142 | } |
| 143 | |
| 144 | let env = comments |
| 145 | ? `# Environment variables declared in this file are NOT automatically loaded by Prisma. |
| 146 | # Please add \`import "dotenv/config";\` to your \`prisma.config.ts\` file, or use the Prisma CLI with Bun |
| 147 | # to load environment variables from .env files: https://pris.ly/prisma-config-env-vars. |
| 148 | |
| 149 | # Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. |
| 150 | # See the documentation for all the connection string options: https://pris.ly/d/connection-strings |
| 151 | |
| 152 | ${ |
| 153 | url.startsWith('prisma+postgres:') && url.includes('localhost') |
| 154 | ? `# The following \`prisma+postgres\` URL is similar to the URL produced by running a local Prisma Postgres |
| 155 | # server with the \`prisma dev\` CLI command, when not choosing any non-default ports or settings. The API key, unlike the |
| 156 | # one found in a remote Prisma Postgres URL, does not contain any sensitive information.\n\n` |
| 157 | : '' |
| 158 | }` |
| 159 | : '' |
| 160 | env += `DATABASE_URL="${url}"` |
| 161 | return env |
| 162 | } |
| 163 | |
| 164 | export const defaultPort = (datasourceProvider: ConnectorType) => { |
| 165 | switch (datasourceProvider) { |
no test coverage detected