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

Refactor Firestore Documents to Use Sub-collections #155

Closed
scratchclaggy opened this issue Dec 17, 2022 · 0 comments · Fixed by #165
Closed

Refactor Firestore Documents to Use Sub-collections #155

scratchclaggy opened this issue Dec 17, 2022 · 0 comments · Fixed by #165
Assignees
Labels
backend Task must have a back end issue debt Tasks to resolve technical debts and/or increase maintainability difficulty::medium Challenging tasks

Comments

@scratchclaggy
Copy link
Contributor

scratchclaggy commented Dec 17, 2022

Context

Originally the user document contained a user's visits and contacts in an array. The intent was that this would reduce document reads (and therefore costs) for the firestore. This makes enforcing security rules for visits and contacts difficult as Firestore's security rules are not designed to work with large arrays.

Proposed Solution

Use sub-collections for the user document to store visits and contacts. This allows us to design security rules and data validation for each document in the sub-collection. Note that this may several refactors throughout the application to transition from the existing system.

Alternative solutions

There are two other ways to structure the firestore:

  • Keep the current structure: this will make data validation difficult to implement, and may actually be impossible
  • Use top level collections for visits and contacts: this would reduce document reads, but would increase complexity as the documents would each need to refer to their respective user.

Additional Notes

This blocks #145

@scratchclaggy scratchclaggy added the enhancement New feature or request label Dec 17, 2022
@scratchclaggy scratchclaggy changed the title Refactor Fire Refactor Firestore Documents to Use Sub-collections Dec 17, 2022
@scratchclaggy scratchclaggy added backend Task must have a back end issue debt Tasks to resolve technical debts and/or increase maintainability difficulty::medium Challenging tasks and removed enhancement New feature or request labels Dec 17, 2022
@scratchclaggy scratchclaggy self-assigned this Dec 17, 2022
@scratchclaggy scratchclaggy linked a pull request Dec 22, 2022 that will close this issue
4 tasks
scratchclaggy added a commit that referenced this issue Dec 29, 2022
…ocuments-to-use-sub-collections

#155 refactor firestore documents to use sub collections
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Task must have a back end issue debt Tasks to resolve technical debts and/or increase maintainability difficulty::medium Challenging tasks
Projects
Development

Successfully merging a pull request may close this issue.

1 participant