(schema: Schema)
| 407 | } |
| 408 | |
| 409 | export function getIdentifiers(schema: Schema): { |
| 410 | instanceName: string; |
| 411 | instanceId: string; |
| 412 | databaseId: string; |
| 413 | schemaName: string; |
| 414 | serviceName: string; |
| 415 | } { |
| 416 | const postgresDatasource = schema.datasources.find((d) => d.postgresql); |
| 417 | const databaseId = postgresDatasource?.postgresql?.database; |
| 418 | if (!databaseId) { |
| 419 | throw new FirebaseError( |
| 420 | "SQL Connect schema must have a postgres datasource with a database name.", |
| 421 | ); |
| 422 | } |
| 423 | const instanceName = postgresDatasource?.postgresql?.cloudSql?.instance; |
| 424 | if (!instanceName) { |
| 425 | throw new FirebaseError( |
| 426 | "SQL Connect schema must have a postgres datasource with a CloudSQL instance.", |
| 427 | ); |
| 428 | } |
| 429 | const instanceId = instanceName.split("/").pop()!; |
| 430 | const schemaName = postgresDatasource?.postgresql?.schema || DEFAULT_SCHEMA; |
| 431 | const serviceName = serviceNameFromSchema(schema); |
| 432 | return { |
| 433 | databaseId, |
| 434 | instanceId, |
| 435 | instanceName, |
| 436 | schemaName, |
| 437 | serviceName, |
| 438 | }; |
| 439 | } |
| 440 | |
| 441 | /** Extracts the service name from the schema name. */ |
| 442 | export function serviceNameFromSchema(schema: Schema): string { |
no test coverage detected
searching dependent graphs…