Skip to content

Commit db27b6f

Browse files
feat: Display Firestore database edition (#8926)
* feat: Display Firestore database edition Adds the 'Edition' to the output of the `firestore:databases:get` command. The `Database` resource in the Firestore API now includes a `databaseEdition` field. This change updates the `DatabaseResp` type to include this new field and modifies the `prettyPrintDatabase` function to display the database edition in the output table. The possible values for the edition are `STANDARD` and `ENTERPRISE`. If the edition is not specified or is `DATABASE_EDITION_UNSPECIFIED`, it will default to `STANDARD`. * feat: Display Firestore database edition Adds the 'Edition' to the output of the `firestore:databases:get` command. The `Database` resource in the Firestore API now includes a `databaseEdition` field. This change updates the `DatabaseResp` type to include this new field and modifies the `prettyPrintDatabase` function to display the database edition in the output table. The possible values for the edition are `STANDARD` and `ENTERPRISE`. If the edition is not specified or is `DATABASE_EDITION_UNSPECIFIED`, it will default to `STANDARD`. * feat: Display Firestore database edition Adds the 'Edition' to the output of the `firestore:databases:get` command. The `Database` resource in the Firestore API now includes a `databaseEdition` field. This change updates the `DatabaseResp` type to include this new field and modifies the `prettyPrintDatabase` function to display the database edition in the output table. The possible values for the edition are `STANDARD` and `ENTERPRISE`. If the edition is not specified or is `DATABASE_EDITION_UNSPECIFIED`, it will default to `STANDARD`. Also refactors the tests for `prettyPrintDatabase` to improve readability and maintainability. * feat: Display Firestore database edition Adds the 'Edition' to the output of the `firestore:databases:get` command. The `Database` resource in the Firestore API now includes a `databaseEdition` field. This change updates the `DatabaseResp` type to include this new field and modifies the `prettyPrintDatabase` function to display the database edition in the output table. The possible values for the edition are `STANDARD` and `ENTERPRISE`. If the edition is not specified or is `DATABASE_EDITION_UNSPECIFIED`, it will default to `STANDARD`. Also refactors the tests for `prettyPrintDatabase` to improve readability and maintainability and adds a test case for the `STANDARD` edition. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 535a658 commit db27b6f

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

src/firestore/api-types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ export enum PointInTimeRecoveryEnablement {
121121
DISABLED = "POINT_IN_TIME_RECOVERY_DISABLED",
122122
}
123123

124+
export enum DatabaseEdition {
125+
DATABASE_EDITION_UNSPECIFIED = "DATABASE_EDITION_UNSPECIFIED",
126+
STANDARD = "STANDARD",
127+
ENTERPRISE = "ENTERPRISE",
128+
}
129+
124130
export interface DatabaseReq {
125131
locationId?: string;
126132
type?: DatabaseType;
@@ -155,6 +161,7 @@ export interface DatabaseResp {
155161
versionRetentionPeriod: string;
156162
earliestVersionTime: string;
157163
cmekConfig?: CmekConfig;
164+
databaseEdition?: DatabaseEdition;
158165
}
159166

160167
export interface RestoreDatabaseReq {

src/firestore/pretty-print.spec.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { expect } from "chai";
2+
import * as sinon from "sinon";
23
import * as API from "./api-types";
34
import { PrettyPrint } from "./pretty-print";
5+
import { logger } from "../logger";
46

57
const printer = new PrettyPrint();
68

@@ -92,3 +94,77 @@ describe("prettyStringArray", () => {
9294
expect(printer.prettyStringArray([])).to.equal("");
9395
});
9496
});
97+
98+
describe("prettyPrintDatabase", () => {
99+
let loggerInfoStub: sinon.SinonStub;
100+
101+
const BASE_DATABASE: API.DatabaseResp = {
102+
name: "projects/my-project/databases/(default)",
103+
uid: "uid",
104+
createTime: "2020-01-01T00:00:00Z",
105+
updateTime: "2020-01-01T00:00:00Z",
106+
locationId: "us-central1",
107+
type: API.DatabaseType.FIRESTORE_NATIVE,
108+
concurrencyMode: "OPTIMISTIC",
109+
appEngineIntegrationMode: "ENABLED",
110+
keyPrefix: "prefix",
111+
deleteProtectionState: API.DatabaseDeleteProtectionState.DISABLED,
112+
pointInTimeRecoveryEnablement: API.PointInTimeRecoveryEnablement.DISABLED,
113+
etag: "etag",
114+
versionRetentionPeriod: "1h",
115+
earliestVersionTime: "2020-01-01T00:00:00Z",
116+
};
117+
118+
beforeEach(() => {
119+
loggerInfoStub = sinon.stub(logger, "info");
120+
});
121+
122+
afterEach(() => {
123+
loggerInfoStub.restore();
124+
});
125+
126+
it("should display STANDARD edition when databaseEdition is not provided", () => {
127+
const database: API.DatabaseResp = { ...BASE_DATABASE };
128+
129+
printer.prettyPrintDatabase(database);
130+
131+
expect(loggerInfoStub.firstCall.args[0]).to.include("Edition");
132+
expect(loggerInfoStub.firstCall.args[0]).to.include("STANDARD");
133+
});
134+
135+
it("should display STANDARD edition when databaseEdition is UNSPECIFIED", () => {
136+
const database: API.DatabaseResp = {
137+
...BASE_DATABASE,
138+
databaseEdition: API.DatabaseEdition.DATABASE_EDITION_UNSPECIFIED,
139+
};
140+
141+
printer.prettyPrintDatabase(database);
142+
143+
expect(loggerInfoStub.firstCall.args[0]).to.include("Edition");
144+
expect(loggerInfoStub.firstCall.args[0]).to.include("STANDARD");
145+
});
146+
147+
it("should display ENTERPRISE edition when databaseEdition is ENTERPRISE", () => {
148+
const database: API.DatabaseResp = {
149+
...BASE_DATABASE,
150+
databaseEdition: API.DatabaseEdition.ENTERPRISE,
151+
};
152+
153+
printer.prettyPrintDatabase(database);
154+
155+
expect(loggerInfoStub.firstCall.args[0]).to.include("Edition");
156+
expect(loggerInfoStub.firstCall.args[0]).to.include("ENTERPRISE");
157+
});
158+
159+
it("should display STANDARD edition when databaseEdition is STANDARD", () => {
160+
const database: API.DatabaseResp = {
161+
...BASE_DATABASE,
162+
databaseEdition: API.DatabaseEdition.STANDARD,
163+
};
164+
165+
printer.prettyPrintDatabase(database);
166+
167+
expect(loggerInfoStub.firstCall.args[0]).to.include("Edition");
168+
expect(loggerInfoStub.firstCall.args[0]).to.include("STANDARD");
169+
});
170+
});

src/firestore/pretty-print.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,17 @@ export class PrettyPrint {
5959
colWidths: [30, colValueWidth],
6060
});
6161

62+
const edition =
63+
!database.databaseEdition ||
64+
database.databaseEdition === types.DatabaseEdition.DATABASE_EDITION_UNSPECIFIED
65+
? types.DatabaseEdition.STANDARD
66+
: database.databaseEdition;
6267
table.push(
6368
["Name", clc.yellow(database.name)],
6469
["Create Time", clc.yellow(database.createTime)],
6570
["Last Update Time", clc.yellow(database.updateTime)],
6671
["Type", clc.yellow(database.type)],
72+
["Edition", clc.yellow(edition)],
6773
["Location", clc.yellow(database.locationId)],
6874
["Delete Protection State", clc.yellow(database.deleteProtectionState)],
6975
["Point In Time Recovery", clc.yellow(database.pointInTimeRecoveryEnablement)],

0 commit comments

Comments
 (0)