Skip to content

Commit d59b78b

Browse files
authored
Stop using AppEngine to check database mode (#5261)
* Stop using AppEngine to check database mode * fixing tests * Removing unnecessary check for cloud resource location * remove outdated test * add changelog
1 parent 06b8bad commit d59b78b

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
- Refactor Functions Emulator. (#5422)
2-
- Fix race condition when discovering functions. (#5444)
1+
- Refactors Functions Emulator. (#5422)
2+
- Fixes race condition when discovering functions. (#5444)
3+
- Fixes issue where `init firestore` was unecessarilly checking for default resource location. (#5230 and #5452)

src/firestore/checkDatabaseType.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
import { appengineOrigin } from "../api";
1+
import { firestoreOrigin } from "../api";
22
import { Client } from "../apiv2";
33
import { logger } from "../logger";
44

55
/**
66
* Determine the Firestore database type for a given project. One of:
77
* - DATABASE_TYPE_UNSPECIFIED (unspecified)
8-
* - CLOUD_DATASTORE (Datastore legacy)
9-
* - CLOUD_FIRESTORE (Firestore native mode)
10-
* - CLOUD_DATASTORE_COMPATIBILITY (Firestore datastore mode)
8+
* - DATASTORE_MODE(Datastore legacy)
9+
* - FIRESTORE_NATIVE (Firestore native mode)
1110
*
1211
* @param projectId the Firebase project ID.
1312
*/
14-
export async function checkDatabaseType(projectId: string): Promise<string | undefined> {
13+
export async function checkDatabaseType(
14+
projectId: string
15+
): Promise<"DATASTORE_MODE" | "FIRESTORE_NATIVE" | "DATABASE_TYPE_UNSPECIFIED" | undefined> {
1516
try {
16-
const client = new Client({ urlPrefix: appengineOrigin, apiVersion: "v1" });
17-
const resp = await client.get<{ databaseType?: string }>(`/apps/${projectId}`);
18-
return resp.body.databaseType;
17+
const client = new Client({ urlPrefix: firestoreOrigin, apiVersion: "v1" });
18+
const resp = await client.get<{
19+
type?: "DATASTORE_MODE" | "FIRESTORE_NATIVE" | "DATABASE_TYPE_UNSPECIFIED";
20+
}>(`/projects/${projectId}/databases/(default)`);
21+
return resp.body.type;
1922
} catch (err: any) {
2023
logger.debug("error getting database type", err);
2124
return undefined;

src/init/features/firestore/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { logger } from "../../../logger";
22
import * as apiEnabled from "../../../ensureApiEnabled";
3-
import { ensureLocationSet } from "../../../ensureCloudResourceLocation";
43
import { requirePermissions } from "../../../requirePermissions";
54
import { checkDatabaseType } from "../../../firestore/checkDatabaseType";
65
import * as rules from "./rules";
@@ -36,14 +35,13 @@ async function checkProjectSetup(setup: any, config: any, options: any) {
3635

3736
if (!dbType) {
3837
throw firestoreUnusedError;
39-
} else if (dbType !== "CLOUD_FIRESTORE") {
38+
} else if (dbType !== "FIRESTORE_NATIVE") {
4039
throw new FirebaseError(
4140
`It looks like this project is using Cloud Datastore or Cloud Firestore in Datastore mode. The Firebase CLI can only manage projects using Cloud Firestore in Native mode. For more information, visit https://cloud.google.com/datastore/docs/firestore-or-datastore`,
4241
{ exit: 1 }
4342
);
4443
}
4544

46-
ensureLocationSet(setup.projectLocation, "Cloud Firestore");
4745
await requirePermissions({ ...options, project: setup.projectId });
4846
}
4947

src/test/init/features/firestore.spec.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("firestore", () => {
2121

2222
// By default, mock Firestore enabled in Native mode
2323
checkApiStub.returns(true);
24-
checkDbTypeStub.returns("CLOUD_FIRESTORE");
24+
checkDbTypeStub.returns("FIRESTORE_NATIVE");
2525
});
2626

2727
afterEach(() => {
@@ -46,15 +46,6 @@ describe("firestore", () => {
4646
expect(_.get(setup, "config.firestore")).to.deep.equal({});
4747
});
4848

49-
it("should error when cloud resource location is not set", async () => {
50-
const setup = { config: {}, projectId: "my-project-123" };
51-
52-
await expect(firestore.doSetup(setup, {}, {})).to.eventually.be.rejectedWith(
53-
FirebaseError,
54-
"Cloud resource location is not set"
55-
);
56-
});
57-
5849
it("should error when the firestore API is not enabled", async () => {
5950
checkApiStub.returns(false);
6051

0 commit comments

Comments
 (0)