Skip to content

Commit eab7913

Browse files
authored
Make firebase:database:list to always use the RTDB management API (#6063)
* remove rtdbmanagement experiment * rm firedata api * m * avoid breaking changes * m * doc * Update database-instances-list.ts * Update CHANGELOG.md
1 parent 7a9d6f2 commit eab7913

File tree

3 files changed

+29
-92
lines changed

3 files changed

+29
-92
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
Disables KeepAlive timeout when debugger is attached to the functions emulator. (#6069)
2+
Fixed an issue where `database:list` would have inaccurate results. (#6063)
Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { Command } from "../command";
21
const Table = require("cli-table");
2+
3+
import { Command } from "../command";
34
import * as clc from "colorette";
45
import * as ora from "ora";
56

67
import { logger } from "../logger";
78
import { requirePermissions } from "../requirePermissions";
8-
import { needProjectNumber } from "../projectUtils";
9-
import * as firedata from "../gcp/firedata";
109
import { Emulators } from "../emulator/types";
1110
import { warnEmulatorNotSupported } from "../emulator/commandUtils";
1211
import * as experiments from "../experiments";
@@ -18,71 +17,48 @@ import {
1817
parseDatabaseLocation,
1918
} from "../management/database";
2019

21-
function logInstances(instances: DatabaseInstance[]): void {
22-
if (instances.length === 0) {
23-
logger.info(clc.bold("No database instances found."));
24-
return;
25-
}
26-
const tableHead = ["Database Instance Name", "Location", "Type", "State"];
27-
const table = new Table({ head: tableHead, style: { head: ["green"] } });
28-
instances.forEach((db) => {
29-
table.push([db.name, db.location, db.type, db.state]);
30-
});
31-
32-
logger.info(table.toString());
33-
}
34-
35-
function logInstancesCount(count = 0): void {
36-
if (count === 0) {
37-
return;
38-
}
39-
logger.info("");
40-
logger.info(`${count} database instance(s) total.`);
41-
}
42-
43-
export let command = new Command("database:instances:list")
20+
export const command = new Command("database:instances:list")
4421
.description("list realtime database instances, optionally filtered by a specified location")
4522
.before(requirePermissions, ["firebasedatabase.instances.list"])
23+
.option(
24+
"-l, --location <location>",
25+
"(optional) location for the database instance, defaults to all regions"
26+
)
4627
.before(warnEmulatorNotSupported, Emulators.DATABASE)
4728
.action(async (options: any) => {
4829
const location = parseDatabaseLocation(options.location, DatabaseLocation.ANY);
4930
const spinner = ora(
5031
"Preparing the list of your Firebase Realtime Database instances" +
5132
`${location === DatabaseLocation.ANY ? "" : ` for location: ${location}`}`
5233
).start();
53-
let instances;
5434

55-
if (experiments.isEnabled("rtdbmanagement")) {
56-
const projectId = needProjectId(options);
57-
try {
58-
instances = await listDatabaseInstances(projectId, location);
59-
} catch (err: any) {
60-
spinner.fail();
61-
throw err;
62-
}
63-
spinner.succeed();
64-
logInstances(instances);
65-
logInstancesCount(instances.length);
66-
return instances;
67-
}
68-
const projectNumber = await needProjectNumber(options);
35+
const projectId = needProjectId(options);
36+
let instances: DatabaseInstance[] = [];
6937
try {
70-
instances = await firedata.listDatabaseInstances(projectNumber);
38+
instances = await listDatabaseInstances(projectId, location);
7139
} catch (err: any) {
7240
spinner.fail();
7341
throw err;
7442
}
7543
spinner.succeed();
76-
for (const instance of instances) {
77-
logger.info(instance.instance);
44+
if (instances.length === 0) {
45+
logger.info(clc.bold("No database instances found."));
46+
return;
47+
}
48+
// TODO: remove rtdbmanagement experiment in the next major release.
49+
if (!experiments.isEnabled("rtdbmanagement")) {
50+
for (const instance of instances) {
51+
logger.info(instance.name);
52+
}
53+
logger.info(`Project ${options.project} has ${instances.length} database instances`);
54+
return instances;
55+
}
56+
const tableHead = ["Database Instance Name", "Location", "Type", "State"];
57+
const table = new Table({ head: tableHead, style: { head: ["green"] } });
58+
for (const db of instances) {
59+
table.push([db.name, db.location, db.type, db.state]);
7860
}
79-
logger.info(`Project ${options.project} has ${instances.length} database instances`);
61+
logger.info(table.toString());
62+
logger.info(`${instances.length} database instance(s) total.`);
8063
return instances;
8164
});
82-
83-
if (experiments.isEnabled("rtdbmanagement")) {
84-
command = command.option(
85-
"-l, --location <location>",
86-
"(optional) location for the database instance, defaults to us-central1"
87-
);
88-
}

src/gcp/firedata.ts

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

0 commit comments

Comments
 (0)