Skip to content

Commit 0b5fd85

Browse files
authored
Switch to cascading deletes (#8266)
* Switch to cascading deletes * Fix test and add changelog * formats
1 parent 8eacf67 commit 0b5fd85

File tree

6 files changed

+25
-129
lines changed

6 files changed

+25
-129
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- Added initial delay when loading python functions (#8239)
33
- Enforced webframeworks enablement only on webframeworks sites (#8168)
44
- Fixed issue where `apps:init` throws an error upon app creation.
5+
- Reenabled prompts for unused service deletion in `deploy --only`.
56
- Update Firebase Data Connect local toolkit to v1.8.3, which includes the following changes: (#8263)
67
- Adds a `_metadata.distance` field to vector similarity search results
78
- Fixes `auth` and `request.auth` when the request is unauthenticated

scripts/dataconnect-test/tests.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ function expected(
3232
}
3333

3434
async function cleanUpService(projectId: string, serviceId: string, databaseId: string) {
35-
await client.deleteServiceAndChildResources(
36-
`projects/${projectId}/locations/us-central1/services/${serviceId}`,
37-
);
35+
await client.deleteService(`projects/${projectId}/locations/us-central1/services/${serviceId}`);
3836
await deleteDatabase(projectId, "dataconnect-test", databaseId);
3937
}
4038

src/dataconnect/client.spec.ts

Lines changed: 0 additions & 87 deletions
This file was deleted.

src/dataconnect/client.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ export async function createService(
6161
return pollRes;
6262
}
6363

64-
async function deleteService(serviceName: string): Promise<types.Service> {
65-
// NOTE(fredzqm): Don't force delete yet. Backend would leave orphaned resources.
66-
const op = await dataconnectClient().delete<types.Service>(serviceName);
64+
export async function deleteService(serviceName: string): Promise<types.Service> {
65+
// Note that we need to force delete in order to delete child resources too.
66+
const op = await dataconnectClient().delete<types.Service>(serviceName, {
67+
queryParams: { force: "true" },
68+
});
6769
const pollRes = await operationPoller.pollOperation<types.Service>({
6870
apiOrigin: dataconnectOrigin(),
6971
apiVersion: DATACONNECT_API_VERSION,
@@ -72,19 +74,6 @@ async function deleteService(serviceName: string): Promise<types.Service> {
7274
return pollRes;
7375
}
7476

75-
export async function deleteServiceAndChildResources(serviceName: string): Promise<void> {
76-
const connectors = await listConnectors(serviceName);
77-
await Promise.all(connectors.map(async (c) => deleteConnector(c.name)));
78-
try {
79-
await deleteSchema(serviceName);
80-
} catch (err: any) {
81-
if (err.status !== 404) {
82-
throw err;
83-
}
84-
}
85-
await deleteService(serviceName);
86-
}
87-
8877
/** Schema methods */
8978

9079
export async function getSchema(serviceName: string): Promise<types.Schema | undefined> {

src/dataconnect/schemaMigration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ async function promptForInvalidConnectorError(
487487
!options.nonInteractive &&
488488
(await confirm({
489489
...options,
490-
message: `Would you like to delete and recreate these connectors? This will cause ${clc.red(`downtime.`)}.`,
490+
message: `Would you like to delete and recreate these connectors? This will cause ${clc.red(`downtime`)}.`,
491491
}))
492492
) {
493493
return true;

src/deploy/dataconnect/deploy.ts

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ResourceFilter } from "../../dataconnect/filters";
99
import { vertexAIOrigin } from "../../api";
1010
import * as ensureApiEnabled from "../../ensureApiEnabled";
1111
import { join } from "node:path";
12+
import { confirm } from "../../prompt";
1213

1314
/**
1415
* Checks for and creates a Firebase DataConnect service, if needed.
@@ -56,28 +57,22 @@ export default async function (
5657
);
5758

5859
if (servicesToDelete.length) {
59-
const warning = `The following services exist on ${projectId} but are not listed in your 'firebase.json'\n${servicesToDelete
60-
.map((s) => s.name)
61-
.join("\n")}\nConsider deleting these via the Firebase console if they are no longer needed.`;
62-
utils.logLabeledWarning("dataconnect", warning);
63-
// TODO: Switch this back to prompting for deletion.
64-
// if (
65-
// await confirm({
66-
// force: options.force,
67-
// nonInteractive: options.nonInteractive,
68-
// message: `The following services exist on ${projectId} but are not listed in your 'firebase.json'\n${servicesToDelete
69-
// .map((s) => s.name)
70-
// .join("\n")}\nWould you like to delete these services?`,
71-
// })
72-
// ) {
73-
// await Promise.all(
74-
// servicesToDelete.map(async (s) => {
75-
// const { projectId, locationId, serviceId } = splitName(s.name);
76-
// await client.deleteService(projectId, locationId, serviceId);
77-
// utils.logLabeledSuccess("dataconnect", `Deleted service ${s.name}`);
78-
// }),
79-
// );
80-
// }
60+
if (
61+
await confirm({
62+
force: options.force,
63+
nonInteractive: options.nonInteractive,
64+
message: `The following services exist on ${projectId} but are not listed in your 'firebase.json'\n${servicesToDelete
65+
.map((s) => s.name)
66+
.join("\n")}\nWould you like to delete these services?`,
67+
})
68+
) {
69+
await Promise.all(
70+
servicesToDelete.map(async (s) => {
71+
await client.deleteService(s.name);
72+
utils.logLabeledSuccess("dataconnect", `Deleted service ${s.name}`);
73+
}),
74+
);
75+
}
8176
}
8277

8378
// Provision CloudSQL resources

0 commit comments

Comments
 (0)