(project: string)
| 59 | } |
| 60 | |
| 61 | async function createDefaultDatabaseInstance(project: string): Promise<DatabaseInstance> { |
| 62 | const selectedLocation = await select<DatabaseLocation>({ |
| 63 | message: "Please choose the location for your default Realtime Database instance:", |
| 64 | choices: [ |
| 65 | { name: "us-central1", value: DatabaseLocation.US_CENTRAL1 }, |
| 66 | { name: "europe-west1", value: DatabaseLocation.EUROPE_WEST1 }, |
| 67 | { name: "asia-southeast1", value: DatabaseLocation.ASIA_SOUTHEAST1 }, |
| 68 | ], |
| 69 | }); |
| 70 | let instanceName = `${project}-default-rtdb`; |
| 71 | // check if the conventional default instance name is available. |
| 72 | const checkOutput = await checkInstanceNameAvailable( |
| 73 | project, |
| 74 | instanceName, |
| 75 | DatabaseInstanceType.DEFAULT_DATABASE, |
| 76 | selectedLocation, |
| 77 | ); |
| 78 | // if the conventional instance name is not available, pick the first suggestion. |
| 79 | if (!checkOutput.available) { |
| 80 | if (!checkOutput.suggestedIds || checkOutput.suggestedIds.length === 0) { |
| 81 | logger.debug( |
| 82 | `No instance names were suggested instead of conventional instance name: ${instanceName}`, |
| 83 | ); |
| 84 | throw new FirebaseError("Failed to create default RTDB instance"); |
| 85 | } |
| 86 | instanceName = checkOutput.suggestedIds[0]; |
| 87 | logger.info( |
| 88 | `${clc.yellow( |
| 89 | "WARNING:", |
| 90 | )} your project ID has the legacy name format, so your default Realtime Database instance will be named differently: ${instanceName}`, |
| 91 | ); |
| 92 | } |
| 93 | const spinner = ora(`Creating your default Realtime Database instance: ${instanceName}`).start(); |
| 94 | try { |
| 95 | const createdInstance = await createInstance( |
| 96 | project, |
| 97 | instanceName, |
| 98 | selectedLocation, |
| 99 | DatabaseInstanceType.DEFAULT_DATABASE, |
| 100 | ); |
| 101 | spinner.succeed(); |
| 102 | return createdInstance; |
| 103 | } catch (err: any) { |
| 104 | spinner.fail(); |
| 105 | throw err; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | async function initializeDatabaseInstance(projectId: string): Promise<DatabaseInstance | null> { |
| 110 | await ensure(projectId, rtdbManagementOrigin(), "database", false); |
no test coverage detected
searching dependent graphs…