diff --git a/docs/en/configuration.rst b/docs/en/configuration.rst index d577c092e..3eeb7fe08 100644 --- a/docs/en/configuration.rst +++ b/docs/en/configuration.rst @@ -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``) diff --git a/src/Phinx/Config/FeatureFlags.php b/src/Phinx/Config/FeatureFlags.php index 67da55d29..8d85550e5 100644 --- a/src/Phinx/Config/FeatureFlags.php +++ b/src/Phinx/Config/FeatureFlags.php @@ -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; diff --git a/src/Phinx/Db/Adapter/AbstractAdapter.php b/src/Phinx/Db/Adapter/AbstractAdapter.php index 7391d12d1..89798e97a 100644 --- a/src/Phinx/Db/Adapter/AbstractAdapter.php +++ b/src/Phinx/Db/Adapter/AbstractAdapter.php @@ -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; @@ -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) {