Page 1 of 1

New database field to released game

Posted: 07 September 2024, 23:22
by AxeCrazy
Hi all,

I’m a game I developed and which is officially released I need to add a new database field to the players database.
But if I do so already running games will break.
Is there a way to keep running games running and let newly created games make use of the new field?

Re: New database field to released game

Posted: 08 September 2024, 10:38
by RicardoRix
I have no experience, but is it the function at the bottom of the game.php.

Code: Select all

function upgradeTableDb( $from_version )

Re: New database field to released game

Posted: 08 September 2024, 16:30
by imralav
Never tried it, but Ricardo's guess seems to be correct. You'll probably need to:
1. Recognize in this method which version of database schema is on for current game (right now, every game has old, let's say V1, schema)
2. Run database queries to move the schema to next, V2, version
3. migrating data along the process

What you need to discover is when exactly is this method run so that you know if your main data model can be migrated immediately from V1 to V2, or if you maybe need some intermediate V1.5 for backward compatibility.

Re: New database field to released game

Posted: 08 September 2024, 16:51
by vurtan
You can find the info here in documentation:
https://en.doc.boardgamearena.com/Post- ... ase_schema

I have done it in some projects and works quite well. You can test in in the BGA studio if you adjust the version in the globals table.

If you have time you can add it to the dbmodel.sql and wait some days till all the tables created will have it and then release the function afterwards.

Re: New database field to released game

Posted: 21 September 2024, 13:02
by AxeCrazy
i wanted to try this on studio but it is not that clear to me :?
i added this to the upgradeTableDB
if ($from_version <= 2408292225) {
self::trace("ALTER DATABASE " . $from_version);
$sql = "ALTER TABLE `player` ADD `huts` smallint(5) NOT NULL;";
self::applyDbUpgradeToAllDB($sql);
$sql = "ALTER TABLE `player` ADD `extra_huts` smallint(5) NOT NULL;";
self::applyDbUpgradeToAllDB($sql);
}

where 2408292225 is the currentverrsion but the new fields are not added to the database.

Does anybody have a 9working) example for this function and how i can test it? (did not find a version field in the database globals to modify?)

Re: New database field to released game

Posted: 21 September 2024, 13:35
by thoun
This is almost good, but don't forget the DBPREFIX_ like this :
if ($from_version <= 2408292225) {
self::trace("ALTER DATABASE " . $from_version);
$sql = "ALTER TABLE `DBPREFIX_player` ADD `huts` smallint(5) NOT NULL;";
self::applyDbUpgradeToAllDB($sql);
$sql = "ALTER TABLE `DBPREFIX_player` ADD `extra_huts` smallint(5) NOT NULL;";
self::applyDbUpgradeToAllDB($sql);
}

And as it will add columns to existing lines, it will break if you don't set a default value (or make it nullable). adding DEFAULT 0 should do the trick.

Re: New database field to released game

Posted: 21 September 2024, 18:17
by AxeCrazy
Did not get the dbprefix part.
If it’s that’s simple it should work.

Thanx

Re: New database field to released game

Posted: 21 September 2024, 19:08
by AxeCrazy
And is this update done before the data of the game is queried?
So I can be sure I can query the new variables in each game?

Re: New database field to released game

Posted: 21 September 2024, 19:40
by thoun
Yes!
(If it wasn't, it would be almost useless :D )

Re: New database field to released game

Posted: 21 September 2024, 20:18
by AxeCrazy
You got a point there 😁
Thanx