Looking for complete sample of upgradeTableDb and DBPREFIX_

Game development with Board Game Arena Studio
User avatar
MikeIsHere
Posts: 61
Joined: 30 April 2020, 22:52

Re: Looking for complete sample of upgradeTableDb and DBPREFIX_

Post by MikeIsHere » 22 June 2020, 19:27

just for giggles I tried

Code: Select all

        $sqlColumnCheck = "SHOW COLUMNS FROM player LIKE 'player_auto_go'";
        $row = self::getObjectFromDB( $sqlColumnCheck );

        if (empty($row)) {
            $sql = "ALTER TABLE DBPREFIX_player ADD player_auto_go BOOLEAN NOT NULL DEFAULT '0'";
            self::applyDbUpgradeToAllDB( $sql );
        }

        $sqlColumnCheck = "SHOW COLUMNS FROM player LIKE 'previous_score'";
        $row = self::getObjectFromDB( $sqlColumnCheck );

        if (empty($row)) {
            $sql = "ALTER TABLE DBPREFIX_player ADD previous_score int not null DEFAULT '-1'";
            self::applyDbUpgradeToAllDB( $sql );
        }
    }    
 
That did not help

User avatar
Een
Posts: 2688
Joined: 16 June 2010, 19:52

Re: Looking for complete sample of upgradeTableDb and DBPREFIX_

Post by Een » 23 June 2020, 12:57

Not really sure what's happening, I'll need to find some time to look into your project code and make some tests. The last time I checked on upgradeTableDb for other projects update it was working fine, but who knows.

User avatar
MikeIsHere
Posts: 61
Joined: 30 April 2020, 22:52

Re: Looking for complete sample of upgradeTableDb and DBPREFIX_

Post by MikeIsHere » 23 June 2020, 15:33

That's fine no urgency because this is alpha, I just needed confirmation it wasn't my programming :D

User avatar
Een
Posts: 2688
Joined: 16 June 2010, 19:52

Re: Looking for complete sample of upgradeTableDb and DBPREFIX_

Post by Een » 24 June 2020, 09:04

MikeIsHere wrote:
23 June 2020, 15:33
That's fine no urgency because this is alpha, I just needed confirmation it wasn't my programming :D
If you need to do a change again, please let me know in advance and I'll check on a test table to see what happens.

User avatar
MikeIsHere
Posts: 61
Joined: 30 April 2020, 22:52

Re: Looking for complete sample of upgradeTableDb and DBPREFIX_

Post by MikeIsHere » 29 June 2020, 21:28

I have a new version queued up but not deployed

Version 200629-2224

This version adds two new columns to the database. Here is the code I wrote

DbModel.sql

Code: Select all

ALTER TABLE `player` ADD `player_auto_cut` BOOLEAN NOT NULL DEFAULT '0';
ALTER TABLE `player` ADD `player_games_won` BOOLEAN NOT NULL DEFAULT '0';
Snippet from upgradeTableDb

Code: Select all

$sqlColumnCheck = "SHOW COLUMNS FROM player LIKE 'player_auto_cut'";
$row = self::getObjectFromDB( $sqlColumnCheck );

if ($from_version <= '2006251740' || empty($row)) {
	$sql = "ALTER TABLE DBPREFIX_player ADD player_auto_cut BOOLEAN NOT NULL DEFAULT '0'";
	self::applyDbUpgradeToAllDB( $sql );
}

$sqlColumnCheck = "SHOW COLUMNS FROM player LIKE 'player_games_won'";
$row = self::getObjectFromDB( $sqlColumnCheck );

if ($from_version <= '2006251740' || empty($row)) {
	$sql = "ALTER TABLE DBPREFIX_player ADD player_games_won BOOLEAN NOT NULL DEFAULT '0'";
	self::applyDbUpgradeToAllDB( $sql );
}
Thank you for your help

User avatar
Een
Posts: 2688
Joined: 16 June 2010, 19:52

Re: Looking for complete sample of upgradeTableDb and DBPREFIX_

Post by Een » 30 June 2020, 08:11

Actually, discussing this with another developer, we have setup a procedure to test on the studio:
http://en.doc.boardgamearena.com/Post-r ... ase_schema

This should allow you to make sure it works before deploying.

User avatar
MikeIsHere
Posts: 61
Joined: 30 April 2020, 22:52

Re: Looking for complete sample of upgradeTableDb and DBPREFIX_

Post by MikeIsHere » 30 June 2020, 18:53

Sorry but I am having problem with step 1

Ok I think I did it correctly

I looked in the commit log and found
------------------------------------------------------------------------
r53675 | bgastudio | 2020-06-25 17:40:04 +0200 (Thu, 25 Jun 2020) | 1 line

<MikeIsWorking, cribbage> Four Color Deck / Add Cut Card to Detail / Zoom for smaller devices

I put 53675 in the overwrite working copy with this revision

I started up a game (the game options and game preferences were still from the new game), but the interface and the database was from the revision above

Looking at the DB I was missing the two columns

In the global table I edited row 300 with 2006251740 (int11), saved,
reloaded the screen ctrl-f5
Refresh the DB window looked in the Player table and.... nothing new.

Did I mess something up? Is there a way I can debug the method, either using notifies or var_dump?

The new columns should be player_auto_cut, and player_games_won

Thank you

User avatar
Een
Posts: 2688
Joined: 16 June 2010, 19:52

Re: Looking for complete sample of upgradeTableDb and DBPREFIX_

Post by Een » 01 July 2020, 09:12

After launching the game with the revision "53675" and updating global 300 in the database, did you overwrite your project again with the "head" revision in order to get back the current code before refreshing? (otherwise you are still executing the code for revision 53675 when refreshing)

User avatar
MikeIsHere
Posts: 61
Joined: 30 April 2020, 22:52

Re: Looking for complete sample of upgradeTableDb and DBPREFIX_

Post by MikeIsHere » 01 July 2020, 13:42

-- never mind --
Last edited by MikeIsHere on 01 July 2020, 14:19, edited 1 time in total.

User avatar
MikeIsHere
Posts: 61
Joined: 30 April 2020, 22:52

Re: Looking for complete sample of upgradeTableDb and DBPREFIX_

Post by MikeIsHere » 01 July 2020, 14:19

So good news bad news
I was able to get the error my players where getting in the past
Sorry, an unexpected error has occurred...

Error while processing SQL request: SELECT player_id id, player_score score, previous_score, player_games_won games_won FROM player Unknown column 'player_games_won' in 'field list'

#0 /var/tournoi/release/tournoi-200622-1731-gs/www/include/APP_DbObject.inc.php(455): APP_DbObject::DbQuery('SELECT player_i...', NULL)
#1 /var/tournoi/release/games/cribbage/999999-9999/cribbage.game.php(213): APP_DbObject->getCollectionFromDB('SELECT player_i...')
#2 /var/tournoi/release/tournoi-200622-1731-gs/www/game/module/table/table.game.php(152): Cribbage->getAllDatas()
#3 /var/tournoi/release/tournoi-200622-1731-gs/www/view/common/game.view.php(417): Table->getAllTableDatas()
#4 /var/tournoi/release/tournoi-200622-1731-gs/www/view/common/game.view.php(341): game_view->post_generate(Array)
#5 /var/tournoi/release/tournoi-200622-1731-gs/www/view/common/ebg.view.php(23): game_view->generate_content(Array)
#6 /var/tournoi/release/tournoi-200622-1731-gs/www/include/webActionCore.inc.php(231): ebg_view->generate(Array)
#7 /var/tournoi/release/tournoi-200622-1731-gs/www/index.php(230): launchWebAction('cribbage', 'action_cribbage', '__default', false, false, NULL, true, false)
#8 {main}
To recap the steps
  1. Rewrite the head with revision 53675
  2. Change the global table recordId 300 to 2006251740
  3. Rewrite the head with revision 54228 (which is the one I have queued up for production)
  4. ERROR

Post Reply

Return to “Developers”