Skip to content

feat: Display Firestore database edition #8926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/firestore/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ export enum PointInTimeRecoveryEnablement {
DISABLED = "POINT_IN_TIME_RECOVERY_DISABLED",
}

export enum DatabaseEdition {
DATABASE_EDITION_UNSPECIFIED = "DATABASE_EDITION_UNSPECIFIED",
STANDARD = "STANDARD",
ENTERPRISE = "ENTERPRISE",
}

export interface DatabaseReq {
locationId?: string;
type?: DatabaseType;
Expand Down Expand Up @@ -155,6 +161,7 @@ export interface DatabaseResp {
versionRetentionPeriod: string;
earliestVersionTime: string;
cmekConfig?: CmekConfig;
databaseEdition?: DatabaseEdition;
}

export interface RestoreDatabaseReq {
Expand Down
76 changes: 76 additions & 0 deletions src/firestore/pretty-print.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { expect } from "chai";
import * as sinon from "sinon";
import * as API from "./api-types";
import { PrettyPrint } from "./pretty-print";
import { logger } from "../logger";

const printer = new PrettyPrint();

Expand Down Expand Up @@ -92,3 +94,77 @@ describe("prettyStringArray", () => {
expect(printer.prettyStringArray([])).to.equal("");
});
});

describe("prettyPrintDatabase", () => {
let loggerInfoStub: sinon.SinonStub;

const BASE_DATABASE: API.DatabaseResp = {
name: "projects/my-project/databases/(default)",
uid: "uid",
createTime: "2020-01-01T00:00:00Z",
updateTime: "2020-01-01T00:00:00Z",
locationId: "us-central1",
type: API.DatabaseType.FIRESTORE_NATIVE,
concurrencyMode: "OPTIMISTIC",
appEngineIntegrationMode: "ENABLED",
keyPrefix: "prefix",
deleteProtectionState: API.DatabaseDeleteProtectionState.DISABLED,
pointInTimeRecoveryEnablement: API.PointInTimeRecoveryEnablement.DISABLED,
etag: "etag",
versionRetentionPeriod: "1h",
earliestVersionTime: "2020-01-01T00:00:00Z",
};

beforeEach(() => {
loggerInfoStub = sinon.stub(logger, "info");
});

afterEach(() => {
loggerInfoStub.restore();
});

it("should display STANDARD edition when databaseEdition is not provided", () => {
const database: API.DatabaseResp = { ...BASE_DATABASE };

printer.prettyPrintDatabase(database);

expect(loggerInfoStub.firstCall.args[0]).to.include("Edition");
expect(loggerInfoStub.firstCall.args[0]).to.include("STANDARD");
});

it("should display STANDARD edition when databaseEdition is UNSPECIFIED", () => {
const database: API.DatabaseResp = {
...BASE_DATABASE,
databaseEdition: API.DatabaseEdition.DATABASE_EDITION_UNSPECIFIED,
};

printer.prettyPrintDatabase(database);

expect(loggerInfoStub.firstCall.args[0]).to.include("Edition");
expect(loggerInfoStub.firstCall.args[0]).to.include("STANDARD");
});

it("should display ENTERPRISE edition when databaseEdition is ENTERPRISE", () => {
const database: API.DatabaseResp = {
...BASE_DATABASE,
databaseEdition: API.DatabaseEdition.ENTERPRISE,
};

printer.prettyPrintDatabase(database);

expect(loggerInfoStub.firstCall.args[0]).to.include("Edition");
expect(loggerInfoStub.firstCall.args[0]).to.include("ENTERPRISE");
});

it("should display STANDARD edition when databaseEdition is STANDARD", () => {
const database: API.DatabaseResp = {
...BASE_DATABASE,
databaseEdition: API.DatabaseEdition.STANDARD,
};

printer.prettyPrintDatabase(database);

expect(loggerInfoStub.firstCall.args[0]).to.include("Edition");
expect(loggerInfoStub.firstCall.args[0]).to.include("STANDARD");
});
});
6 changes: 6 additions & 0 deletions src/firestore/pretty-print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,17 @@
colWidths: [30, colValueWidth],
});

const edition =
!database.databaseEdition ||
database.databaseEdition === types.DatabaseEdition.DATABASE_EDITION_UNSPECIFIED
? types.DatabaseEdition.STANDARD
: database.databaseEdition;
table.push(
["Name", clc.yellow(database.name)],
["Create Time", clc.yellow(database.createTime)],
["Last Update Time", clc.yellow(database.updateTime)],
["Type", clc.yellow(database.type)],
["Edition", clc.yellow(edition)],
["Location", clc.yellow(database.locationId)],
["Delete Protection State", clc.yellow(database.deleteProtectionState)],
["Point In Time Recovery", clc.yellow(database.pointInTimeRecoveryEnablement)],
Expand Down Expand Up @@ -110,8 +116,8 @@
const table = new Table({
head: ["Backup Name", "Database Name", "Snapshot Time", "State"],
colWidths: [
Math.max(...sortedBackups.map((backup) => backup.name!.length + 5), 20),

Check warning on line 119 in src/firestore/pretty-print.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
Math.max(...sortedBackups.map((backup) => backup.database!.length + 5), 20),

Check warning on line 120 in src/firestore/pretty-print.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
30,
10,
],
Expand Down Expand Up @@ -151,13 +157,13 @@
prettyPrintBackupSchedule(backupSchedule: BackupSchedule): void {
const table = new Table({
head: ["Field", "Value"],
colWidths: [25, Math.max(50, 5 + backupSchedule.name!.length)],

Check warning on line 160 in src/firestore/pretty-print.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
});

table.push(
["Name", clc.yellow(backupSchedule.name!)],

Check warning on line 164 in src/firestore/pretty-print.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
["Create Time", clc.yellow(backupSchedule.createTime!)],

Check warning on line 165 in src/firestore/pretty-print.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
["Last Update Time", clc.yellow(backupSchedule.updateTime!)],

Check warning on line 166 in src/firestore/pretty-print.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
["Retention", clc.yellow(backupSchedule.retention)],
["Recurrence", this.prettyRecurrenceString(backupSchedule)],
);
Expand All @@ -181,10 +187,10 @@
* Print important fields of a backup to the console as an ASCII table.
* @param backup the Firestore backup.
*/
prettyPrintBackup(backup: Backup) {

Check warning on line 190 in src/firestore/pretty-print.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function
const table = new Table({
head: ["Field", "Value"],
colWidths: [25, Math.max(50, 5 + backup.name!.length, 5 + backup.database!.length)],

Check warning on line 193 in src/firestore/pretty-print.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
});

table.push(
Expand Down
Loading