2022-01-25 01:32:42 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
|
|
|
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.4.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
class Migration_Add_timestamp_columns extends EA_Migration
|
|
|
|
{
|
2023-10-19 17:25:45 +03:00
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
protected $tables = ['appointments', 'categories', 'consents', 'roles', 'services', 'settings', 'users'];
|
2023-10-19 17:25:45 +03:00
|
|
|
|
2022-01-25 01:32:42 +03:00
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
protected $columns = ['delete_datetime', 'update_datetime', 'create_datetime'];
|
2022-01-25 01:32:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Upgrade method.
|
|
|
|
*/
|
2024-12-19 21:13:51 +03:00
|
|
|
public function up(): void
|
2022-01-25 01:32:42 +03:00
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
foreach ($this->tables as $table) {
|
|
|
|
foreach ($this->columns as $column) {
|
|
|
|
if (!$this->db->field_exists($column, $table)) {
|
2022-01-25 01:32:42 +03:00
|
|
|
$fields = [
|
|
|
|
$column => [
|
|
|
|
'type' => 'DATETIME',
|
2023-11-29 12:24:09 +03:00
|
|
|
'null' => true,
|
2023-12-22 13:35:41 +03:00
|
|
|
'after' => 'id',
|
|
|
|
],
|
2022-01-25 01:32:42 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->dbforge->add_column($table, $fields);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Downgrade method.
|
|
|
|
*/
|
2024-12-19 21:13:51 +03:00
|
|
|
public function down(): void
|
2022-01-25 01:32:42 +03:00
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
foreach ($this->tables as $table) {
|
|
|
|
foreach ($this->columns as $column) {
|
|
|
|
if ($this->db->field_exists($column, $table)) {
|
2022-01-25 01:32:42 +03:00
|
|
|
$this->dbforge->drop_column($table, $column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|