Migration scripts, where it is possible, now are using MigrationLib

This commit is contained in:
bison-paolo
2016-11-11 11:16:27 +01:00
parent f13985620c
commit 8025974438
6 changed files with 271 additions and 220 deletions
+55 -51
View File
@@ -1,56 +1,60 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
if (! defined("BASEPATH")) exit("No direct script access allowed");
class Migration_Add_apikey extends CI_Migration {
require_once APPPATH . "/libraries/MigrationLib.php";
public function up()
{
//$this->load->database('system');
$this->dbforge->add_field(array(
'apikey_id' => array(
'type' => 'INT',
'constraint' => 5,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'key' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
'level' => array(
'type' => 'INT',
'null' => TRUE,
),
'ignore_limits' => array(
'type' => 'INT',
'null' => TRUE,
),
'date_created' => array(
'type' => 'DATE',
'null' => TRUE,
'default' => 'now()'
)
));
$this->dbforge->add_key('apikey_id', TRUE);
if (!$this->db->table_exists('ci_apikey'))
{
$this->dbforge->create_table('ci_apikey');
}
class Migration_Add_apikey extends MigrationLib
{
public function __construct()
{
parent::__construct();
}
public function up()
{
$this->startUP();
// Create table public.ci_apikey
$fields = array(
"apikey_id" => array(
"type" => "serial"
),
"key" => array(
"type" => "varchar(100)",
"null" => false
),
"level" => array(
"type" => "integer",
"null" => true
),
"ignore_limits" => array(
"type" => "integer",
"null" => true
),
"date_created" => array(
"type" => "date DEFAULT NOW()",
"null" => true
)
);
$this->createTable("public", "ci_apikey", $fields);
$this->addPrimaryKey(
"public",
"ci_apikey",
"pk_ci_apikey",
array("apikey_id")
);
$this->grantTable(array("SELECT"), "public", "ci_apikey", "vilesci");
$this->endUP();
}
if (!$this->db->simple_query('GRANT SELECT ON public.ci_apikey TO vilesci;'))
{
echo 'Error GRANT to vilesci!';
}
if (!$this->db->simple_query("INSERT INTO ci_apikey (key) VALUES ('testapikey@fhcomplete.org'); INSERT INTO ci_apikey (key) VALUES ('aufnahme@fhcomplete.org');"))
{
echo 'Error DB-Insert!';
}
}
public function down()
{
$this->dbforge->drop_table('ci_apikey');
}
}
public function down()
{
$this->startDown();
$this->dropTable("public", "ci_apikey");
$this->endDown();
}
}
+27 -28
View File
@@ -2,34 +2,33 @@
if (! defined('BASEPATH')) exit('No direct script access allowed');
class Migration_Create_basedb extends CI_Migration {
public function up()
{
//$this->load->database('system');
if (!$this->db->table_exists('tbl_person'))
class Migration_Create_basedb extends CI_Migration
{
public function up()
{
//$this->load->database('system');
if (!$this->db->table_exists('tbl_person'))
{
$this->load->helper('file');
$sqlfile = read_file('./system/fhcomplete3.0.sql');
if (!$this->db->simple_query($sqlfile))
{
$this->load->helper('file');
$sqlfile = read_file('./system/fhcomplete3.0.sql');
if (!$this->db->simple_query($sqlfile))
{
echo "Error creating Basis DB-Schema!";
}
echo "Error creating Basis DB-Schema!";
}
}
public function down()
{
/*$this->db->simple_query('DROP SCHEMA bis;');
$this->db->simple_query('DROP SCHEMA campus;');
$this->db->simple_query('DROP SCHEMA fue;');
$this->db->simple_query('DROP SCHEMA kommune;');
$this->db->simple_query('DROP SCHEMA lehre;');
$this->db->simple_query('DROP SCHEMA sync;');
$this->db->simple_query('DROP SCHEMA system;');
$this->db->simple_query('DROP SCHEMA testtool;');
$this->db->simple_query('DROP SCHEMA wawi;');*/
}
}
}
}
public function down()
{
/*$this->db->simple_query('DROP SCHEMA bis;');
$this->db->simple_query('DROP SCHEMA campus;');
$this->db->simple_query('DROP SCHEMA fue;');
$this->db->simple_query('DROP SCHEMA kommune;');
$this->db->simple_query('DROP SCHEMA lehre;');
$this->db->simple_query('DROP SCHEMA sync;');
$this->db->simple_query('DROP SCHEMA system;');
$this->db->simple_query('DROP SCHEMA testtool;');
$this->db->simple_query('DROP SCHEMA wawi;');*/
}
}
+18 -19
View File
@@ -2,23 +2,22 @@
if (! defined('BASEPATH')) exit('No direct script access allowed');
class Migration_fhc30 extends CI_Migration {
public function up()
{
echo '<br/><h1>Update to FHC 3.0</h1><br/>';
$this->db=$this->load->database('system', true);
$this->load->helper('fhcdb');
$db = new basis_db($this);
require_once('./system/dbupdate_3.0.php');
}
public function down()
{
/*$this->db->simple_query('DROP TABLE fue.tbl_scrumteam;');
$this->db->simple_query('DROP TABLE lehre.tbl_studienordnung;');
$this->db->simple_query('DROP TABLE lehre.tbl_studienordnung_semester;');
$this->db->simple_query('DROP TABLE lehre.tbl_studienplan;');*/
}
}
class Migration_fhc30 extends CI_Migration
{
public function up()
{
echo '<br/><h1>Update to FHC 3.0</h1><br/>';
$this->db=$this->load->database('system', true);
$this->load->helper('fhcdb');
$db = new basis_db($this);
require_once('./system/dbupdate_3.0.php');
}
public function down()
{
/*$this->db->simple_query('DROP TABLE fue.tbl_scrumteam;');
$this->db->simple_query('DROP TABLE lehre.tbl_studienordnung;');
$this->db->simple_query('DROP TABLE lehre.tbl_studienordnung_semester;');
$this->db->simple_query('DROP TABLE lehre.tbl_studienplan;');*/
}
}
+23 -24
View File
@@ -2,28 +2,27 @@
if (! defined('BASEPATH')) exit('No direct script access allowed');
class Migration_fhc31 extends CI_Migration {
public function up()
{
echo '<br/><h1>Update to FHC 3.1</h1><br/>';
$this->db=$this->load->database('system', true);
$this->load->helper('fhcdb');
$db = new basis_db($this);
require_once('./system/dbupdate_3.1.php');
}
public function down()
{
/*$this->db->simple_query('DROP SCHEMA bis;');
$this->db->simple_query('DROP SCHEMA campus;');
$this->db->simple_query('DROP SCHEMA fue;');
$this->db->simple_query('DROP SCHEMA kommune;');
$this->db->simple_query('DROP SCHEMA lehre;');
$this->db->simple_query('DROP SCHEMA sync;');
$this->db->simple_query('DROP SCHEMA system;');
$this->db->simple_query('DROP SCHEMA testtool;');
$this->db->simple_query('DROP SCHEMA wawi;');*/
}
}
class Migration_fhc31 extends CI_Migration
{
public function up()
{
echo '<br/><h1>Update to FHC 3.1</h1><br/>';
$this->db=$this->load->database('system', true);
$this->load->helper('fhcdb');
$db = new basis_db($this);
require_once('./system/dbupdate_3.1.php');
}
public function down()
{
/*$this->db->simple_query('DROP SCHEMA bis;');
$this->db->simple_query('DROP SCHEMA campus;');
$this->db->simple_query('DROP SCHEMA fue;');
$this->db->simple_query('DROP SCHEMA kommune;');
$this->db->simple_query('DROP SCHEMA lehre;');
$this->db->simple_query('DROP SCHEMA sync;');
$this->db->simple_query('DROP SCHEMA system;');
$this->db->simple_query('DROP SCHEMA testtool;');
$this->db->simple_query('DROP SCHEMA wawi;');*/
}
}
+23 -24
View File
@@ -2,28 +2,27 @@
if (! defined('BASEPATH')) exit('No direct script access allowed');
class Migration_fhc32 extends CI_Migration {
public function up()
{
echo '<br/><h1>Update to FHC 3.2</h1><br/>';
$this->db=$this->load->database('system', true);
$this->load->helper('fhcdb');
$db = new basis_db($this);
require_once('./system/dbupdate_3.2.php');
}
public function down()
{
/*$this->db->simple_query('DROP SCHEMA bis;');
$this->db->simple_query('DROP SCHEMA campus;');
$this->db->simple_query('DROP SCHEMA fue;');
$this->db->simple_query('DROP SCHEMA kommune;');
$this->db->simple_query('DROP SCHEMA lehre;');
$this->db->simple_query('DROP SCHEMA sync;');
$this->db->simple_query('DROP SCHEMA system;');
$this->db->simple_query('DROP SCHEMA testtool;');
$this->db->simple_query('DROP SCHEMA wawi;');*/
}
}
class Migration_fhc32 extends CI_Migration
{
public function up()
{
echo '<br/><h1>Update to FHC 3.2</h1><br/>';
$this->db=$this->load->database('system', true);
$this->load->helper('fhcdb');
$db = new basis_db($this);
require_once('./system/dbupdate_3.2.php');
}
public function down()
{
/*$this->db->simple_query('DROP SCHEMA bis;');
$this->db->simple_query('DROP SCHEMA campus;');
$this->db->simple_query('DROP SCHEMA fue;');
$this->db->simple_query('DROP SCHEMA kommune;');
$this->db->simple_query('DROP SCHEMA lehre;');
$this->db->simple_query('DROP SCHEMA sync;');
$this->db->simple_query('DROP SCHEMA system;');
$this->db->simple_query('DROP SCHEMA testtool;');
$this->db->simple_query('DROP SCHEMA wawi;');*/
}
}
+125 -74
View File
@@ -1,85 +1,136 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
if (! defined("BASEPATH")) exit("No direct script access allowed");
class Migration_Phrase extends CI_Migration {
require_once APPPATH . "/libraries/MigrationLib.php";
class Migration_Phrase extends MigrationLib
{
public function __construct()
{
parent::__construct();
}
public function up()
{
if (! $this->db->table_exists('system.tbl_app'))
{
$query= "
CREATE TABLE system.tbl_app (
app varchar(32),
PRIMARY KEY (app)
);
GRANT SELECT ON TABLE system.tbl_app TO web;
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE system.tbl_app TO admin;
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE system.tbl_app TO vilesci;
";
if (!$this->db->simple_query($query))
{
echo "Error creating Basis DB-Schema!";
}
}
if (! $this->db->table_exists('system.tbl_phrase'))
{
$query= "
CREATE TABLE system.tbl_phrase (
phrase_id serial,
app varchar(32) NOT NULL,
phrase varchar(64) NOT NULL,
insertamum timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
insertvon varchar(32),
PRIMARY KEY (phrase_id)
);
GRANT SELECT ON TABLE system.tbl_phrase TO web;
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE system.tbl_phrase TO admin;
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE system.tbl_phrase TO vilesci;
GRANT SELECT, UPDATE ON SEQUENCE system.tbl_phrase_phrase_id_seq TO web;
GRANT SELECT, UPDATE ON SEQUENCE system.tbl_phrase_phrase_id_seq TO admin;
GRANT SELECT, UPDATE ON SEQUENCE system.tbl_phrase_phrase_id_seq TO vilesci;
CREATE TABLE system.tbl_phrasentext (
phrasentext_id serial,
phrase_id bigint NOT NULL,
sprache varchar(32) NOT NULL,
orgeinheit_kurzbz varchar(32),
orgform_kurzbz varchar(32),
text text,
description text,
insertamum timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
insertvon varchar(32),
PRIMARY KEY (phrasentext_id)
);
GRANT SELECT ON TABLE system.tbl_phrasentext TO web;
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE system.tbl_phrasentext TO admin;
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE system.tbl_phrasentext TO vilesci;
GRANT SELECT, UPDATE ON SEQUENCE system.tbl_phrasentext_phrasentext_id_seq TO web;
GRANT SELECT, UPDATE ON SEQUENCE system.tbl_phrasentext_phrasentext_id_seq TO admin;
GRANT SELECT, UPDATE ON SEQUENCE system.tbl_phrasentext_phrasentext_id_seq TO vilesci;
";
if (!$this->db->simple_query($query))
{
echo "Error creating Basis DB-Schema!";
}
}
$this->startUP();
// Create table system.tbl_app
$fields = array(
"app" => array(
"type" => "varchar(32)"
)
);
$this->createTable("system", "tbl_app", $fields);
$this->addPrimaryKey(
"system",
"tbl_app",
"pk_tbl_app",
array("app")
);
$this->grantTable("SELECT", "system", "tbl_app", "web");
$this->grantTable(array("SELECT", "INSERT", "DELETE", "UPDATE"), "system", "tbl_app", "admin");
$this->grantTable(array("SELECT", "INSERT", "DELETE", "UPDATE"), "system", "tbl_app", "vilesci");
// Create table system.tbl_phrase
$fields = array(
"phrase_id" => array(
"type" => "serial"
),
"app" => array(
"type" => "varchar(32)",
"null" => false
),
"phrase" => array(
"type" => "varchar(64)",
"null" => false
),
"insertamum" => array(
"type" => "timestamp DEFAULT CURRENT_TIMESTAMP",
"null" => false
),
"insertvon" => array(
"type" => "varchar(32)",
"null" => true
)
);
$this->createTable("system", "tbl_phrase", $fields);
$this->addPrimaryKey(
"system",
"tbl_phrase",
"pk_tbl_phrase",
array("phrase_id")
);
$this->grantTable("SELECT", "system", "tbl_phrase", "web");
$this->grantTable(array("SELECT", "INSERT", "DELETE", "UPDATE"), "system", "tbl_phrase", "admin");
$this->grantTable(array("SELECT", "INSERT", "DELETE", "UPDATE"), "system", "tbl_phrase", "vilesci");
$this->grantSequence(array("SELECT", "UPDATE"), "system", "tbl_phrase_phrase_id_seq", "web");
$this->grantSequence(array("SELECT", "UPDATE"), "system", "tbl_phrase_phrase_id_seq", "admin");
$this->grantSequence(array("SELECT", "UPDATE"), "system", "tbl_phrase_phrase_id_seq", "vilesci");
// Create table system.tbl_phrasentext
$fields = array(
"phrasentext_id" => array(
"type" => "serial"
),
"phrase_id" => array(
"type" => "bigint",
"null" => false
),
"sprache" => array(
"type" => "varchar(32)",
"null" => false
),
"orgeinheit_kurzbz" => array(
"type" => "varchar(32)",
"null" => true
),
"orgform_kurzbz" => array(
"type" => "varchar(32)",
"null" => true
),
"text" => array(
"type" => "text",
"null" => true
),
"description" => array(
"type" => "text",
"null" => true
),
"insertamum" => array(
"type" => "timestamp DEFAULT CURRENT_TIMESTAMP",
"null" => false
),
"insertvon" => array(
"type" => "varchar(32)",
"null" => true
)
);
$this->createTable("system", "tbl_phrasentext", $fields);
$this->addPrimaryKey(
"system",
"tbl_phrasentext",
"pk_tbl_phrasentext",
array("phrasentext_id")
);
$this->grantTable("SELECT", "system", "tbl_phrasentext", "web");
$this->grantTable(array("SELECT", "INSERT", "DELETE", "UPDATE"), "system", "tbl_phrasentext", "admin");
$this->grantTable(array("SELECT", "INSERT", "DELETE", "UPDATE"), "system", "tbl_phrasentext", "vilesci");
$this->grantSequence(array("SELECT", "UPDATE"), "system", "tbl_phrasentext_phrasentext_id_seq", "web");
$this->grantSequence(array("SELECT", "UPDATE"), "system", "tbl_phrasentext_phrasentext_id_seq", "admin");
$this->grantSequence(array("SELECT", "UPDATE"), "system", "tbl_phrasentext_phrasentext_id_seq", "vilesci");
$this->endUP();
}
public function down()
{
try
{
$this->dbforge->drop_table('system.tbl_phrasentext');
$this->dbforge->drop_table('system.tbl_phrase');
$this->dbforge->drop_table('system.tbl_app');
echo "Table system.tbl_phrasentext, system.tbl_phrase and system.tbl_app dropped!";
}
catch(Exception $e)
{
echo 'Exception abgefangen: ', $e->getMessage(), "\n";
echo $this->db->error();
}
$this->startDown();
$this->dropTable("system", "tbl_phrasentext");
$this->dropTable("system", "tbl_phrase");
$this->dropTable("system", "tbl_app");
$this->endDown();
}
}
}