Forum BigDB How to Update Your "Schema"

Discussion and help relating to the PlayerIO database solution, BigDB.

How to Update Your "Schema"

Postby JimLion » October 7th, 2014, 9:54 pm

I know it is said that BigDb is a NoSQL database an so is "schema-less", but for my game there is a standard way for structured each players PlayerObject so that it is standardized and can be read by the code. So suppose we have a simple PlayerObject structure with the player's name as the key. Then inside there is an object called "stats" with one integer, "wins".

Now suppose we release the game and people are playing it, registering accounts, etc. In the register method we create all the player's PlayerObjects as described above. However, now the CEO (or whoever) comes along and says we need a new parameter in the stats object, "losses". It's simple to change the register method so that all new users have their PlayerObject like this, but what about all the users that have already been created?

So that is my question. How do you update all of the users at once? Something like, "select all users and add this integer property in the stats object"?
JimLion
 
Posts: 73
Joined: June 17th, 2014, 3:35 am

Re: How to Update Your "Schema"

Postby Chacaros » October 9th, 2014, 8:52 pm

Well basically you wouldn't need to update a value if you never use it anywhere, so you should add it the first time it is needed. You could for example create a function that adds this field the first time a DBObj is loaded which is not already containing it.

If you however really want to update all DBObjects in a table this would require you to chain addTimer or schedulleCallback calls and iterate over the table using an index. This would involve sending all of the tables contents over the internet to the server running this room and could take some time. You would also need to somehow "lock" such a table during the update, otherwise your data might get inconsistent.
Chacaros
 
Posts: 13
Joined: September 5th, 2014, 5:47 pm

Re: How to Update Your "Schema"

Postby AquamentosGames » October 10th, 2014, 8:00 pm

I agree with what Chacaros said. Every time I pull a variable from an object I check for null and if it's null (doesn't exist) then I have a default value to use (For something like losses the default would be 0).

I typically don't re-save an object just to give it the default value, though if you needed it for some kind of lookup then you would. Players who haven't logged in since the update would have no losses value (which would default do 0 if queried by code if you coded it to check) until they have logged in once (unless you do what Chacaros says and iterate through the entire database - be wary that there is a maximum run time for scripts so you may have to break this up into multiple passes depending on how many objects you need to update.)
AquamentosGames
 
Posts: 27
Joined: December 9th, 2011, 12:44 am

Re: How to Update Your "Schema"

Postby JimLion » October 10th, 2014, 10:25 pm

Cool. Thanks guys. This is a huge hassle in relational databases so it's good to know I don't have too much to worry about here.
JimLion
 
Posts: 73
Joined: June 17th, 2014, 3:35 am

Re: How to Update Your "Schema"

Postby Henrik » October 13th, 2014, 5:32 am

There's the Contains method that tells you if a property exists on an object:

https://gamesnet.yahoo.net/documentatio ... t#Contains

And all the Get methods take an (optional) default, so that you don't have to store default values:

https://gamesnet.yahoo.net/documentatio ... ect#GetInt
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm


Return to BigDB



cron