New database field to released game

Game development with Board Game Arena Studio
Post Reply
User avatar
AxeCrazy
Posts: 90
Joined: 15 March 2014, 01:07

New database field to released game

Post 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?
User avatar
RicardoRix
Posts: 2548
Joined: 29 April 2012, 23:43

Re: New database field to released game

Post 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 )
imralav
Posts: 44
Joined: 02 February 2024, 08:56

Re: New database field to released game

Post 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.
User avatar
vurtan
Posts: 57
Joined: 13 June 2020, 19:54

Re: New database field to released game

Post 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.
User avatar
AxeCrazy
Posts: 90
Joined: 15 March 2014, 01:07

Re: New database field to released game

Post 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?)
User avatar
thoun
Posts: 1620
Joined: 10 December 2020, 22:25

Re: New database field to released game

Post 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.
User avatar
AxeCrazy
Posts: 90
Joined: 15 March 2014, 01:07

Re: New database field to released game

Post by AxeCrazy »

Did not get the dbprefix part.
If it’s that’s simple it should work.

Thanx
User avatar
AxeCrazy
Posts: 90
Joined: 15 March 2014, 01:07

Re: New database field to released game

Post 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?
User avatar
thoun
Posts: 1620
Joined: 10 December 2020, 22:25

Re: New database field to released game

Post by thoun »

Yes!
(If it wasn't, it would be almost useless :D )
User avatar
AxeCrazy
Posts: 90
Joined: 15 March 2014, 01:07

Re: New database field to released game

Post by AxeCrazy »

You got a point there 😁
Thanx
Post Reply

Return to “Developers”