Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed 2 bugs (unintended database mode changes and disabling of PITR or delete-protection) when updating Firestore databases (#6478)
24 changes: 13 additions & 11 deletions src/commands/firestore-databases-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ export const command = new Command("firestore:databases:update <database>")
.action(async (database: string, options: FirestoreOptions) => {
const api = new fsi.FirestoreApi();

if (!options.type && !options.deleteProtection && !options.pointInTimeRecovery) {
if (!options.deleteProtection && !options.pointInTimeRecovery) {
logger.error(
"Missing properties to update. See firebase firestore:databases:update --help for more info."
);
return;
}
const type: types.DatabaseType = types.DatabaseType.FIRESTORE_NATIVE;
if (
options.deleteProtection &&
options.deleteProtection !== types.DatabaseDeleteProtectionStateOption.ENABLED &&
Expand All @@ -43,10 +42,12 @@ export const command = new Command("firestore:databases:update <database>")
);
return;
}
const deleteProtectionState: types.DatabaseDeleteProtectionState =
options.deleteProtection === types.DatabaseDeleteProtectionStateOption.ENABLED
? types.DatabaseDeleteProtectionState.ENABLED
: types.DatabaseDeleteProtectionState.DISABLED;
let deleteProtectionState: types.DatabaseDeleteProtectionState | undefined;
if (options.deleteProtection === types.DatabaseDeleteProtectionStateOption.ENABLED) {
deleteProtectionState = types.DatabaseDeleteProtectionState.ENABLED;
} else if (options.deleteProtection === types.DatabaseDeleteProtectionStateOption.DISABLED) {
deleteProtectionState = types.DatabaseDeleteProtectionState.DISABLED;
}

if (
options.pointInTimeRecovery &&
Expand All @@ -58,15 +59,16 @@ export const command = new Command("firestore:databases:update <database>")
);
return;
}
const pointInTimeRecoveryEnablement: types.PointInTimeRecoveryEnablement =
options.pointInTimeRecovery === types.PointInTimeRecoveryEnablementOption.ENABLED
? types.PointInTimeRecoveryEnablement.ENABLED
: types.PointInTimeRecoveryEnablement.DISABLED;
let pointInTimeRecoveryEnablement: types.PointInTimeRecoveryEnablement | undefined;
if (options.pointInTimeRecovery === types.PointInTimeRecoveryEnablementOption.ENABLED) {
pointInTimeRecoveryEnablement = types.PointInTimeRecoveryEnablement.ENABLED;
} else if (options.pointInTimeRecovery === types.PointInTimeRecoveryEnablementOption.DISABLED) {
pointInTimeRecoveryEnablement = types.PointInTimeRecoveryEnablement.DISABLED;
}

const databaseResp: types.DatabaseResp = await api.updateDatabase(
options.project,
database,
type,
deleteProtectionState,
pointInTimeRecoveryEnablement
);
Expand Down
3 changes: 0 additions & 3 deletions src/firestore/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -754,20 +754,17 @@ export class FirestoreApi {
* Update a named Firestore Database
* @param project the Firebase project id.
* @param databaseId the name of the Firestore Database
* @param type FIRESTORE_NATIVE or DATASTORE_MODE
* @param deleteProtectionState DELETE_PROTECTION_ENABLED or DELETE_PROTECTION_DISABLED
* @param pointInTimeRecoveryEnablement POINT_IN_TIME_RECOVERY_ENABLED or POINT_IN_TIME_RECOVERY_DISABLED
*/
async updateDatabase(
project: string,
databaseId: string,
type?: types.DatabaseType,
deleteProtectionState?: types.DatabaseDeleteProtectionState,
pointInTimeRecoveryEnablement?: types.PointInTimeRecoveryEnablement
): Promise<types.DatabaseResp> {
const url = `/projects/${project}/databases/${databaseId}`;
const payload: types.DatabaseReq = {
type,
deleteProtectionState,
pointInTimeRecoveryEnablement,
};
Expand Down