Skip to content

Conversation

albe
Copy link
Contributor

@albe albe commented Feb 25, 2020

There is no CREATE INDEX IF NOT EXISTS in MySql, so we need to try/catch to make the operation optional.
See https://dba.stackexchange.com/questions/24531/mysql-create-index-if-not-exists
Fixes #12

@albe albe added the bug label Feb 25, 2020
Copy link
Member

@markusguenther markusguenther left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for taking care @albe :)

try {
$this->connection->exec("CREATE INDEX state_scheduled ON {$this->connection->quoteIdentifier($this->tableName)} (state, scheduled)");
} catch (Exception $e) {
// See https://dba.stackexchange.com/questions/24531/mysql-create-index-if-not-exists
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's a dangerous pattern to just silently ignore a whole class of exceptions.. IMO we should just catch the exact exception class for the described case and (in the long run) allow the setup to report back

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate key name 'state_scheduled' error
4 participants