Skip to content

Commit

Permalink
Update PostgresSchema.php
Browse files Browse the repository at this point in the history
Change how NULL and default values are handled. Fix problem where 'DATETIME' was not being handled correctly.
  • Loading branch information
ajquick committed Jan 15, 2017
1 parent 5a75112 commit 1dcca27
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Database/Schema/PostgresSchema.php
Expand Up @@ -409,17 +409,22 @@ public function columnSql(Table $table, $name)

if (isset($data['null']) && $data['null'] === false) {
$out .= ' NOT NULL';
} elseif (isset($data['null']) && $data['null'] === true) {
$out .= ' NULL';
}
if (isset($data['null']) && $data['null'] === true && $data['type'] === 'timestamp') {
$out .= ' DEFAULT NULL';
unset($data['default']);
}
if (isset($data['default']) && $data['type'] !== 'timestamp') {

if (isset($data['default']) &&
in_array($data['type'], ['timestamp', 'datetime']) &&
strtolower($data['default']) === 'current_timestamp') {
$out .= ' DEFAULT CURRENT_TIMESTAMP';
} elseif (isset($data['default'])) {
$defaultValue = $data['default'];
if ($data['type'] === 'boolean') {
$defaultValue = (bool)$defaultValue;
}
$out .= ' DEFAULT ' . $this->_driver->schemaValue($defaultValue);
} elseif (isset($data['null']) && $data['null'] === true) {
$out .= ' DEFAULT NULL';
}

return $out;
Expand Down

0 comments on commit 1dcca27

Please sign in to comment.