Cloudlog/application/migrations/100_update_cat_table.php

87 wiersze
2.8 KiB
PHP
Czysty Zwykły widok Historia

2022-09-29 23:24:10 +00:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
Update CAT table
*/
class Migration_update_cat_table extends CI_Migration {
public function up()
{
if ($this->db->table_exists('cat')) {
if ($this->db->field_exists('uplink_freq', 'cat')) {
$this->dbforge->drop_column('cat', 'uplink_freq');
}
if ($this->db->field_exists('uplink_mode', 'cat')) {
$this->dbforge->drop_column('cat', 'uplink_mode');
}
if ($this->db->field_exists('downlink_freq', 'cat')) {
2022-09-30 15:11:30 +00:00
2022-09-30 14:57:23 +00:00
$fields = array(
2022-09-30 15:11:30 +00:00
2022-09-30 14:57:23 +00:00
'downlink_freq' => array(
'name' => 'frequency_rx',
2022-09-30 15:11:30 +00:00
'type' => 'BIGINT',
'constraint' => '13',
2022-09-30 14:57:23 +00:00
),
);
2022-09-30 14:59:14 +00:00
$this->dbforge->modify_column('cat', $fields);
2022-09-30 15:11:30 +00:00
2022-09-29 23:24:10 +00:00
}
if ($this->db->field_exists('downlink_mode', 'cat')) {
2022-09-30 14:57:23 +00:00
$fields = array(
2022-09-30 15:11:30 +00:00
2022-09-30 14:57:23 +00:00
'downlink_mode' => array(
2022-09-30 15:11:30 +00:00
'name' => 'mode_rx',
'type' => 'VARCHAR',
'constraint' => '10',
2022-09-30 14:57:23 +00:00
),
);
2022-09-30 14:59:14 +00:00
$this->dbforge->modify_column('cat', $fields);
2022-09-29 23:24:10 +00:00
}
}
}
public function down()
{
if ($this->db->table_exists('cat')) {
if ($this->db->field_exists('frequency_rx', 'cat')) {
2022-09-30 15:11:30 +00:00
$fields = array(
'frequency_rx' => array(
'name' => 'downlink_freq',
'type' => 'BIGINT',
'null' => TRUE,
'default' => NULL,
),
);
$this->dbforge->modify_column('cat', $fields);
2022-09-29 23:24:10 +00:00
}
if ($this->db->field_exists('mode_rx', 'cat')) {
2022-09-30 15:11:30 +00:00
$fields = array(
'mode_rx' => array(
'name' => 'downlink_mode',
'type' => 'VARCHAR(255)',
'null' => TRUE,
'default' => NULL,
),
);
$this->dbforge->modify_column('cat', $fields);
2022-09-29 23:24:10 +00:00
}
if (!$this->db->field_exists('uplink_freq', 'cat')) {
$fields = array(
'uplink_freq bigint(13) DEFAULT NULL AFTER `downlink_freq`',
);
$this->dbforge->add_column('cat', $fields);
}
if (!$this->db->field_exists('uplink_mode', 'cat')) {
$fields = array(
'uplink_mode varchar(255) DEFAULT NULL AFTER `downlink_mode`',
);
$this->dbforge->add_column('cat', $fields);
}
}
}
}