Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Firestore backup/schedule and restore support #6778

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

rwhogg
Copy link
Contributor

@rwhogg rwhogg commented Feb 16, 2024

Description

Creates new commands for Firestore disaster recovery support:

  • firestore:backups:schedules:list
  • firestore:backups:schedules:create
  • firestore:backups:schedules:update
  • firestore:backups:schedules:delete
  • firestore:backups:get
  • firestore:backups:list
  • firestore:backups:delete
  • firestore:databases:restore

Scenarios Tested

firestore:backups:schedules:list

  • Successful list (no schedules)
  • Successful list (daily schedule only)
  • Successful list (weekly schedule only)
  • Successful list (both)
  • Database flag defaults to "(default)"
  • Unsuccesful list (database does not exist)

firestore:backups:schedules:create

  • Successful creation (daily alone)
  • Successful creation (weekly alone)
  • Successful creation (daily with preexisting weekly)
  • Successful creation (weekly with preexisting daily)
  • Unsuccessful creation (two dailies)
  • Unsuccessful creation (two weeklies)
  • Unsuccessful creation (database does not exist)
  • Database flag defaults to "(default)"
  • Client error (no retention specified)
  • Client error (no recurrence specified)
  • Client error (bad retention syntax)
  • Client error (recurrence other than DAILY or WEEKLY)
  • Client error (weekly retention but no day of week)
  • Client error (day of week specified for daily retention)
  • Unsuccessful creation (daily retention, >7 days)
  • Unsuccessful creation (weekly retention, >14 weeks)

firestore:backups:schedules:update

  • Successful update (daily)
  • Successful update (weekly)
  • Unsuccessful update (schedule does not exist)
  • Client error (try to update recurrence)
  • Client error (no retention specified)
  • Client error (bad retention syntax)
  • Unsuccessful update (daily retention, >7 days)
  • Unsuccessful update (weekly retention, >14 weeks)

firestore:backups:schedules:delete

  • Successful delete (daily)
  • Successful delete (weekly)
  • Unsuccessful delete (schedule does not exist)
  • Delete aborted (confirmation prompt rejected)
  • Delete allowed (confirmation prompt allowed)
  • Confirmation prompt skipped (--force)

firestore:backups:get

  • Successful get
  • Unsuccessful get (backup does not exist)
  • Client error (backup not specified)

firestore:backups:list

  • Successful list (no backups)
  • Successful list (> 0 backups)
  • Location flag defaults to "-" ("all locations")
  • Unsuccessful list (location does not exist)

firestore:backups:delete

  • Successful delete
  • Unsuccessful delete (backup does not exist)
  • Client error (backup not specified)
  • Delete aborted (confirmation prompt rejected)
  • Delete allowed (confirmation prompt allowed)
  • Confirmation prompt skipped (--force)

firestore:databases:restore

  • Successful restore initiation
  • Unsuccessful restore initiation (backup does not exist)
  • Unsuccessful restore initiation (database name is already taken)
  • Client error (backup not specified)
  • Client error (database name not specified)

Sample Commands

  • firebase firestore:backups:get projects/myproj/locations/nam5/backups/abcdefg
  • firebase firestore:backups:list –location=nam5 –project=myproj
  • firebase firestore:backups:delete projects/myproj/locations/nam5/backup/abcdefg
  • firebase firestore:backups:schedules:list --database '(default)'
  • firebase firestore:backups:schedules:create --database '(default)' --recurrence DAILY --retention 3d
  • firebase firestore:backups:schedules:create --database '(default)' --recurrence WEEKLY --day-of-week TUESDAY --retention 7d
  • firebase firestore:backups:schedules:update projects/myproj/databases/(default)/backupSchedules/hijklmnop --retention 4d
  • firebase firestore:backups:schedules:delete projects/myproj/databases/(default)/backupSchedules/hijklmnop
  • firebase firestore:databases:restore --database restore-target --backup projects/myproject/locations/nam5/backups/abcdefg

@codecov-commenter
Copy link

codecov-commenter commented Feb 16, 2024

Codecov Report

Attention: Patch coverage is 27.13568% with 145 lines in your changes are missing coverage. Please review.

Project coverage is 54.22%. Comparing base (2ef6af8) to head (33d5a60).

Files Patch % Lines
src/firestore/pretty-print.ts 7.07% 92 Missing ⚠️
src/gcp/firestore.ts 38.29% 29 Missing ⚠️
src/firestore/api.ts 15.00% 17 Missing ⚠️
src/firestore/backupUtils.ts 75.00% 2 Missing and 2 partials ⚠️
src/firestore/api-sort.ts 78.57% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6778      +/-   ##
==========================================
- Coverage   54.28%   54.22%   -0.06%     
==========================================
  Files         350      352       +2     
  Lines       24362    24485     +123     
  Branches     5042     5063      +21     
==========================================
+ Hits        13225    13278      +53     
- Misses       9930     9996      +66     
- Partials     1207     1211       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@joehan joehan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small style things and I'd love some more unit tests, but this LGTM overall.

src/commands/firestore-backups-delete.ts Show resolved Hide resolved
src/commands/firestore-backups-list.ts Outdated Show resolved Hide resolved
src/firestore/api.ts Outdated Show resolved Hide resolved
src/firestore/api.ts Outdated Show resolved Hide resolved
src/firestore/api-sort.ts Show resolved Hide resolved
@rwhogg rwhogg force-pushed the rh-firestore-backups branch 4 times, most recently from 513f0cc to 109e513 Compare February 22, 2024 17:52
@rwhogg rwhogg enabled auto-merge (squash) February 22, 2024 17:57
@rwhogg rwhogg merged commit 9b0a71d into master Feb 22, 2024
35 checks passed
@rwhogg rwhogg deleted the rh-firestore-backups branch February 22, 2024 20:37
rwhogg added a commit that referenced this pull request Feb 27, 2024
rwhogg added a commit that referenced this pull request Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants