Solved: Storage Upgrade Failed: EXCEPTION: AphrontQueryException

Phabricator version:
Current up-to-date ‘origin/stable’

Observed Behavior:

  • installing new phabricator to new server,
  • Migrating old phab. datas to new server. Went through this tutorial: https://secure.phabricator.com/book/phabricator/article/configuring_backups/
  • Got the latest of libphutil, arcanist, phabricator using “git pull”.
  • Restored the local storage files, mysql databases, uploaded files.
  • Tried accessing phabricator, but stopped with a “Upgrade MySQL Schema” error logs.
  • Ran phabricator/ $ ./bin/storage upgrade
  • Has the following error. Checked the local json file, everything looks similiar to old copy.
  • Checked mysql login and password, all looks good too.

Stack Trace:

Applying patch “phabricator:20160102.badges.award.sql” to host “localhost:3306”…
[2018-03-21 19:58:27] EXCEPTION: (AphrontQueryException) #1050: Table ‘badges_award’ already exists at [/src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php:355]
arcanist(head=stable, ref.stable=7b6a9a93f4a4), phabricator(head=stable, ref.stable=f03d6d6a2a85), phutil(head=stable, ref.stable=47cfa511ca67)
#0 AphrontBaseMySQLDatabaseConnection::throwQueryCodeException(integer, string) called at [/src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php:289]
#1 AphrontBaseMySQLDatabaseConnection::throwQueryException(mysqli) called at [/src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php:185]
#2 AphrontBaseMySQLDatabaseConnection::executeRawQuery(string) called at [/src/xsprintf/queryfx.php:8]
#3 queryfx(AphrontMySQLiDatabaseConnection, string, string) called at [/src/infrastructure/storage/management/PhabricatorStorageManagementAPI.php:268]
#4 PhabricatorStorageManagementAPI::applyPatchSQL(string) called at [/src/infrastructure/storage/management/PhabricatorStorageManagementAPI.php:238]
#5 PhabricatorStorageManagementAPI::applyPatch(PhabricatorStoragePatch) called at [/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementWorkflow.php:1103]
#6 PhabricatorStorageManagementWorkflow::doUpgradeSchemata(array, NULL, boolean, boolean) called at [/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementWorkflow.php:849]
#7 PhabricatorStorageManagementWorkflow::upgradeSchemata(array, NULL, boolean, boolean) called at [/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementUpgradeWorkflow.php:78]
#8 PhabricatorStorageManagementUpgradeWorkflow::didExecute(PhutilArgumentParser) called at [/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementWorkflow.php:107]
#9 PhabricatorStorageManagementWorkflow::execute(PhutilArgumentParser) called at [/src/parser/argument/PhutilArgumentParser.php:441]
#10 PhutilArgumentParser::parseWorkflowsFull(array) called at [/src/parser/argument/PhutilArgumentParser.php:333]
#11 PhutilArgumentParser::parseWorkflows(array) called at [/scripts/sql/manage_storage.php:249]

Not sure

  1. Did you run ./bin/storage upgrade before copying the old data over? That would create tables that are not expected to exist, and cause a mismatch between the actual state and the expected state in the metadata database.
  2. When copying over data, did the metadata database copy correctly? The patch that’s failing is over 2 years old - is that a reasonable date for your old data? Look for tips about “updating really old installs” if so - it’s beyond the expected range.
  1. Yes, I started mysql. then ran the upgrade.
    1b. Should i logged into the fresh site as well before copying over the db? (I know the phab is working, when I went to the address and saw the auth box.)

  2. How do i know if my metadata is copied correctly? “Check the 'phabricator_meta_data” db?
    2a. Do you know this patch, which db is it located in? Maybe, i can delete that database from the backup i made, and try to let it run restore again?
    2b. This tips on “updating really old installs” is in phabricator? or just in a general sense on databases?

  3. I actually followed this blog procedure on upgrading
    http://runawaycoder.co.za/phabricatorDbMygration/

This is my current phabricator version. And yes, it sure does look old on the phabricator end.

phabricator 571960e712276083be4a0d2a67119c5aade02d25 (Dec 26 2015)
arcanist 3dbc1418ff07de30cbd22193efad0efd5fc2d7f2 (Dec 26 2015)
phutil 7b8d38cd2d4e85edcfebfe5bf60846afd1044e0f (Jan 2 2016)

  1. If there is no better way around, i can only think of 2 solutions.
    a. Delete all the unused database, and keep the necessary ones ?
    The reason i say this is because currently we only utilize the following Phabricator widgets:
  • Dashboards
  • Projects
  • Maniphest
  • People
    Question is , is it easy to pick and choose what to backup and not?

b. Progressively upgrade phabricator? maybe every 3 or 6 months until the current version ?

Thanks!

You should not have run the upgrades before copying the data over - you now have inconsistent state.
The best thing you can do is delete all the new database (You can use ./bin/storage drop, I think), copy the old data, and then run ./bin/storage upgrade.

Since your current install is very old, you should upgrade incrementally - every few months should work. You’ll need to read the Changelogs to make sure the repositories (arc/libphutil/phabricator) are in-sync, otherwise things will not work.

1 Like

Avivey, Alas! problem solved!

I had to remove all the databases that have been created using ( ./bin/storage destroy, and then run ./bin/storage upgrade.)

All is working as it should.

Thanks!