From a2abeeca39c053f46df7353a49c8f9a8c9b687c8 Mon Sep 17 00:00:00 2001 From: qnnp <58357109+qnnp-me@users.noreply.github.com> Date: Mon, 8 Dec 2025 16:14:19 +0800 Subject: [PATCH 1/3] refactor(db): Change timestamp column types to datetime - Change start_time column type to datetime - Change end_time column type to datetime --- src/Phinx/Db/Adapter/AbstractAdapter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Phinx/Db/Adapter/AbstractAdapter.php b/src/Phinx/Db/Adapter/AbstractAdapter.php index 7391d12d1..918ff6d95 100644 --- a/src/Phinx/Db/Adapter/AbstractAdapter.php +++ b/src/Phinx/Db/Adapter/AbstractAdapter.php @@ -310,8 +310,8 @@ public function createSchemaTable(): void $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', 'datetime', ['default' => null, 'null' => true]) + ->addColumn('end_time', 'datetime', ['default' => null, 'null' => true]) ->addColumn('breakpoint', 'boolean', ['default' => false, 'null' => false]) ->save(); } catch (Exception $exception) { From 99a15c58a21d770deaff53d6a449fcc39c7aab84 Mon Sep 17 00:00:00 2001 From: qnnp <58357109+qnnp-me@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:40:47 +0800 Subject: [PATCH 2/3] feat(migrations): Control timestamp column type using feature flag - Introduce a FeatureFlags class to control the type of timestamp columns - Select DATETIME or TIMESTAMP type based on the addTimestampsUseDateTime flag - Update the timestamp column creation logic in the schema table to support dynamic type selection --- src/Phinx/Db/Adapter/AbstractAdapter.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Phinx/Db/Adapter/AbstractAdapter.php b/src/Phinx/Db/Adapter/AbstractAdapter.php index 918ff6d95..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', 'datetime', ['default' => null, 'null' => true]) - ->addColumn('end_time', 'datetime', ['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) { From b62dbf853edb1102dfc361423aebf54603ff7425 Mon Sep 17 00:00:00 2001 From: qnnp <58357109+qnnp-me@users.noreply.github.com> Date: Sat, 13 Dec 2025 14:20:39 +0800 Subject: [PATCH 3/3] docs(config): Updated configuration documentation and feature flag comments - Added explanation in the configuration documentation regarding the impact of the `add_timestamps_use_datetime` setting on the schema table - Updated the comments for `addTimestampsUseDateTime` in the FeatureFlags class to clarify its effect on the schema table - Ensured consistency between the documentation and code comments --- docs/en/configuration.rst | 3 ++- src/Phinx/Config/FeatureFlags.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) 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;