Skip to content

Commit

Permalink
Merge pull request #14798 from phalcon/fix/#14797-create-table-default
Browse files Browse the repository at this point in the history
#14797 - Column default value
  • Loading branch information
Jeckerson authored Feb 1, 2020
2 parents 5781395 + 470583a commit c69f80e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
## Fixed
- Fixed `Phalcon\Db\Adapter\Pdo\Postgresql` to correctly identify `bool` fields instead of treating them as `tinyint` [#14722](https://github.com/phalcon/cphalcon/issues/14722) [@tidytrax](https://github.com/tidytrax)
- Fixed `Phalcon\Cli\Console` to pass current container to the `Phalcon\Mvc\ModuleDefinitionInterface::registerAutoloaders()` [#14787](https://github.com/phalcon/cphalcon/issues/14787) [@TimurFlush](https://github.com/TimurFlush)
- Fixed `Phalcon\Db\Dialect\Mysql::createTable()` to create default value with CURRENT_TIMESTAMP ON UPDATE/DELETE [#14797]

# [4.0.3](https://github.com/phalcon/cphalcon/releases/tag/v4.0.3) (2020-01-25)
## Added
Expand Down
2 changes: 1 addition & 1 deletion phalcon/Db/Dialect/Mysql.zep
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class Mysql extends Dialect
let defaultValue = column->getDefault();

if memstr(strtoupper(defaultValue), "CURRENT_TIMESTAMP") {
let columnLine .= " DEFAULT CURRENT_TIMESTAMP";
let columnLine .= " DEFAULT " . defaultValue;
} else {
let columnLine .= " DEFAULT \"" . addcslashes(defaultValue, "\"") . "\"";
}
Expand Down
3 changes: 3 additions & 0 deletions tests/_data/fixtures/Db/mysql/example7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE TABLE `table` (
`default_timestamp_update` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL
)
17 changes: 17 additions & 0 deletions tests/integration/Db/Dialect/Mysql/CreateTableCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,23 @@ protected function getCreateTableFixtures(): array
],
rtrim(file_get_contents(dataDir('fixtures/Db/mysql/example6.sql'))),
],
'example7' => [
'',
[
'columns' => [
new Column(
'default_timestamp_update',
[
'type' => 'TIMESTAMP',
'typeReference' => Column::TYPE_TIMESTAMP,
'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
'notNull' => true,
]
),
]
],
rtrim(file_get_contents(dataDir('fixtures/Db/mysql/example7.sql'))),
],
];
}
}

0 comments on commit c69f80e

Please sign in to comment.