}
$this->columnsToAdd[$tableName][] = $column;
}
- else if (!empty(array_diff($column->getData(), $existingColumns[$column->getName()]->getData()))) {
+ else if ($this->diffColumns($existingColumns[$column->getName()], $column)) {
if (!isset($this->columnsToAlter[$tableName])) {
$this->columnsToAlter[$tableName] = [];
}
]);
}
+ /**
+ * Returns `true` if the two columns differ.
+ *
+ * @param IDatabaseTableColumn $oldColumn
+ * @param IDatabaseTableColumn $newColumn
+ * @return bool
+ */
+ protected function diffColumns(IDatabaseTableColumn $oldColumn, IDatabaseTableColumn $newColumn) {
+ if (!empty(array_diff($oldColumn->getData(), $newColumn->getData()))) {
+ return true;
+ }
+
+ // default type has to be checked with a strict check to differentiate between having
+ // no default value (`null`) and having an empty string as default value
+ return $oldColumn->getDefaultValue() !== $newColumn->getDefaultValue();
+ }
+
/**
* Drops the given foreign key.
*
*/
public function getData() {
$data = [
- 'default' => $this->defaultValue,
+ 'default' => $this->getDefaultValue() !== null ? "'" . str_replace(["'", '\\'], ["''", '\\\\'], $this->getDefaultValue()) . "'" : null,
'notNull' => $this->isNotNull() ? 1 : 0,
'type' => $this->getType()
];