mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-06 14:49:27 +00:00
Fixed method addColumn. Now it checks correctly if a column exists.
The method provided from CI (db->field_exists) is not reliable.
This commit is contained in:
@@ -52,6 +52,18 @@ class MigrationLib extends CI_Migration
|
||||
printf("%s %s" . $this->getEOL(), $this->ERROR_PREFIX, $error);
|
||||
}
|
||||
|
||||
private function columnExists($name, $schema, $table)
|
||||
{
|
||||
$query = sprintf('SELECT %s FROM %s.%s LIMIT 1', $name, $schema, $table);
|
||||
|
||||
if (@$this->db->simple_query($query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function startUP()
|
||||
{
|
||||
$this->printInfo(sprintf("%s Start method up of class %s %s", $this->SEPARATOR, get_called_class(), $this->SEPARATOR));
|
||||
@@ -66,7 +78,7 @@ class MigrationLib extends CI_Migration
|
||||
{
|
||||
foreach($fields as $name => $definition)
|
||||
{
|
||||
if (!$this->db->field_exists($name, $schema . '.' . $table))
|
||||
if (!$this->columnExists($name, $schema, $table))
|
||||
{
|
||||
if ($this->dbforge->add_column($schema . '.' . $table, array($name => $definition)))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user