Skip to content

Commit 4ac4bee

Browse files
fredzqmyuchenshi
andauthored
[FDC] Ask for region if app description is given (#9256)
* ask for region if app description is given * m * m * Update src/init/features/dataconnect/index.ts Co-authored-by: Yuchen Shi <[email protected]> --------- Co-authored-by: Yuchen Shi <[email protected]>
1 parent a952fb4 commit 4ac4bee

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/init/features/dataconnect/index.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ import {
4040
import { configstore } from "../../../configstore";
4141
import { trackGA4 } from "../../../track";
4242

43+
// Default GCP region for Data Connect
44+
export const FDC_DEFAULT_REGION = "us-east4";
45+
4346
const DATACONNECT_YAML_TEMPLATE = readTemplateSync("init/dataconnect/dataconnect.yaml");
4447
const CONNECTOR_YAML_TEMPLATE = readTemplateSync("init/dataconnect/connector.yaml");
4548
const SCHEMA_TEMPLATE = readTemplateSync("init/dataconnect/schema.gql");
@@ -125,6 +128,8 @@ export async function askQuestions(setup: Setup): Promise<void> {
125128
}
126129
if (hasBilling) {
127130
await promptForCloudSQL(setup, info);
131+
} else if (info.appDescription) {
132+
await promptForLocation(setup, info);
128133
}
129134
}
130135
setup.featureInfo = setup.featureInfo || {};
@@ -148,7 +153,7 @@ export async function actuate(setup: Setup, config: Config, options: any): Promi
148153
// Populate the default values of required fields.
149154
info.serviceId = info.serviceId || defaultServiceId();
150155
info.cloudSqlInstanceId = info.cloudSqlInstanceId || `${info.serviceId.toLowerCase()}-fdc`;
151-
info.locationId = info.locationId || `us-central1`;
156+
info.locationId = info.locationId || FDC_DEFAULT_REGION;
152157
info.cloudSqlDatabase = info.cloudSqlDatabase || `fdcdb`;
153158

154159
try {
@@ -435,10 +440,10 @@ function subDataconnectYamlValues(replacementValues: {
435440
}): string {
436441
const replacements: Record<string, string> = {
437442
serviceId: "__serviceId__",
443+
locationId: "__location__",
438444
cloudSqlDatabase: "__cloudSqlDatabase__",
439445
cloudSqlInstanceId: "__cloudSqlInstanceId__",
440446
connectorDirs: "__connectorDirs__",
441-
locationId: "__location__",
442447
};
443448
let replaced = DATACONNECT_YAML_TEMPLATE;
444449
for (const [k, v] of Object.entries(replacementValues)) {
@@ -614,12 +619,7 @@ async function promptForCloudSQL(setup: Setup, info: RequiredInfo): Promise<void
614619
}
615620

616621
if (info.locationId === "") {
617-
const choices = await locationChoices(setup);
618-
info.locationId = await select<string>({
619-
message: "What location would like to use?",
620-
choices,
621-
default: "us-east4",
622-
});
622+
await promptForLocation(setup, info);
623623
info.shouldProvisionCSQL = await confirm({
624624
message: `Would you like to provision your Cloud SQL instance and database now?`,
625625
default: true,
@@ -642,6 +642,17 @@ async function promptForCloudSQL(setup: Setup, info: RequiredInfo): Promise<void
642642
return;
643643
}
644644

645+
async function promptForLocation(setup: Setup, info: RequiredInfo): Promise<void> {
646+
if (info.locationId === "") {
647+
const choices = await locationChoices(setup);
648+
info.locationId = await select<string>({
649+
message: "What location should the new Cloud SQL instance be in?",
650+
choices,
651+
default: FDC_DEFAULT_REGION,
652+
});
653+
}
654+
}
655+
645656
async function locationChoices(setup: Setup) {
646657
if (setup.projectId) {
647658
const locations = await listLocations(setup.projectId);

src/mcp/tools/core/init.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
validateAppExists,
1313
} from "../../../init/features/ailogic/utils";
1414
import { getFirebaseProject } from "../../../management/projects";
15+
import { FDC_DEFAULT_REGION } from "../../../init/features/dataconnect";
1516

1617
export const init = tool(
1718
{
@@ -82,7 +83,7 @@ export const init = tool(
8283
location_id: z
8384
.string()
8485
.optional()
85-
.default("us-central1")
86+
.default(FDC_DEFAULT_REGION)
8687
.describe("The GCP region ID to set up the Firebase Data Connect service."),
8788
cloudsql_instance_id: z
8889
.string()

0 commit comments

Comments
 (0)