Skip to content

Commit 99a15c5

Browse files
committed
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
1 parent a2abeec commit 99a15c5

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

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', 'datetime', ['default' => null, 'null' => true])
314-
->addColumn('end_time', 'datetime', ['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)