Make sure tables dont exist before running migration

这个提交包含在:
Peter Goodhall 2021-08-16 11:24:16 +01:00
父节点 79d9167e8b
当前提交 a80089f97c
共有 2 个文件被更改,包括 61 次插入57 次删除

查看文件

@ -11,38 +11,40 @@ class Migration_create_station_logbook_table extends CI_Migration {
public function up() public function up()
{ {
$this->dbforge->add_field(array( if (!$this->db->table_exists('station_logbooks')) {
'logbook_id' => array( $this->dbforge->add_field(array(
'type' => 'BIGINT', 'logbook_id' => array(
'constraint' => 20, 'type' => 'BIGINT',
'unsigned' => TRUE, 'constraint' => 20,
'auto_increment' => TRUE, 'unsigned' => TRUE,
'unique' => TRUE 'auto_increment' => TRUE,
), 'unique' => TRUE
),
'user_id' => array( 'user_id' => array(
'type' => 'BIGINT', 'type' => 'BIGINT',
'constraint' => 20, 'constraint' => 20,
'unsigned' => TRUE, 'unsigned' => TRUE,
'auto_increment' => FALSE 'auto_increment' => FALSE
), ),
'logbook_name' => array( 'logbook_name' => array(
'type' => 'VARCHAR', 'type' => 'VARCHAR',
'constraint' => '191', 'constraint' => '191',
'null' => TRUE 'null' => TRUE
), ),
'modified' => array( 'modified' => array(
'type' => 'timestamp', 'type' => 'timestamp',
'null' => TRUE, 'null' => TRUE,
) )
)); ));
$this->dbforge->add_key('logbook_id', TRUE); $this->dbforge->add_key('logbook_id', TRUE);
$this->dbforge->add_key('user_id', TRUE); $this->dbforge->add_key('user_id', TRUE);
$this->dbforge->create_table('station_logbooks'); $this->dbforge->create_table('station_logbooks');
}
} }
public function down() public function down()

查看文件

@ -11,40 +11,42 @@ class Migration_create_station_logbook_relationship_table extends CI_Migration {
public function up() public function up()
{ {
$this->dbforge->add_field(array( if (!$this->db->table_exists('station_logbooks_relationship')) {
'logbook_relation_id' => array( $this->dbforge->add_field(array(
'type' => 'BIGINT', 'logbook_relation_id' => array(
'constraint' => 20, 'type' => 'BIGINT',
'unsigned' => TRUE, 'constraint' => 20,
'auto_increment' => TRUE, 'unsigned' => TRUE,
'unique' => TRUE 'auto_increment' => TRUE,
), 'unique' => TRUE
),
'station_logbook_id' => array( 'station_logbook_id' => array(
'type' => 'BIGINT', 'type' => 'BIGINT',
'constraint' => 20, 'constraint' => 20,
'unsigned' => TRUE, 'unsigned' => TRUE,
'auto_increment' => FALSE 'auto_increment' => FALSE
), ),
'station_location_id' => array( 'station_location_id' => array(
'type' => 'BIGINT', 'type' => 'BIGINT',
'constraint' => 20, 'constraint' => 20,
'unsigned' => TRUE, 'unsigned' => TRUE,
'auto_increment' => FALSE 'auto_increment' => FALSE
), ),
'modified' => array( 'modified' => array(
'type' => 'timestamp', 'type' => 'timestamp',
'null' => TRUE, 'null' => TRUE,
) )
)); ));
$this->dbforge->add_key('logbook_relation_id', TRUE); $this->dbforge->add_key('logbook_relation_id', TRUE);
$this->dbforge->add_key('station_logbook_id', TRUE); $this->dbforge->add_key('station_logbook_id', TRUE);
$this->dbforge->add_key('station_location_id', TRUE); $this->dbforge->add_key('station_location_id', TRUE);
$this->dbforge->create_table('station_logbooks_relationship'); $this->dbforge->create_table('station_logbooks_relationship');
}
} }
public function down() public function down()