[mythtv-commits] Ticket #9983: [PATCH] Fix upgrade from an empty database

MythTV noreply at mythtv.org
Thu Aug 11 09:15:58 UTC 2011


#9983: [PATCH] Fix upgrade from an empty database
-------------------------------------------------+-------------------------
     Reporter:  Lawrence Rust <lvr@…>            |      Owner:  danielk
         Type:  Patch - Bug Fix                  |     Status:  new
     Priority:  minor                            |  Milestone:  unknown
    Component:  MythTV - Mythtv-setup            |    Version:  Trunk Head
     Severity:  medium                           |   Keywords:  database
Ticket locked:  0                                |  upgrade
-------------------------------------------------+-------------------------
 mythtv-setup fails when starting with an empty database, failing during
 the wizard upgrade step from the intiak database schema 1226.

 2011-08-10 15:56:56.192100 C  Newest MythTV Schema Version : 1280
 2011-08-10 15:56:56.197098 N  Inserting MythTV initial database
 information.
 2011-08-10 15:56:56.197158 C  Upgrading to MythTV schema version 1226
 2011-08-10 15:56:56.197777 E  DB Error (Performing database upgrade):
 Query was: ALTER DATABASE mythmaster DEFAULT CHARACTER SET utf8;
 Error was: Driver error was [2/1192]:
 QMYSQL: Unable to execute query
 Database error was:
 Can't execute the given command because you have active locked tables or
 an active transaction

 new version: 1226
 2011-08-10 15:56:56.197802 E  Database Schema upgrade FAILED, unlocking.

 Steps to reproduce - Run this script:

 {{{
 #!/bin/sh -e
 : ${MYTHCONFDIR:="$PWD/mythconf-test"}
 : ${MYTHTVDIR:="$PWD/mythinstall"}
 export MYTHCONFDIR
 export MYTHTVDIR
 hostname="server"
 database="test"
 admin_username="root"
 admin_password="password"
 mythtv_username="mythtv"
 mythtv_password="mythtv"

 newdb() {
     local db=$1 user=$2 pass=$3
     local SECURITY_INFO="--user='$admin_username'\
       ${admin_password:+-p$admin_password}"
     mysql --host=$hostname $SECURITY_INFO <<END
 DROP DATABASE IF EXISTS ${db};
 CREATE DATABASE IF NOT EXISTS ${db};
 GRANT ALL ON ${db}.* TO ${user}@"%" IDENTIFIED BY "${pass}";
 FLUSH PRIVILEGES;
 END
 }

 echo "WARNING: About to re-initialise MythTV database $database"
 read -p "Presss [Return] to continue or {Control-C] to abort" temp
 newdb $database $mythtv_username $mythtv_password

 rm -rf "$MYTHCONFDIR"
 mkdir -p "$MYTHCONFDIR"
 cat > "$MYTHCONFDIR/mysql.txt" <<END
 DBHostName=${hostname}
 DBUserName=${mythtv_username}
 DBPassword=${mythtv_password}
 DBName=${database}
 DBType=QMYSQL3
 END

 $MYTHTVDIR/bin/mythtv-setup $@
 }}}

 There are 2 problems:

 1. MythDB::GetSetting can't read the dbschemavar during initialisation
 because HaveValidDatabase returns false.

 2. After calling DBUtil::lockSchema mysql requests fail during prepare
 with the error that LOCK TABLES wasn't called.

 This fix allows the dbschemavar to be read by MythDB::GetSetting even if
 HaveValidDatabase returns false and disables "LOCK TABLE schemalock
 WRITE;" I don't (and hope never will) have the mysql knowledge to fix the
 table locking 'properly' so this is an expedient fix.

-- 
Ticket URL: <http://code.mythtv.org/trac/ticket/9983>
MythTV <http://code.mythtv.org/trac>
MythTV Media Center


More information about the mythtv-commits mailing list