mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Add foreign key constraint also to satmode table
This commit is contained in:
@@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE;
|
||||
|
|
||||
*/
|
||||
|
||||
$config['migration_version'] = 240;
|
||||
$config['migration_version'] = 241;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
22
application/migrations/241_satmode_fk.php
Normal file
22
application/migrations/241_satmode_fk.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Migration_satmode_fk extends CI_Migration {
|
||||
|
||||
public function up() {
|
||||
$this->dbtry("delete from satellitemode where not exists (select 1 from satellite where satelliteid = satellite.id);");
|
||||
$this->dbtry("ALTER TABLE satellitemode ADD CONSTRAINT satmode_satellite_FK FOREIGN KEY (satelliteid) REFERENCES satellite (id) ON DELETE CASCADE ON UPDATE RESTRICT;");
|
||||
}
|
||||
|
||||
public function down() {
|
||||
$this->dbtry("alter table satellitemode drop foreign key satmode_satellite_FK;");
|
||||
}
|
||||
function dbtry($what) {
|
||||
try {
|
||||
$this->db->query($what);
|
||||
} catch (Exception $e) {
|
||||
log_message("error", "Something gone wrong while altering FKs: ".$e." // Executing: ".$this->db->last_query());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user