diff --git a/services/nginx/app/classes/department_daily_report_complaints_schema_bootstrap.php b/services/nginx/app/classes/department_daily_report_complaints_schema_bootstrap.php index 5d2f1fa0..6d18793c 100644 --- a/services/nginx/app/classes/department_daily_report_complaints_schema_bootstrap.php +++ b/services/nginx/app/classes/department_daily_report_complaints_schema_bootstrap.php @@ -34,17 +34,21 @@ class department_daily_report_complaints_schema_bootstrap ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" ); - $db->query( - "ALTER TABLE " . self::TABLE . " - ADD COLUMN IF NOT EXISTS wash_date DATE NULL - AFTER customer_number" - ); + if (!self::columnExists(self::TABLE, 'wash_date')) { + $db->query( + "ALTER TABLE " . self::TABLE . " + ADD COLUMN wash_date DATE NULL + AFTER customer_number" + ); + } - $db->query( - "ALTER TABLE " . self::TABLE . " - ADD COLUMN IF NOT EXISTS category VARCHAR(64) NULL - AFTER wash_date" - ); + if (!self::columnExists(self::TABLE, 'category')) { + $db->query( + "ALTER TABLE " . self::TABLE . " + ADD COLUMN category VARCHAR(64) NULL + AFTER wash_date" + ); + } if (!self::indexExists(self::TABLE, self::WASH_DATE_INDEX)) { $db->query( @@ -68,4 +72,17 @@ class department_daily_report_complaints_schema_bootstrap return $result !== false && $result->num_rows > 0; } + + private static function columnExists(string $table, string $column): bool + { + global $db; + + $table_sql = $db->escape_string($table); + $column_sql = $db->escape_string($column); + $result = $db->query( + "SHOW COLUMNS FROM `$table_sql` LIKE '$column_sql'" + ); + + return $result !== false && $result->num_rows > 0; + } }