- Added method addUniqueKey, addCommentToColumn, addCommentToTable and grantSequence to MigrationLib

- Ported script 008_message.php to MigrationLib
- Added fields sent and sentinfo to tbl_msg_recipient
- Changes to 012_bewerbungsfrist.php to be phpcs compliant
This commit is contained in:
paolo
2016-07-26 17:28:01 +02:00
parent 88a395b31e
commit 6eec1ba0b7
3 changed files with 415 additions and 98 deletions
+122
View File
@@ -257,6 +257,44 @@ class MigrationLib extends CI_Migration
}
}
/**
* Sets a column as unique key of a table and schema
*/
protected function addUniqueKey($schema, $table, $name, $fields)
{
$stringFields = null;
if (is_array($fields))
{
if (count($fields) > 0)
{
$stringFields = "";
for ($i = 0; $i < count($fields); $i++)
{
$stringFields .= $fields[$i];
if ($i != count($fields) - 1)
{
$stringFields .= ", ";
}
}
$query = sprintf("CREATE UNIQUE INDEX %s ON %s.%s (%s)", $name, $schema, $table, $stringFields);
}
}
else
{
$query = sprintf("CREATE UNIQUE INDEX %s ON %s.%s (%s)", $name, $schema, $table, $fields);
}
if (@$this->db->simple_query($query))
{
$this->printMessage(sprintf("Added unique key %s on table %s.%s", $name, $schema, $table));
}
else
{
$this->printError(sprintf("Adding unique key %s on table %s.%s", $name, $schema, $table));
}
}
/**
* Grants permissions to a user on a table and schema
*/
@@ -356,6 +394,90 @@ class MigrationLib extends CI_Migration
}
}
/**
* Add comment to a column
*/
protected function addCommentToColumn($schema, $table, $field, $comment)
{
$query = sprintf("COMMENT ON COLUMN %s.%s.%s IS ?", $schema, $table, $field);
if (@$this->db->query($query, array($comment)))
{
$this->printMessage(sprintf("Comment added to %s.%s.%s", $schema, $table, $field));
}
else
{
$this->printError(sprintf("Error while adding comment to %s.%s.%s", $schema, $table, $field));
}
}
/**
* Add comment to a table
*/
protected function addCommentToTable($schema, $table, $comment)
{
$query = sprintf("COMMENT ON TABLE %s.%s IS ?", $schema, $table, $field);
if (@$this->db->query($query, array($comment)))
{
$this->printMessage(sprintf("Comment added to %s.%s", $schema, $table));
}
else
{
$this->printError(sprintf("Error while adding comment to %s.%s", $schema, $table));
}
}
/**
* Grants permissions to a user on a sequence
*/
protected function grantSequence($permissions, $schema, $sequence, $user)
{
$stringPermission = null;
if (is_array($permissions))
{
if (count($permissions) > 0)
{
$stringPermission = "";
for ($i = 0; $i < count($permissions); $i++)
{
$stringPermission .= $permissions[$i];
if ($i != count($permissions) - 1)
{
$stringPermission .= ", ";
}
}
$query = sprintf("GRANT %s ON SEQUENCE %s.%s TO %s", $stringPermission, $schema, $sequence, $user);
}
}
else
{
$query = sprintf("GRANT %s ON SEQUENCE %s.%s TO %s", $permissions, $schema, $sequence, $user);
}
if (@$this->db->simple_query($query))
{
$this->printMessage(
sprintf("Granted permissions %s on sequence %s.%s to user %s",
is_null($stringPermission) ? $permissions : $stringPermission,
$schema,
$sequence,
$user
));
}
else
{
$this->printError(
sprintf("Granting permissions %s on sequence %s.%s to user %s",
is_null($stringPermission) ? $permissions : $stringPermission,
$schema,
$sequence,
$user
));
}
}
/**
* Executes the given query
*/