[go: nahoru, domu]

Skip to content

Commit

Permalink
Print message to view Firestore database in console after creation or…
Browse files Browse the repository at this point in the history
… restore (#6949)
  • Loading branch information
rwhogg committed Apr 10, 2024
1 parent c096f32 commit 45b5491
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add Firebase console link after creating or restoring a Firestore database (#6949)
3 changes: 3 additions & 0 deletions src/commands/firestore-databases-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ export const command = new Command("firestore:databases:create <database>")
"the new database. By default, created databases will have closed rules that\n" +
"block any incoming third-party traffic.",
);
logger.info(
`Your database may be viewed at ${printer.firebaseConsoleDatabaseUrl(options.project, database)}`,
);
}

return databaseResp;
Expand Down
3 changes: 3 additions & 0 deletions src/commands/firestore-databases-restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export const command = new Command("firestore:databases:restore")
"the new database. By default, created databases will have closed rules that\n" +
"block any incoming third-party traffic.",
);
logger.info(
`Once the restore is complete, your database may be viewed at ${printer.firebaseConsoleDatabaseUrl(options.project, databaseId)}`,
);
}

return databaseResp;
Expand Down
9 changes: 9 additions & 0 deletions src/firestore/pretty-print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as sort from "./api-sort";
import * as types from "./api-types";
import { logger } from "../logger";
import * as util from "./util";
import { consoleUrl } from "../utils";
import { Backup, BackupSchedule } from "../gcp/firestore";

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

/**
* Get a URL to view a given Firestore database in the Firebase console
*/
firebaseConsoleDatabaseUrl(project: string, databaseId: string): string {
const urlFriendlyDatabaseId = databaseId === "(default)" ? "-default-" : databaseId;
return consoleUrl(project, `/firestore/databases/${urlFriendlyDatabaseId}/data`);
}

/**
* Get a colored, pretty-printed representation of a field
*/
Expand Down
14 changes: 14 additions & 0 deletions src/test/firestore/pretty-print.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,17 @@ describe("prettyIndexString", () => {
).to.contain("(foo,ASCENDING) (bar,VECTOR<200>) ");
});
});

describe("firebaseConsoleDatabaseUrl", () => {
it("should provide a console link", () => {
expect(printer.firebaseConsoleDatabaseUrl("example-project", "example-db")).to.equal(
"https://console.firebase.google.com/project/example-project/firestore/databases/example-db/data",
);
});

it("should convert (default) to -default-", () => {
expect(printer.firebaseConsoleDatabaseUrl("example-project", "(default)")).to.equal(
"https://console.firebase.google.com/project/example-project/firestore/databases/-default-/data",
);
});
});

0 comments on commit 45b5491

Please sign in to comment.