2020-04-22 22:48:56 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
2018-04-25 14:40:13 +03:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2018-04-25 14:40:13 +03:00
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2018-04-25 14:40:13 +03:00
|
|
|
* @since v1.3.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
class Migration_Remove_prefix_from_fkey_constraints extends EA_Migration
|
|
|
|
{
|
2020-04-22 22:48:56 +03:00
|
|
|
/**
|
|
|
|
* Upgrade method.
|
|
|
|
*/
|
2018-04-25 14:40:13 +03:00
|
|
|
public function up()
|
|
|
|
{
|
|
|
|
// Drop table constraints.
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('appointments') .
|
|
|
|
'` DROP FOREIGN KEY `' .
|
|
|
|
$this->db->dbprefix('appointments') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'_ibfk_2`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('appointments') .
|
|
|
|
'` DROP FOREIGN KEY `' .
|
|
|
|
$this->db->dbprefix('appointments') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'_ibfk_3`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('appointments') .
|
|
|
|
'` DROP FOREIGN KEY `' .
|
|
|
|
$this->db->dbprefix('appointments') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'_ibfk_4`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('secretaries_providers') .
|
|
|
|
'` DROP FOREIGN KEY `fk_' .
|
|
|
|
$this->db->dbprefix('secretaries_providers') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'_1`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('secretaries_providers') .
|
|
|
|
'` DROP FOREIGN KEY `fk_' .
|
|
|
|
$this->db->dbprefix('secretaries_providers') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'_2`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('services_providers') .
|
|
|
|
'` DROP FOREIGN KEY `' .
|
|
|
|
$this->db->dbprefix('services_providers') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'_ibfk_1`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('services_providers') .
|
|
|
|
'` DROP FOREIGN KEY `' .
|
|
|
|
$this->db->dbprefix('services_providers') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'_ibfk_2`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('services') .
|
|
|
|
'` DROP FOREIGN KEY `' .
|
|
|
|
$this->db->dbprefix('services') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'_ibfk_1`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('users') .
|
|
|
|
'` DROP FOREIGN KEY `' .
|
|
|
|
$this->db->dbprefix('users') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'_ibfk_1`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('user_settings') .
|
|
|
|
'` DROP FOREIGN KEY `' .
|
|
|
|
$this->db->dbprefix('user_settings') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'_ibfk_1`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2018-04-25 14:40:13 +03:00
|
|
|
|
|
|
|
// Add table constraints again without the "ea" prefix.
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('appointments') .
|
|
|
|
'`
|
|
|
|
ADD CONSTRAINT `appointments_users_customer` FOREIGN KEY (`id_users_customer`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('users') .
|
|
|
|
'` (`id`)
|
2018-04-25 14:40:13 +03:00
|
|
|
ON DELETE CASCADE
|
|
|
|
ON UPDATE CASCADE,
|
2023-11-29 12:24:09 +03:00
|
|
|
ADD CONSTRAINT `appointments_services` FOREIGN KEY (`id_services`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('services') .
|
|
|
|
'` (`id`)
|
2018-04-25 14:40:13 +03:00
|
|
|
ON DELETE CASCADE
|
|
|
|
ON UPDATE CASCADE,
|
2023-11-29 12:24:09 +03:00
|
|
|
ADD CONSTRAINT `appointments_users_provider` FOREIGN KEY (`id_users_provider`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('users') .
|
|
|
|
'` (`id`)
|
2018-04-25 14:40:13 +03:00
|
|
|
ON DELETE CASCADE
|
2023-12-22 13:35:41 +03:00
|
|
|
ON UPDATE CASCADE',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2018-04-25 14:40:13 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('secretaries_providers') .
|
|
|
|
'`
|
|
|
|
ADD CONSTRAINT `secretaries_users_secretary` FOREIGN KEY (`id_users_secretary`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('users') .
|
|
|
|
'` (`id`)
|
2018-04-25 14:40:13 +03:00
|
|
|
ON DELETE CASCADE
|
|
|
|
ON UPDATE CASCADE,
|
2023-11-29 12:24:09 +03:00
|
|
|
ADD CONSTRAINT `secretaries_users_provider` FOREIGN KEY (`id_users_provider`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('users') .
|
|
|
|
'` (`id`)
|
2018-04-25 14:40:13 +03:00
|
|
|
ON DELETE CASCADE
|
2023-12-22 13:35:41 +03:00
|
|
|
ON UPDATE CASCADE',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2018-04-25 14:40:13 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('services') .
|
|
|
|
'`
|
|
|
|
ADD CONSTRAINT `services_service_categories` FOREIGN KEY (`id_service_categories`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('service_categories') .
|
|
|
|
'` (`id`)
|
2018-04-25 14:40:13 +03:00
|
|
|
ON DELETE SET NULL
|
2023-12-22 13:35:41 +03:00
|
|
|
ON UPDATE CASCADE',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2018-04-25 14:40:13 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('services_providers') .
|
|
|
|
'`
|
|
|
|
ADD CONSTRAINT `services_providers_users_provider` FOREIGN KEY (`id_users`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('users') .
|
|
|
|
'` (`id`)
|
2018-04-25 14:40:13 +03:00
|
|
|
ON DELETE CASCADE
|
|
|
|
ON UPDATE CASCADE,
|
2023-11-29 12:24:09 +03:00
|
|
|
ADD CONSTRAINT `services_providers_services` FOREIGN KEY (`id_services`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('services') .
|
|
|
|
'` (`id`)
|
2018-04-25 14:40:13 +03:00
|
|
|
ON DELETE CASCADE
|
2023-12-22 13:35:41 +03:00
|
|
|
ON UPDATE CASCADE',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2018-04-25 14:40:13 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('users') .
|
|
|
|
'`
|
|
|
|
ADD CONSTRAINT `users_roles` FOREIGN KEY (`id_roles`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('roles') .
|
|
|
|
'` (`id`)
|
2018-04-25 14:40:13 +03:00
|
|
|
ON DELETE CASCADE
|
2023-12-22 13:35:41 +03:00
|
|
|
ON UPDATE CASCADE',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2018-04-25 14:40:13 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('user_settings') .
|
|
|
|
'`
|
|
|
|
ADD CONSTRAINT `user_settings_users` FOREIGN KEY (`id_users`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('users') .
|
|
|
|
'` (`id`)
|
2018-04-25 14:40:13 +03:00
|
|
|
ON DELETE CASCADE
|
2023-12-22 13:35:41 +03:00
|
|
|
ON UPDATE CASCADE',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2018-04-25 14:40:13 +03:00
|
|
|
}
|
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
/**
|
|
|
|
* Downgrade method.
|
|
|
|
*/
|
2018-04-25 14:40:13 +03:00
|
|
|
public function down()
|
|
|
|
{
|
|
|
|
// Drop table constraints.
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
2023-12-22 13:35:41 +03:00
|
|
|
'ALTER TABLE `' . $this->db->dbprefix('appointments') . '` DROP FOREIGN KEY `appointments_services`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
2023-12-22 13:35:41 +03:00
|
|
|
'ALTER TABLE `' . $this->db->dbprefix('appointments') . '` DROP FOREIGN KEY `appointments_users_customer`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
2023-12-22 13:35:41 +03:00
|
|
|
'ALTER TABLE `' . $this->db->dbprefix('appointments') . '` DROP FOREIGN KEY `appointments_users_provider`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('secretaries_providers') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'` DROP FOREIGN KEY `secretaries_users_secretary`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('secretaries_providers') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'` DROP FOREIGN KEY `secretaries_users_provider`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('services_providers') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'` DROP FOREIGN KEY `services_providers_users_provider`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('services_providers') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'` DROP FOREIGN KEY `services_providers_services`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
|
|
|
$this->db->query(
|
2023-12-22 13:35:41 +03:00
|
|
|
'ALTER TABLE `' . $this->db->dbprefix('services') . '` DROP FOREIGN KEY `services_service_categories`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2020-05-02 13:51:06 +03:00
|
|
|
$this->db->query('ALTER TABLE `' . $this->db->dbprefix('users') . '` DROP FOREIGN KEY `users_roles`');
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
2023-12-22 13:35:41 +03:00
|
|
|
'ALTER TABLE `' . $this->db->dbprefix('user_settings') . '` DROP FOREIGN KEY `user_settings_users`',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2018-04-25 14:40:13 +03:00
|
|
|
|
|
|
|
// Add table constraints again.
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('appointments') .
|
|
|
|
'`
|
|
|
|
ADD CONSTRAINT `' .
|
|
|
|
$this->db->dbprefix('appointments') .
|
|
|
|
'_ibfk_2` FOREIGN KEY (`id_users_customer`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('users') .
|
|
|
|
'` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
|
|
ADD CONSTRAINT `' .
|
|
|
|
$this->db->dbprefix('appointments') .
|
|
|
|
'_ibfk_3` FOREIGN KEY (`id_services`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('services') .
|
|
|
|
'` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
|
|
ADD CONSTRAINT `' .
|
|
|
|
$this->db->dbprefix('appointments') .
|
|
|
|
'_ibfk_4` FOREIGN KEY (`id_users_provider`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('users') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'` (`id`) ON DELETE CASCADE ON UPDATE CASCADE',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2018-04-25 14:40:13 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('secretaries_providers') .
|
|
|
|
'`
|
|
|
|
ADD CONSTRAINT `fk_' .
|
|
|
|
$this->db->dbprefix('secretaries_providers') .
|
|
|
|
'_1` FOREIGN KEY (`id_users_secretary`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('users') .
|
|
|
|
'` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
|
|
ADD CONSTRAINT `fk_' .
|
|
|
|
$this->db->dbprefix('secretaries_providers') .
|
|
|
|
'_2` FOREIGN KEY (`id_users_provider`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('users') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'` (`id`) ON DELETE CASCADE ON UPDATE CASCADE',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2018-04-25 14:40:13 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('services') .
|
|
|
|
'`
|
|
|
|
ADD CONSTRAINT `' .
|
|
|
|
$this->db->dbprefix('services') .
|
|
|
|
'_ibfk_1` FOREIGN KEY (`id_service_categories`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('service_categories') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'` (`id`) ON DELETE SET NULL ON UPDATE CASCADE',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2018-04-25 14:40:13 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('services_providers') .
|
|
|
|
'`
|
|
|
|
ADD CONSTRAINT `' .
|
|
|
|
$this->db->dbprefix('services_providers') .
|
|
|
|
'_ibfk_1` FOREIGN KEY (`id_users`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('users') .
|
|
|
|
'` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
|
|
ADD CONSTRAINT `' .
|
|
|
|
$this->db->dbprefix('services_providers') .
|
|
|
|
'_ibfk_2` FOREIGN KEY (`id_services`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('services') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'` (`id`) ON DELETE CASCADE ON UPDATE CASCADE',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2018-04-25 14:40:13 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('users') .
|
|
|
|
'`
|
|
|
|
ADD CONSTRAINT `' .
|
|
|
|
$this->db->dbprefix('users') .
|
|
|
|
'_ibfk_1` FOREIGN KEY (`id_roles`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('roles') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'` (`id`) ON DELETE CASCADE ON UPDATE CASCADE',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2018-04-25 14:40:13 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->db->query(
|
|
|
|
'ALTER TABLE `' .
|
|
|
|
$this->db->dbprefix('user_settings') .
|
|
|
|
'`
|
|
|
|
ADD CONSTRAINT `' .
|
|
|
|
$this->db->dbprefix('user_settings') .
|
|
|
|
'_ibfk_1` FOREIGN KEY (`id_users`) REFERENCES `' .
|
|
|
|
$this->db->dbprefix('users') .
|
2023-12-22 13:35:41 +03:00
|
|
|
'` (`id`) ON DELETE CASCADE ON UPDATE CASCADE',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2018-04-25 14:40:13 +03:00
|
|
|
}
|
|
|
|
}
|