diff --git a/application/libraries/MigrationLib.php b/application/libraries/MigrationLib.php index 923a7b394..d150f9ef0 100644 --- a/application/libraries/MigrationLib.php +++ b/application/libraries/MigrationLib.php @@ -74,6 +74,16 @@ class MigrationLib extends CI_Migration $this->printInfo(sprintf("%s End method up of class %s %s", $this->SEPARATOR, get_called_class(), $this->SEPARATOR)); } + protected function startDown() + { + $this->printInfo(sprintf("%s Start method down of class %s %s", $this->SEPARATOR, get_called_class(), $this->SEPARATOR)); + } + + protected function endDown() + { + $this->printInfo(sprintf("%s End method down of class %s %s", $this->SEPARATOR, get_called_class(), $this->SEPARATOR)); + } + protected function addColumn($schema, $table, $fields) { foreach($fields as $name => $definition) @@ -96,6 +106,25 @@ class MigrationLib extends CI_Migration } } + protected function dropColumn($schema, $table, $field) + { + if ($this->columnExists($field, $schema, $table)) + { + if ($this->dbforge->drop_column($schema . '.' . $table, $field)) + { + $this->printMessage(sprintf("Column %s.%s.%s has been dropped", $schema, $table, $field)); + } + else + { + $this->printError(sprintf("Error while dropping column %s.%s.%s", $schema, $table, $field)); + } + } + else + { + $this->printInfo(sprintf("Column %s.%s.%s doesn't exist", $schema, $table, $field)); + } + } + protected function addPrimaryKey($schema, $table, $name, $fields) { $stringFields = null; @@ -207,6 +236,18 @@ class MigrationLib extends CI_Migration } } + protected function dropTable($schema, $table) + { + if ($this->dbforge->drop_table($schema . "." . $table)) + { + $this->printMessage(sprintf("Table %s.%s has been dropped", $schema, $table)); + } + else + { + $this->printError(sprintf("Dropping table %s.%s", $schema, $table)); + } + } + protected function execQuery($query) { if (! @$this->db->simple_query($query)) diff --git a/application/migrations/011_reihungstest.php b/application/migrations/011_reihungstest.php index faa10f954..0e677bb63 100644 --- a/application/migrations/011_reihungstest.php +++ b/application/migrations/011_reihungstest.php @@ -178,24 +178,16 @@ class Migration_Reihungstest extends MigrationLib public function down() { - try - { - $this->dbforge->drop_column("public.tbl_reihungstest", "stufe"); - $this->dbforge->drop_column("public.tbl_reihungstest", "anmeldefrist"); - $this->dbforge->drop_column("public.tbl_prestudentstatus", "rt_stufe"); + $this->startDown(); - echo "Columns public.tbl_reihungstest.stufe, public.tbl_reihungstest.anmeldefrist, public.tbl_prestudentstatus.rt_stufe dropped!"; + $this->dropColumn("public", "tbl_reihungstest", "stufe"); + $this->dropColumn("public", "tbl_reihungstest", "anmeldefrist"); + $this->dropColumn("public", "tbl_prestudentstatus", "rt_stufe"); - $this->dbforge->drop_table("public.tbl_rt_studienplan"); - $this->dbforge->drop_table("public.tbl_rt_person"); - $this->dbforge->drop_table("public.tbl_rt_ort"); + $this->dropTable("public", "tbl_rt_studienplan"); + $this->dropTable("public", "tbl_rt_person"); + $this->dropTable("public", "tbl_rt_ort"); - echo "Tables public.tbl_rt_studienplan, public.tbl_rt_person, public.tbl_rt_ort dropped!"; - } - catch(Exception $e) - { - echo "Exception: ", $e->getMessage(), "\n"; - echo $this->db->error(); - } + $this->endDown(); } } \ No newline at end of file diff --git a/application/migrations/012_bewerbungsfrist.php b/application/migrations/012_bewerbungsfrist.php new file mode 100644 index 000000000..6be2bf1ff --- /dev/null +++ b/application/migrations/012_bewerbungsfrist.php @@ -0,0 +1,96 @@ +startUP(); + + // Create table lehre.tbl_bewerbungsfrist + $fields = array( + "bewerbungsfrist_id" => array( + "type" => "integer", + "auto_increment" => true + ), + "studiensemester_kurzbz" => array( + "type" => "varchar(16)" + ), + "begin" => array( + "type" => "date" + ), + "ende" => array( + "type" => "date" + ), + "ende" => array( + "type" => "date" + ), + "nachfrist" => array( + "type" => "boolean DEFAULT FALSE", + "null" => TRUE + ), + "nachfristende" => array( + "type" => "date", + "null" => TRUE + ), + "anmerkung" => array( + "type" => "text" + ), + "insertamum" => array( + "type" => "timestamp DEFAULT NOW()", + "null" => TRUE + ), + "insertvon" => array( + "type" => "varchar(32)", + "null" => TRUE + ), + "updateamum" => array( + "type" => "timestamp DEFAULT NOW()", + "null" => TRUE + ), + "updatevon" => array( + "type" => "varchar(32)", + "null" => TRUE + ) + ); + $this->createTable("lehre", "tbl_bewerbungsfrist", $fields); + $this->addPrimaryKey( + "lehre", + "tbl_bewerbungsfrist", + "pk_tbl_bewerbungsfrist", + array("bewerbungsfrist_id") + ); + $this->addForeingKey( + "lehre", + "tbl_bewerbungsfrist", + "fk_bewerbungsfrist_studiensemester_kurzbz", + "studiensemester_kurzbz", + "public", + "tbl_studiensemester", + "studiensemester_kurzbz", + "ON UPDATE CASCADE ON DELETE RESTRICT" + ); + $this->grantTable("SELECT", "lehre", "tbl_bewerbungsfrist", "web"); + $this->grantTable(array("SELECT", "INSERT", "DELETE", "UPDATE"), "lehre", "tbl_bewerbungsfrist", "admin"); + $this->grantTable(array("SELECT", "INSERT", "DELETE", "UPDATE"), "lehre", "tbl_bewerbungsfrist", "vilesci"); + + $this->endUP(); + } + + public function down() + { + $this->startDown(); + + $this->dropTable("lehre", "tbl_bewerbungsfrist"); + + $this->endDown(); + } +} \ No newline at end of file