--- alx-src/branches/alx-web-070/scripts/sql-schema/mcore-sql-schema.sh 2016/02/05 14:11:39 8500 +++ alx-src/branches/alx-web-070/scripts/sql-schema/mcore-sql-schema.sh 2016/02/05 14:34:11 8503 @@ -189,6 +189,7 @@ local column local autoincrement local primary + local current_primary table="${TABLE_DEFINITION[0]}" count="${#TABLE_DEFINITION[*]}" @@ -214,7 +215,13 @@ if [[ -n ${primary} ]] then - mysqldo "ALTER TABLE ${MCORE_SQL_DB}.${table} ADD PRIMARY KEY (${primary});" || die "adding primary key to table '${table}'" + # only run this if the primary key is not already the same column + i=( $(mysqldo 'SHOW COLUMNS FROM '${MCORE_SQL_DB}.${table}' WHERE `Key`="PRI"') ) + current_primary="${i[0]}" + if [[ ${current_primary} != ${primary} ]] + then + mysqldo "ALTER TABLE ${MCORE_SQL_DB}.${table} ADD PRIMARY KEY (${primary});" || die "adding primary key to table '${table}'" + fi fi if [[ -n ${autoincrement} ]] then @@ -292,7 +299,7 @@ if [[ ${current_sql_db_schema_version} = ${MCORE_SQL_DB_SCHEMA_VERSION} ]] then - echo "Database is already up to date" + echo "Database schema is already up to date" return 0 fi