Skip to content

Commit 9e6c71d

Browse files
authored
Use timestamp column type for phinxlog if addTimestampsUseDateTime flag disabled (#2401)
1 parent cea9c12 commit 9e6c71d

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

docs/en/configuration.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ For some breaking changes, Phinx offers a way to opt-out of new behavior. The fo
562562
* ``column_null_default``: Should Phinx create columns as null by default? (default: ``true``)
563563

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

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

src/Phinx/Config/FeatureFlags.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class FeatureFlags
2424
public static bool $columnNullDefault = true;
2525
/**
2626
* @var bool Should Phinx create datetime columns for addTimestamps instead of timestamp?
27+
* Also affects start_time and end_time column types in schema table.
2728
*/
2829
public static bool $addTimestampsUseDateTime = false;
2930

src/Phinx/Db/Adapter/AbstractAdapter.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Exception;
1212
use InvalidArgumentException;
13+
use Phinx\Config\FeatureFlags;
1314
use Phinx\Db\Table;
1415
use Phinx\Db\Table\Column;
1516
use Phinx\Util\Literal;
@@ -307,11 +308,15 @@ public function createSchemaTable(): void
307308
'primary_key' => 'version',
308309
];
309310

311+
$columnType = FeatureFlags::$addTimestampsUseDateTime
312+
? AdapterInterface::PHINX_TYPE_DATETIME
313+
: AdapterInterface::PHINX_TYPE_TIMESTAMP;
314+
310315
$table = new Table($this->getSchemaTableName(), $options, $this);
311316
$table->addColumn('version', 'biginteger', ['null' => false])
312317
->addColumn('migration_name', 'string', ['limit' => 100, 'default' => null, 'null' => true])
313-
->addColumn('start_time', 'timestamp', ['default' => null, 'null' => true])
314-
->addColumn('end_time', 'timestamp', ['default' => null, 'null' => true])
318+
->addColumn('start_time', $columnType, ['default' => null, 'null' => true])
319+
->addColumn('end_time', $columnType, ['default' => null, 'null' => true])
315320
->addColumn('breakpoint', 'boolean', ['default' => false, 'null' => false])
316321
->save();
317322
} catch (Exception $exception) {

0 commit comments

Comments
 (0)