-
Notifications
You must be signed in to change notification settings - Fork 120
Closed
Description
Basic Information
- Plugin version: 5.x-dev
- Framework version: 5.3.x-dev
- PHP version: 8.2.30
Problem Description
We've built a Bake template that will generate a Migration containing the following code:
public function up(): void
{
$table = $this->table('foo_partitioned', [
'id' => false,
'primary_key' => ['id', 'created'],
]);
$table->partitionBy(Partition::TYPE_RANGE_COLUMNS, 'created')
// Yearly partitions for historical data
->addPartition('p2023', '2024-01-01')
->addPartition('p2024', '2025-01-01')
// Monthly partitions from January 2025 onward
->addPartition('p2025_01', '2025-02-01')
->addPartition('p2025_02', '2025-03-01')
...
->addPartition('p2025_11', '2025-12-01')
->addPartition('p2025_12', '2026-01-01')
// Catch-all for future data
->addPartition('pmax', 'MAXVALUE')
->create();
}
We were testing these migrations with -x/--dry-run and we noticed that the partitions query only gets generated if you call create() and not update():
# with 'update'
❯ bin/cake migrations migrate -x -c test_partitions -s Partitions
DRY-RUN mode enabled
== 20260105211436 PartitionOrdersTable: migrating
INSERT INTO phinxlog (version, migration_name, start_time, end_time, breakpoint) VALUES (:c0, :c1, :c2, :c3, :c4)
== 20260105211436 PartitionOrdersTable: migrated 0.0907s
All Done. Took 0.5902s
Observed Behavior
If you switch to create() instead of update() you see the query that you were expecting, kind of:
# with 'create'
❯ bin/cake migrations migrate -x -c test_aurora -s Partitions
DRY-RUN mode enabled
== 20260105211436 PartitionOrdersTable: migrating
CREATE TABLE `foo_partitioned` ( PRIMARY KEY (`id`,`created`)) ENGINE = InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci PARTITION BY RANGE COLUMNS (`created`) (PARTITION `p2023` VALUES LESS THAN ('2024-01-01'), PARTITION `p2024` VALUES LESS THAN ('2025-01-01'), PARTITION `p2025_01` VALUES LESS THAN ('2025-02-01'), ... PARTITION `pmax` VALUES LESS THAN MAXVALUE);
INSERT INTO phinxlog (version, migration_name, start_time, end_time, breakpoint) VALUES (:c0, :c1, :c2, :c3, :c4)
== 20260105211436 PartitionOrdersTable: migrated 0.0859s
All Done. Took 0.5901s
However, in our case the table already exists and we don't want the migration to create it. Granted, this is because we called create().
What We Tried
Trying update() or save() with addPartitionToExisting() has the same issue: no query is generated other than the phinxlog update.