Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Disables KeepAlive timeout when debugger is attached to the functions emulator. (#6069)
Fixed an issue where `database:list` would have inaccurate results. (#6063)
80 changes: 28 additions & 52 deletions src/commands/database-instances-list.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Command } from "../command";
const Table = require("cli-table");

import { Command } from "../command";
import * as clc from "colorette";
import * as ora from "ora";

import { logger } from "../logger";
import { requirePermissions } from "../requirePermissions";
import { needProjectNumber } from "../projectUtils";
import * as firedata from "../gcp/firedata";
import { Emulators } from "../emulator/types";
import { warnEmulatorNotSupported } from "../emulator/commandUtils";
import * as experiments from "../experiments";
Expand All @@ -18,71 +17,48 @@ import {
parseDatabaseLocation,
} from "../management/database";

function logInstances(instances: DatabaseInstance[]): void {
if (instances.length === 0) {
logger.info(clc.bold("No database instances found."));
return;
}
const tableHead = ["Database Instance Name", "Location", "Type", "State"];
const table = new Table({ head: tableHead, style: { head: ["green"] } });
instances.forEach((db) => {
table.push([db.name, db.location, db.type, db.state]);
});

logger.info(table.toString());
}

function logInstancesCount(count = 0): void {
if (count === 0) {
return;
}
logger.info("");
logger.info(`${count} database instance(s) total.`);
}

export let command = new Command("database:instances:list")
export const command = new Command("database:instances:list")
.description("list realtime database instances, optionally filtered by a specified location")
.before(requirePermissions, ["firebasedatabase.instances.list"])
.option(
"-l, --location <location>",
"(optional) location for the database instance, defaults to all regions"
)
.before(warnEmulatorNotSupported, Emulators.DATABASE)
.action(async (options: any) => {
const location = parseDatabaseLocation(options.location, DatabaseLocation.ANY);
const spinner = ora(
"Preparing the list of your Firebase Realtime Database instances" +
`${location === DatabaseLocation.ANY ? "" : ` for location: ${location}`}`
).start();
let instances;

if (experiments.isEnabled("rtdbmanagement")) {
const projectId = needProjectId(options);
try {
instances = await listDatabaseInstances(projectId, location);
} catch (err: any) {
spinner.fail();
throw err;
}
spinner.succeed();
logInstances(instances);
logInstancesCount(instances.length);
return instances;
}
const projectNumber = await needProjectNumber(options);
const projectId = needProjectId(options);
let instances: DatabaseInstance[] = [];
try {
instances = await firedata.listDatabaseInstances(projectNumber);
instances = await listDatabaseInstances(projectId, location);
} catch (err: any) {
spinner.fail();
throw err;
}
spinner.succeed();
for (const instance of instances) {
logger.info(instance.instance);
if (instances.length === 0) {
logger.info(clc.bold("No database instances found."));
return;
}
// TODO: remove rtdbmanagement experiment in the next major release.
if (!experiments.isEnabled("rtdbmanagement")) {
for (const instance of instances) {
logger.info(instance.name);
}
logger.info(`Project ${options.project} has ${instances.length} database instances`);
return instances;
}
const tableHead = ["Database Instance Name", "Location", "Type", "State"];
const table = new Table({ head: tableHead, style: { head: ["green"] } });
for (const db of instances) {
table.push([db.name, db.location, db.type, db.state]);
}
logger.info(`Project ${options.project} has ${instances.length} database instances`);
logger.info(table.toString());
logger.info(`${instances.length} database instance(s) total.`);
return instances;
});

if (experiments.isEnabled("rtdbmanagement")) {
command = command.option(
"-l, --location <location>",
"(optional) location for the database instance, defaults to us-central1"
);
}
40 changes: 0 additions & 40 deletions src/gcp/firedata.ts

This file was deleted.