From 16863bcf5b1504aa0af53d407aaa37884dbbb942 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Wed, 15 Dec 2021 07:45:41 +0100 Subject: [PATCH] Renamed the id_service_categories field of services to id_categories --- ...ce_categories_column_of_services_table.php | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 application/migrations/024_rename_id_service_categories_column_of_services_table.php diff --git a/application/migrations/024_rename_id_service_categories_column_of_services_table.php b/application/migrations/024_rename_id_service_categories_column_of_services_table.php new file mode 100644 index 00000000..af58eeb5 --- /dev/null +++ b/application/migrations/024_rename_id_service_categories_column_of_services_table.php @@ -0,0 +1,66 @@ + + * @copyright Copyright (c) 2013 - 2020, Alex Tselegidis + * @license http://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link http://easyappointments.org + * @since v1.5.0 + * ---------------------------------------------------------------------------- */ + +class Migration_Rename_id_service_categories_column_of_services_table extends EA_Migration { + /** + * Upgrade method. + */ + public function up() + { + if ($this->db->field_exists('id_service_categories', 'services')) + { + $this->db->query('ALTER TABLE `' . $this->db->dbprefix('services') . '` DROP FOREIGN KEY `services_service_categories`'); + + $fields = [ + 'id_service_categories' => [ + 'name' => 'id_categories', + 'type' => 'INT', + 'constraint' => '11' + ] + ]; + + $this->dbforge->modify_column('services', $fields); + + $this->db->query('ALTER TABLE `' . $this->db->dbprefix('services') . '` + ADD CONSTRAINT `services_categories` FOREIGN KEY (`id_categories`) REFERENCES `' . $this->db->dbprefix('categories') . '` (`id`) + ON DELETE SET NULL + ON UPDATE CASCADE'); + } + } + + /** + * Downgrade method. + */ + public function down() + { + if ($this->db->field_exists('id_categories', 'services')) + { + $this->db->query('ALTER TABLE `' . $this->db->dbprefix('services') . '` DROP FOREIGN KEY `services_categories`'); + + $fields = [ + 'id_categories' => [ + 'name' => 'id_service_categories', + 'type' => 'INT', + 'constraint' => '11' + ] + ]; + + $this->dbforge->modify_column('services', $fields); + + $this->db->query('ALTER TABLE `' . $this->db->dbprefix('services') . '` + ADD CONSTRAINT `services_service_categories` FOREIGN KEY (`id_categories`) REFERENCES `' . $this->db->dbprefix('categories') . '` (`id`) + ON DELETE SET NULL + ON UPDATE CASCADE'); + } + } +}