Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/en/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ For some breaking changes, Phinx offers a way to opt-out of new behavior. The fo
* ``column_null_default``: Should Phinx create columns as null by default? (default: ``true``)

Since MySQL ``TIMESTAMP`` fields do not support dates past 2038-01-19, you have the option to use ``DATETIME`` field
types for fields created by the ``addTimestamps()`` function:
types for fields created by the ``addTimestamps()`` function. This setting also affects the start_time and end_time
columns in the schema table:

* ``add_timestamps_use_datetime``: Should Phinx create created_at and updated_at fields as datetime? (default: ``false``)

Expand Down
1 change: 1 addition & 0 deletions src/Phinx/Config/FeatureFlags.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class FeatureFlags
public static bool $columnNullDefault = true;
/**
* @var bool Should Phinx create datetime columns for addTimestamps instead of timestamp?
* Also affects start_time and end_time column types in schema table.
*/
public static bool $addTimestampsUseDateTime = false;

Expand Down
9 changes: 7 additions & 2 deletions src/Phinx/Db/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Exception;
use InvalidArgumentException;
use Phinx\Config\FeatureFlags;
use Phinx\Db\Table;
use Phinx\Db\Table\Column;
use Phinx\Util\Literal;
Expand Down Expand Up @@ -307,11 +308,15 @@ public function createSchemaTable(): void
'primary_key' => 'version',
];

$columnType = FeatureFlags::$addTimestampsUseDateTime
? AdapterInterface::PHINX_TYPE_DATETIME
: AdapterInterface::PHINX_TYPE_TIMESTAMP;

$table = new Table($this->getSchemaTableName(), $options, $this);
$table->addColumn('version', 'biginteger', ['null' => false])
->addColumn('migration_name', 'string', ['limit' => 100, 'default' => null, 'null' => true])
->addColumn('start_time', 'timestamp', ['default' => null, 'null' => true])
->addColumn('end_time', 'timestamp', ['default' => null, 'null' => true])
->addColumn('start_time', $columnType, ['default' => null, 'null' => true])
->addColumn('end_time', $columnType, ['default' => null, 'null' => true])
->addColumn('breakpoint', 'boolean', ['default' => false, 'null' => false])
->save();
} catch (Exception $exception) {
Expand Down