Skip to content

Conversation

@dereuromark
Copy link
Member

Summary

This PR adds support for PARTITION BY (RANGE, LIST, HASH, KEY) clauses when creating tables and managing partitions on existing tables.

Features

  • RANGE, RANGE COLUMNS, LIST, LIST COLUMNS, HASH, KEY partitioning types
  • Composite partition keys
  • Add/drop partitions on existing tables
  • PostgreSQL declarative partitioning with auto-generated partition table names
  • Expression-based partitioning via Literal class

New Classes

  • Partition: Value object for partition configuration
  • PartitionDefinition: Value object for individual partition definitions
  • AddPartition: Action for adding partitions to existing tables
  • DropPartition: Action for dropping partitions

New Table Methods

  • partitionBy(): Define partitioning on new tables
  • addPartition(): Add partition definitions when creating tables
  • addPartitionToExisting(): Add partition to existing partitioned tables
  • dropPartition(): Remove partition from existing tables

Usage Example

$this->table('orders', ['id' => false, 'primary_key' => ['id', 'order_date']])
    ->addColumn('id', 'integer', ['identity' => true])
    ->addColumn('order_date', 'date')
    ->partitionBy(Partition::TYPE_RANGE_COLUMNS, 'order_date')
    ->addPartition('p2022', '2023-01-01')
    ->addPartition('p2023', '2024-01-01')
    ->addPartition('pmax', 'MAXVALUE')
    ->create();

Notes

  • MySQL requires partition columns in the primary key
  • MySQL's RANGE and LIST only work with integer expressions - use RANGE COLUMNS/LIST COLUMNS for DATE/STRING columns
  • KEY partitioning is MySQL-only
  • SQLite does not support partitioning (throws RuntimeException)

Test plan

  • Unit tests for Partition and PartitionDefinition classes
  • Integration tests for MySQL adapter (RANGE COLUMNS, LIST COLUMNS, HASH, KEY, integer RANGE, expression-based)
  • All existing MySQL adapter tests pass
  • CI should verify PostgreSQL tests

🤖 Generated with Claude Code

This adds support for PARTITION BY (RANGE, LIST, HASH, KEY) clauses
when creating tables and managing partitions on existing tables.

Features:
- RANGE, RANGE COLUMNS, LIST, LIST COLUMNS, HASH, KEY partitioning
- Composite partition keys
- Add/drop partitions on existing tables
- PostgreSQL declarative partitioning with auto-generated table names
- Expression-based partitioning via Literal class

New classes:
- Partition: Value object for partition configuration
- PartitionDefinition: Value object for individual partition definitions
- AddPartition: Action for adding partitions to existing tables
- DropPartition: Action for dropping partitions

New Table methods:
- partitionBy(): Define partitioning on new tables
- addPartition(): Add partition definitions when creating tables
- addPartitionToExisting(): Add partition to existing partitioned tables
- dropPartition(): Remove partition from existing tables

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@dereuromark dereuromark marked this pull request as draft November 23, 2025 10:21
@dereuromark dereuromark changed the base branch from 4.x to 5.x November 23, 2025 10:21
- Remove redundant is_array() check in MysqlAdapter (is_scalar already excludes arrays)
- Remove redundant ?? operator in PostgresAdapter (from key always exists)
- Remove : static return type from Partition::addDefinition() per CakePHP coding standards

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@dereuromark
Copy link
Member Author

CI Status Update:

  • PHPStan & PHPCS: Passing
  • MySQL tests: Passing (all PHP versions)
  • MariaDB tests: Passing (all PHP versions)
  • SQLite tests: Passing (all PHP versions)
  • PostgreSQL tests: Failing - but this is a pre-existing failure on the 5.x branch itself (see run #19602773442). The failure is in BakeMigrationSnapshotCommandTest::testPluginBlog related to timestamp vs timestampfractional type detection, completely unrelated to the partitioning feature.

The partitioning implementation is complete and working correctly for all supported databases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants