Fix index creation when using MySQL

This commit fixes a MySQL-related bug introduced on July 13 as part
of commit 3bcb1492aa32cc5034d71f8c473f4a3ff9fa7e3b, which added indexes.
Without this fix, indexes cannot be created for a MySQL-backed events
database, and the Gerrit error_log is spammed with errors.

The problem stems from the fact that MySQL has a slightly different
"CREATE INDEX" syntax than H2.  MySQL does not support the
"IF NOT EXISTS" modifier.  In order to create an index only if it is
not already present, you have to do some prepared-statement trickery
to generate a statement that either adds the index or does nothing.
In this case, we just select the string "Index exists."

In particular, this change adds a more granular database-detection
system to add in proper support for MySQL.  Instead of just explicit
support for Postgres or H2, this now detects Postgres, MySQL, and H2.

Without this fix, anyone using MySQL for the events database will see
the following error in the log over and over and over:

[Store events-1] INFO : Connected to database
[Store events-1] WARN : Cannot start the database. Events will be stored locally until database connection can be established
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS created_idx ON ChangeEvents (date_created);CREATE INDEX IF NOT EXI' at line 1

Change-Id: Ib8a48d55bbb9c797f58beeab47952e66cd20d62a
5 files changed