Skip to content

Commit febce9a

Browse files
committed
Fix two issues with Firestore database updating:
* Performing an update on a Datastore mode database could silently change it to Firestore Native * Enabling PITR (--point-in-time-recovery=ENABLED) while not specifying --disaster-recovery=ENABLED would silently disable disaster recovery, and vice-versa The former issue was due to always sending FIRESTORE_NATIVE as the database type, when we actually didn't need to send it at all. The latter issue was due to command-line option parsing that assumed not specifying an option was equivalent to sending an explicit DISABLE.
1 parent e53c50d commit febce9a

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/commands/firestore-databases-update.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ export const command = new Command("firestore:databases:update <database>")
2626
.action(async (database: string, options: FirestoreOptions) => {
2727
const api = new fsi.FirestoreApi();
2828

29-
if (!options.type && !options.deleteProtection && !options.pointInTimeRecovery) {
29+
if (!options.deleteProtection && !options.pointInTimeRecovery) {
3030
logger.error(
3131
"Missing properties to update. See firebase firestore:databases:update --help for more info."
3232
);
3333
return;
3434
}
35-
const type: types.DatabaseType = types.DatabaseType.FIRESTORE_NATIVE;
3635
if (
3736
options.deleteProtection &&
3837
options.deleteProtection !== types.DatabaseDeleteProtectionStateOption.ENABLED &&
@@ -43,10 +42,12 @@ export const command = new Command("firestore:databases:update <database>")
4342
);
4443
return;
4544
}
46-
const deleteProtectionState: types.DatabaseDeleteProtectionState =
47-
options.deleteProtection === types.DatabaseDeleteProtectionStateOption.ENABLED
48-
? types.DatabaseDeleteProtectionState.ENABLED
49-
: types.DatabaseDeleteProtectionState.DISABLED;
45+
let deleteProtectionState: types.DatabaseDeleteProtectionState | undefined;
46+
if (options.deleteProtection === types.DatabaseDeleteProtectionStateOption.ENABLED) {
47+
deleteProtectionState = types.DatabaseDeleteProtectionState.ENABLED;
48+
} else if (options.deleteProtection === types.DatabaseDeleteProtectionStateOption.DISABLED) {
49+
deleteProtectionState = types.DatabaseDeleteProtectionState.DISABLED;
50+
}
5051

5152
if (
5253
options.pointInTimeRecovery &&
@@ -58,15 +59,16 @@ export const command = new Command("firestore:databases:update <database>")
5859
);
5960
return;
6061
}
61-
const pointInTimeRecoveryEnablement: types.PointInTimeRecoveryEnablement =
62-
options.pointInTimeRecovery === types.PointInTimeRecoveryEnablementOption.ENABLED
63-
? types.PointInTimeRecoveryEnablement.ENABLED
64-
: types.PointInTimeRecoveryEnablement.DISABLED;
62+
let pointInTimeRecoveryEnablement: types.PointInTimeRecoveryEnablement | undefined;
63+
if (options.pointInTimeRecovery === types.PointInTimeRecoveryEnablementOption.ENABLED) {
64+
pointInTimeRecoveryEnablement = types.PointInTimeRecoveryEnablement.ENABLED;
65+
} else if (options.pointInTimeRecovery === types.PointInTimeRecoveryEnablementOption.DISABLED) {
66+
pointInTimeRecoveryEnablement = types.PointInTimeRecoveryEnablement.DISABLED;
67+
}
6568

6669
const databaseResp: types.DatabaseResp = await api.updateDatabase(
6770
options.project,
6871
database,
69-
type,
7072
deleteProtectionState,
7173
pointInTimeRecoveryEnablement
7274
);

src/firestore/api.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -754,20 +754,17 @@ export class FirestoreApi {
754754
* Update a named Firestore Database
755755
* @param project the Firebase project id.
756756
* @param databaseId the name of the Firestore Database
757-
* @param type FIRESTORE_NATIVE or DATASTORE_MODE
758757
* @param deleteProtectionState DELETE_PROTECTION_ENABLED or DELETE_PROTECTION_DISABLED
759758
* @param pointInTimeRecoveryEnablement POINT_IN_TIME_RECOVERY_ENABLED or POINT_IN_TIME_RECOVERY_DISABLED
760759
*/
761760
async updateDatabase(
762761
project: string,
763762
databaseId: string,
764-
type?: types.DatabaseType,
765763
deleteProtectionState?: types.DatabaseDeleteProtectionState,
766764
pointInTimeRecoveryEnablement?: types.PointInTimeRecoveryEnablement
767765
): Promise<types.DatabaseResp> {
768766
const url = `/projects/${project}/databases/${databaseId}`;
769767
const payload: types.DatabaseReq = {
770-
type,
771768
deleteProtectionState,
772769
pointInTimeRecoveryEnablement,
773770
};

0 commit comments

Comments
 (0)