mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
- Improved MigrationLib
- Improved migration script 011_reihungstest - Added migration script 012_bewerbungsfrist
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
if (! defined("BASEPATH")) exit("No direct script access allowed");
|
||||
|
||||
require_once APPPATH . "/libraries/MigrationLib.php";
|
||||
|
||||
class Migration_Bewerbungsfrist extends MigrationLib
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function up()
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user