Skip to content
Snippets Groups Projects
Commit f1a6b43e authored by Demian Katz's avatar Demian Katz Committed by Robert Lange
Browse files

Improve MySQL 8 compatibility. (#1381)

- Resolves VUFIND-1325.
parent f6c757b2
Branches
Tags instance/fid_adlr/staging/20191028
No related merge requests found
...@@ -284,7 +284,9 @@ ...@@ -284,7 +284,9 @@
<!-- build database --> <!-- build database -->
<exec command="mysqladmin -f -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} drop ${vufinddb}" /> <exec command="mysqladmin -f -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} drop ${vufinddb}" />
<exec command="mysqladmin -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} create ${vufinddb}" checkreturn="true" /> <exec command="mysqladmin -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} create ${vufinddb}" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;GRANT SELECT,INSERT,UPDATE,DELETE ON ${vufinddb}.* TO '${vufinddbuser}'@'${mysqlhost}' IDENTIFIED BY '${vufinddbpass}' WITH GRANT OPTION&quot;" checkreturn="true" /> <exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;DROP USER '${vufinddbuser}'@'${mysqlhost}'&quot;" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;CREATE USER '${vufinddbuser}'@'${mysqlhost}' IDENTIFIED BY '${vufinddbpass}'&quot;" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;GRANT SELECT,INSERT,UPDATE,DELETE ON ${vufinddb}.* TO '${vufinddbuser}'@'${mysqlhost}' WITH GRANT OPTION&quot;" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;FLUSH PRIVILEGES&quot;" checkreturn="true" /> <exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;FLUSH PRIVILEGES&quot;" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -D ${vufinddb} &lt; ${srcdir}/module/VuFind/sql/mysql.sql" checkreturn="true" /> <exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -D ${vufinddb} &lt; ${srcdir}/module/VuFind/sql/mysql.sql" checkreturn="true" />
...@@ -352,6 +354,7 @@ ...@@ -352,6 +354,7 @@
<exec command="sudo su -c &quot;psql -c \&quot;DROP USER ${vufinddbuser};\&quot;&quot; ${pgsqlrootuser}" checkreturn="true" /> <exec command="sudo su -c &quot;psql -c \&quot;DROP USER ${vufinddbuser};\&quot;&quot; ${pgsqlrootuser}" checkreturn="true" />
</then> </then>
<else> <else>
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;DROP USER '${vufinddbuser}'@'${mysqlhost}'&quot;" />
<exec command="mysqladmin -f -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} drop ${vufinddb}" /> <exec command="mysqladmin -f -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} drop ${vufinddb}" />
</else> </else>
</if> </if>
......
...@@ -454,11 +454,13 @@ class InstallController extends AbstractBase ...@@ -454,11 +454,13 @@ class InstallController extends AbstractBase
return [$create, $escape, $cuser, $grant]; return [$create, $escape, $cuser, $grant];
} }
// Default: MySQL: // Default: MySQL:
$user = "CREATE USER '{$view->dbuser}'@'{$view->vufindhost}'"
. "IDENTIFIED BY {$escapedPass}";
$grant = "GRANT SELECT,INSERT,UPDATE,DELETE ON " $grant = "GRANT SELECT,INSERT,UPDATE,DELETE ON "
. $view->dbname . $view->dbname
. ".* TO '{$view->dbuser}'@'{$view->vufindhost}' " . ".* TO '{$view->dbuser}'@'{$view->vufindhost}' "
. "IDENTIFIED BY {$escapedPass} WITH GRANT OPTION"; . "WITH GRANT OPTION";
return [$create, $grant, 'FLUSH PRIVILEGES']; return [$create, $user, $grant, 'FLUSH PRIVILEGES'];
} }
/** /**
......
...@@ -627,6 +627,26 @@ class DbUpgrade extends AbstractPlugin ...@@ -627,6 +627,26 @@ class DbUpgrade extends AbstractPlugin
return $missing; return $missing;
} }
/**
* Normalize constraint values.
*
* @param array $constraints Constraints to normalize
*
* @return array
*/
protected function normalizeConstraints($constraints)
{
foreach (['deleteRule', 'updateRule'] as $key) {
// NO ACTION and RESTRICT are equivalent in MySQL, but different
// versions return different values. Here we normalize them to RESTRICT
// for simplicity/consistency.
if ($constraints[$key] == 'NO ACTION') {
$constraints[$key] = 'RESTRICT';
}
}
return $constraints;
}
/** /**
* Compare expected vs. actual constraint actions and return an array of SQL * Compare expected vs. actual constraint actions and return an array of SQL
* clauses required to create the modified constraints. * clauses required to create the modified constraints.
...@@ -646,7 +666,7 @@ class DbUpgrade extends AbstractPlugin ...@@ -646,7 +666,7 @@ class DbUpgrade extends AbstractPlugin
"Could not find constraint '$name' in actual constraints" "Could not find constraint '$name' in actual constraints"
); );
} }
$actualConstr = $actual[$type][$name]; $actualConstr = $this->normalizeConstraints($actual[$type][$name]);
if ($constraint['deleteRule'] !== $actualConstr['deleteRule'] if ($constraint['deleteRule'] !== $actualConstr['deleteRule']
|| $constraint['updateRule'] !== $actualConstr['updateRule'] || $constraint['updateRule'] !== $actualConstr['updateRule']
) { ) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment