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:
paolo
2016-07-12 10:52:43 +02:00
parent d6ab664a33
commit 6f3a02abe2
+13 -1
View File
@@ -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)))
{