1

I am currently adding Google Firestore in my app so I can store user preferences, licenses, and other metadata. I have Google Authentication setup as well so I can track whatever the user is registered or not.

Not being a database/NoSQL expert, any design suggestions would be greatly appreciated!

I need to store the following, and probably more later on:

  • App installation / license (multiple platforms: iOS, macOS, etc.)
  • Bought in-app purchases (for being able to restore them from another platform)
  • User preferences, so they can be re-used on another platform and for backup purposes

I am thinking of this simple design:

/users (collection)
     |
     +-- {user_XXXXXX} <- what should be used here? e-mail? generated ID?
             |
             +--- app_licenses (collection)
                      |
                      + {license_XXX} <-- incremental id? auto-generated?
                      |    |
                      |    +-- platform : ios / macos / ...
                      |    +-- installation_id : device id ?
                      + {license_XXX} <--- incremental id? auto-generated?
                      |    +-- platform : ios / macos / ...
                      |    +-- installation_id : device id ?
                      |
             +--- iap_purchases (collection)
                      |
                      + {iap_XXX} <--- incremental id? auto-generated?
                           |
                           +-- name : unique identifier (title/name)
                           +-- transaction_id 
                           +-- date : purchase date
             +--- prefs
                    |
                    + fav_color : red / blue / ...
                    + another_pref : ....

Thank you!

mgmg
  • 13
  • 4
  • 1
    A good document to securely design a Firestore database is available here: https://firebase.google.com/docs/database/security/ – mgmg Apr 07 '18 at 09:47

1 Answers1

0

Your design so far looks good to me.

Regarding your root user level: Do the user's your adding information for have to be logged in through firebase? If so, I would use the user's UID from firebase. It is guaranteed to be unique and can only be retrieved after authentication. Here's a stack overflow question concerning that.

If you aren't necessarily storing users that are logged in through firebase, I would still use some kind of auto incremented id or GUID. Just make sure you avoid the possibility of duplicate id's being generated.

I would avoid using email because perhaps further down the road you might want to add multiple emails or even phone numbers as contact info.

As for the licenses and in app purchases: I'm not quite familiar with firestore, auto incrementing id's seems like only a SQL thing to me but if you have that available to you, I think that's acceptable. GUID's would also work.

  • Yes, the user needs to be logged in, so I can use the UID from Firebase as you suggest. – mgmg Apr 06 '18 at 14:49