Opened 13 years ago

Closed 13 years ago

#1170 closed Defect (fixed)

Database upgrade should stop after first failure

Reported by: Eric Myers Owned by: davea
Priority: Minor Milestone: Undetermined
Component: Server - Setup Version: 6.12.34
Keywords: database upgrade Cc:

Description

When the database is being upgraded the process should stop if any upgrade step fails. Right now if one SQL statement fails then the others that follow are still applied, which could leave the database in a confusing state, and the file db_revision is updated even if some or all of the upgrade steps failed.

There are several ways this could be accomplished. One is to first modify the do_query() function in db_update.php to use mysql_error() to check for a previous error and exit if there was one. The function becomes:

function do_query($query) {
    if( $err = mysql_error() ) return $err;
    echo "Doing query:\n$query\n";
    $result = mysql_query($query);
    if (!$result) {
        echo "Failed:\n".mysql_error()."\n";
    } else {
        echo "Success.\n";
    }
}

This prevents further upgrade steps if one SQL query fails.

Similarly, the loop in upgrade_db.php which applies successive updates would check for any failures and exit the loop if one is found:

foreach($updates as $update) {
    list($rev, $func) = $update;
    echo "performing update $func\n";
    call_user_func($func);
    if( mysql_errno() ) {
        echo "Database update failed.\n";
        break;
    }
     file_put_contents("../../db_revision", $rev);
}

Change History (1)

comment:1 Changed 13 years ago by davea

Resolution: fixed
Status: newclosed

(In [24969]) - upgrade script:

  • prompt user for DB user/passwd if DB updates needed
  • error out immediately if any DB update fails Fixes #1169, #1170
  • create_work: check for duplicate <file_info>s in input template

NOTE: the input template syntax is pretty clunky

Note: See TracTickets for help on using tickets.