( datasource: DataSource | undefined, config: PrismaConfigWithDatasource, )
| 31 | } |
| 32 | |
| 33 | export function parseDatasourceInfo( |
| 34 | datasource: DataSource | undefined, |
| 35 | config: PrismaConfigWithDatasource, |
| 36 | ): DatasourceInfo { |
| 37 | const url = config.datasource.url |
| 38 | |
| 39 | if (!datasource) { |
| 40 | return { |
| 41 | name: undefined, |
| 42 | prettyProvider: undefined, |
| 43 | dbName: undefined, |
| 44 | dbLocation: undefined, |
| 45 | url, |
| 46 | schema: undefined, |
| 47 | schemas: undefined, |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | const prettyProvider = prettifyProvider(datasource.provider) |
| 52 | |
| 53 | // url parsing for sql server is not implemented |
| 54 | if (datasource.provider === 'sqlserver') { |
| 55 | return { |
| 56 | name: datasource.name, |
| 57 | prettyProvider, |
| 58 | dbName: undefined, |
| 59 | dbLocation: undefined, |
| 60 | url, |
| 61 | schema: undefined, |
| 62 | schemas: datasource.schemas, |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | try { |
| 67 | const credentials = uriToCredentials(url) |
| 68 | const dbLocation = getDbLocation(credentials) |
| 69 | |
| 70 | let schema: string | undefined = undefined |
| 71 | if (['postgresql', 'cockroachdb'].includes(datasource.provider)) { |
| 72 | if (credentials.schema) { |
| 73 | schema = credentials.schema |
| 74 | } else { |
| 75 | schema = 'public' |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | const datasourceInfo = { |
| 80 | name: datasource.name, |
| 81 | prettyProvider, |
| 82 | dbName: credentials.database, |
| 83 | dbLocation, |
| 84 | url, |
| 85 | schema, |
| 86 | schemas: datasource.schemas, |
| 87 | configDir: path.dirname(datasource.sourceFilePath), |
| 88 | } |
| 89 | |
| 90 | // Default to `postgres` database name for PostgreSQL |
no test coverage detected