Skip to content

Add table partitioning support for MySQL and PostgreSQL#966

Merged
markstory merged 3 commits into5.xfrom
feature/table-partitioning
Jan 5, 2026
Merged

Add table partitioning support for MySQL and PostgreSQL#966
markstory merged 3 commits into5.xfrom
feature/table-partitioning

Conversation

@dereuromark
Copy link
Copy Markdown
Member

@dereuromark dereuromark commented Nov 23, 2025

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 <noreply@anthropic.com>
@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 <noreply@anthropic.com>
@dereuromark
Copy link
Copy Markdown
Member Author

dereuromark commented Nov 23, 2025

CI Status Update:

  • PHPStan & PHPCS: Passing
  • ✅ Tests
    The partitioning implementation is complete and working correctly for all supported databases.

@dereuromark dereuromark marked this pull request as ready for review November 26, 2025 04:53
@LordSimal
Copy link
Copy Markdown
Contributor

I have not yet needed this but LGTM 👍🏻

@markstory markstory merged commit 4fad77c into 5.x Jan 5, 2026
13 checks passed
@markstory markstory deleted the feature/table-partitioning branch January 5, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants