Skip to content

Instantly share code, notes, and snippets.

@sfentress
Created June 23, 2017 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfentress/3f06ebcbc6f6cb6d5e765d37580169cf to your computer and use it in GitHub Desktop.
Save sfentress/3f06ebcbc6f6cb6d5e765d37580169cf to your computer and use it in GitHub Desktop.
Saving user data and authoring in Firebase
Thoughts on making state-saving to Firebase, along with authoring on firebase etc., as future-proof as possible
Issues:
1. We may want to support multiple versions of the same game concurrently. E.g. two different treatments in schools, with different authoring. Or we may want a new version of authoring, but to keep the old data. (Note: this does not refer to old versions of the software -- we assume all users always have the most recent version.)
2. We may want to change the user data in breaking ways.
For (1) we can put the version number/name of the application at the root of the tree. Nothing in one version ever needs to refer to anything in another, so it should all be contained in the same branch. Possible issue: If we have permissions based on paths, every time we release a new version of the game, we need to update the permissions. The alternative would be to put the appVersion further down the leaves, but it makes it much messier and the user may have to download much more data.
For (2) we can add a version number to the state, and create migrations in the app every time we need to bump this. If a user loads the game with old state, their state is migrated in-app before being saved back. Possible issue: State is only migrated by a user running the game. If a user stops launching the game, their data will be in an older version, which may make reports/analytics harder. Possible solution: Run migrations across DB if we need to cross that bridge.
Sample structure with appVersion at the root:
{
appVersion: {
"1": {
userState: {
[class-id]: {
[user-id]: {
stateVersion: 1,
state: { [stateObj]}
},
[user-id]: {
stateVersion: 1,
state: { [stateObj]}
},
[user-id]: {
stateVersion: 2,
state: { [newer-stateObj]}
}
}
},
authoring: {
{ [authoring] }
}
}
}
}
Sample structure with appVersion in the leaves:
{
userState: {
[class-id]: {
[user-id]: {
appVersion: {
"1": {
stateVersion: 1,
state: { [stateObj]}
}
}
},
[user-id]: {
appVersion: {
"1": {
stateVersion: 1,
state: { [stateObj]}
}
}
},
[user-id]: {
appVersion: {
"1": {
stateVersion: 2,
state: { [newer-stateObj]}
}
}
}
}
},
authoring: {
appVersion: {
"1": { [authoring] }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment