Migration classes will first check if changes need to be integrated before executing them.

This commit is contained in:
alext 2018-02-23 15:23:13 +01:00
parent f78f45ef6f
commit 95e32bbd38
4 changed files with 48 additions and 46 deletions

View file

@ -16,17 +16,21 @@ class Migration_Add_calendar_view_setting extends CI_Migration {
{
$this->load->dbforge();
$fields = [
'calendar_view' => [
'type' => 'VARCHAR',
'constraint' => '32',
'default' => 'default'
]
];
$fields = $this->db->list_fields('ea_user_settings');
$this->dbforge->add_column('ea_user_settings', $fields);
$this->db->update('ea_user_settings', ['calendar_view' => 'default']);
if (!in_array('calendar_view', $fields, true)) {
$fields = [
'calendar_view' => [
'type' => 'VARCHAR',
'constraint' => '32',
'default' => 'default'
]
];
$this->dbforge->add_column('ea_user_settings', $fields);
$this->db->update('ea_user_settings', ['calendar_view' => 'default']);
}
}
public function down()

View file

@ -14,25 +14,26 @@
class Migration_Add_service_availabilities_type extends CI_Migration {
public function up()
{
$this->load->dbforge();
$fields = [
'availabilities_type' => [
'type' => 'VARCHAR',
'constraint' => '32',
'default' => 'flexible',
'after' => 'description'
]
];
$this->dbforge->add_column('ea_services', $fields);
$this->db->update('ea_services', ['availabilities_type' => 'flexible']);
if (!$this->db->field_exists('availabilities_type', 'ea_services')) {
$fields = [
'availabilities_type' => [
'type' => 'VARCHAR',
'constraint' => '32',
'default' => 'flexible',
'after' => 'description'
]
];
$this->dbforge->add_column('ea_services', $fields);
$this->db->update('ea_services', ['availabilities_type' => 'flexible']);
}
}
public function down()
{
$this->load->dbforge();
$this->dbforge->drop_column('ea_services', 'availabilities_type');
if ($this->db->field_exists('availabilities_type', 'ea_services')) {
$this->dbforge->drop_column('ea_services', 'availabilities_type');
}
}
}

View file

@ -14,25 +14,26 @@
class Migration_Add_service_attendants_number extends CI_Migration {
public function up()
{
$this->load->dbforge();
$fields = [
'attendants_number' => [
'type' => 'INT',
'constraint' => '11',
'default' => '1',
'after' => 'availabilities_type'
]
];
$this->dbforge->add_column('ea_services', $fields);
$this->db->update('ea_services', ['attendants_number' => '1']);
if (!$this->db->field_exists('attendants_number', 'ea_services')) {
$fields = [
'attendants_number' => [
'type' => 'INT',
'constraint' => '11',
'default' => '1',
'after' => 'availabilities_type'
]
];
$this->dbforge->add_column('ea_services', $fields);
$this->db->update('ea_services', ['attendants_number' => '1']);
}
}
public function down()
{
$this->load->dbforge();
$this->dbforge->drop_column('ea_services', 'attendants_number');
if (!$this->db->field_exists('attendants_number', 'ea_services')) {
$this->dbforge->drop_column('ea_services', 'attendants_number');
}
}
}

View file

@ -14,8 +14,6 @@
class Migration_Change_column_types extends CI_Migration {
public function up()
{
$this->load->dbforge();
// Appointments
$fields = [
'id' => [
@ -189,8 +187,6 @@ class Migration_Change_column_types extends CI_Migration {
public function down()
{
$this->load->dbforge();
// Appointments
$fields = [
'id' => [