8000 Print message to view Firestore database in console after creation or… · firebase/firebase-tools@16fe79d · GitHub
[go: up one dir, main page]

Skip to content

Commit 16fe79d

Browse files
committed
Print message to view Firestore database in console after creation or restore
1 parent c096f32 commit 16fe79d

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add Firebase console link after creating or restoring a Firestore database (#6949)

src/commands/firestore-databases-create.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ export const command = new Command("firestore:databases:create <database>")
8585
"the new database. By default, created databases will have closed rules that\n" +
8686
"block any incoming third-party traffic.",
8787
);
88+
logger.info(
89+
`Your database may be viewed at ${printer.firebaseConsoleDatabaseUrl(options.project, database)}`,
90+
);
8891
}
8992

9093
return databaseResp;

src/commands/firestore-databases-restore.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ export const command = new Command("firestore:databases:restore")
5353
"the new database. By default, created databases will have closed rules that\n" +
5454
"block any incoming third-party traffic.",
5555
);
56+
logger.info(
57+
`Once the restore is complete, your database may be viewed at ${printer.firebaseConsoleDatabaseUrl(options.project, databaseId)}`,
58+
);
5659
}
5760

5861
return databaseResp;

src/firestore/pretty-print.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as sort from "./api-sort";
55
import * as types from "./api-types";
66
import { logger } from "../logger";
77
import * as util from "./util";
8+
import { consoleUrl } from "../utils";
89
import { Backup, BackupSchedule } from "../gcp/firestore";
910

1011
export class PrettyPrint {
@@ -274,6 +275,14 @@ export class PrettyPrint {
274275
return clc.yellow(typeof database === "string" ? database : database.name);
275276
}
276277

278+
/**
279+
* Get a URL to view a given Firestore database in the Firebase console
280+
*/
281+
firebaseConsoleDatabaseUrl(project: string, databaseId: string): string {
282+
const urlFriendlyDatabaseId = databaseId === "(default)" ? "-default-" : databaseId;
283+
return consoleUrl(project, `/firestore/databases/${urlFriendlyDatabaseId}/data`);
284+
}
285+
277286
/**
278287
* Get a colored, pretty-printed representation of a field
279288
*/

src/test/firestore/pretty-print.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,17 @@ describe("prettyIndexString", () => {
6666
).to.contain("(foo,ASCENDING) (bar,VECTOR<200>) ");
6767
});
6868
});
69+
70+
describe("firebaseConsoleDatabaseUrl", () => {
71+
it("should provide a console link", () => {
72+
expect(printer.firebaseConsoleDatabaseUrl("example-project", "example-db")).to.equal(
73+
"https://console.firebase.google.com/project/example-project/firestore/databases/example-db/data",
74+
);
75+
});
76+
77+
it("should convert (default) to -default-", () => {
78+
expect(printer.firebaseConsoleDatabaseUrl("example-project", "(default)")).to.equal(
79+
"https://console.firebase.google.com/project/example-project/firestore/databases/-default-/data",
80+
);
81+
});
82+
});

0 commit comments

Comments
 (0)
0