diff --git a/db/migrations/20260306_change_passion_to_position.sql b/db/migrations/20260306_change_passion_to_position.sql index cfc3fd9..ee40127 100644 --- a/db/migrations/20260306_change_passion_to_position.sql +++ b/db/migrations/20260306_change_passion_to_position.sql @@ -1,3 +1,3 @@ -ALTER TABLE employees ADD COLUMN position_id INT NULL; -ALTER TABLE employees DROP COLUMN passion_en; -ALTER TABLE employees DROP COLUMN passion_ar; +ALTER TABLE employees ADD COLUMN IF NOT EXISTS position_id INT NULL; +ALTER TABLE employees DROP COLUMN IF EXISTS passion_en; +ALTER TABLE employees DROP COLUMN IF EXISTS passion_ar; \ No newline at end of file diff --git a/db/migrations/20260306_rename_poisons_to_positions.sql b/db/migrations/20260306_rename_poisons_to_positions.sql index 7c01ca6..0887e39 100644 --- a/db/migrations/20260306_rename_poisons_to_positions.sql +++ b/db/migrations/20260306_rename_poisons_to_positions.sql @@ -1 +1,24 @@ -RENAME TABLE poisons TO positions; \ No newline at end of file +SET @dbname = DATABASE(); +SET @tablename = "poisons"; +SET @targetname = "positions"; + +SET @exists = ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES + WHERE table_schema = @dbname + AND table_name = @tablename +); + +SET @target_exists = ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES + WHERE table_schema = @dbname + AND table_name = @targetname +); + +SET @stmt = IF(@exists > 0 AND @target_exists = 0, + CONCAT('RENAME TABLE ', @tablename, ' TO ', @targetname), + 'SELECT 1' +); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; diff --git a/init_db.php b/init_db.php index e8461c6..f4e824c 100644 --- a/init_db.php +++ b/init_db.php @@ -135,7 +135,7 @@ try { FOREIGN KEY (department_id) REFERENCES departments(id) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - CREATE TABLE IF NOT EXISTS poisons ( + CREATE TABLE IF NOT EXISTS positions ( id INT AUTO_INCREMENT PRIMARY KEY, name_en VARCHAR(255) NOT NULL, name_ar VARCHAR(255) NOT NULL,