Use database() value for column existing detection

[MAILPOET-4916]
This commit is contained in:
Jan Lysý
2022-12-14 16:34:00 +01:00
committed by Aschepikov
parent 8ef1bfaf24
commit c5cd863f15

View File

@@ -43,10 +43,12 @@ abstract class Migration {
}
protected function columnExists(string $tableName, string $columnName): bool {
// We had a problem with the dbName value in ENV for some customers, because it doesn't match DB name in information schema.
// So we decided to use the DATABASE() value instead.
return $this->connection->executeQuery("
SELECT 1
FROM information_schema.columns
WHERE table_schema = ?
WHERE table_schema = COALESCE(DATABASE(), ?)
AND table_name = ?
AND column_name = ?
", [Env::$dbName, $tableName, $columnName])->fetchOne() !== false;