Skip to content

feat: add support for table partitioning#1039

Open
ErdemGKSL wants to merge 2 commits intoSeaQL:masterfrom
ErdemGKSL:feat/table-partitioning
Open

feat: add support for table partitioning#1039
ErdemGKSL wants to merge 2 commits intoSeaQL:masterfrom
ErdemGKSL:feat/table-partitioning

Conversation

@ErdemGKSL
Copy link

@ErdemGKSL ErdemGKSL commented Jan 10, 2026

Summary

This PR adds support for table partitioning to the TableCreateStatement fluent API, with implementations for both PostgreSQL and MySQL backends.

Changes

  • Introduced PartitionBy, PartitionValues, and PartitionDefinition to represent partitioning strategies and values.
  • Extended TableCreateStatement with partitioning methods.
  • Implemented SQL generation logic in PostgresQueryBuilder and MysqlQueryBuilder.
  • Updated TableBuilder trait to include partitioning hooks in prepare_table_create_statement.

Verification

  • Added comprehensive unit tests in tests/postgres/table.rs and tests/mysql/table.rs.
  • All tests passed locally with cargo test --all-features.
  • Formatting and Clippy checks passed.

Usage Example (PostgreSQL)

let sql = Table::create()
    .table(Glyph::Table)
    .col(ColumnDef::new(Glyph::Id).integer().not_null())
    .col(ColumnDef::new(Glyph::Aspect).integer().not_null())
    .partition_by_range([Glyph::Aspect])
    .to_string(PostgresQueryBuilder);

assert_eq!(sql, r#\"CREATE TABLE \"glyph\" ( \"id\" integer NOT NULL, \"aspect\" integer NOT NULL ) PARTITION BY RANGE (\"aspect\")\"#);

let sql = Table::create()
    .table(Alias::new(\"glyph_1\"))
    .partition_of(Glyph::Table)
    .values_from_to([1], [10])
    .to_string(PostgresQueryBuilder);

assert_eq!(sql, r#\"CREATE TABLE \"glyph_1\" PARTITION OF \"glyph\" FOR VALUES FROM (1) TO (10)\"#);

@Huliiiiii
Copy link
Member

LGTM! The only thing left is to replace SimpleExpr with Expr. SimpleExpr is the old API and might be deprecated someday.

@ErdemGKSL
Copy link
Author

@Huliiiiii is this okay?

@LockedThread
Copy link

This looks great and I have been looking forward to this feature for years.

@ErdemGKSL
Copy link
Author

Hi @tyt2y3, just checking in on this when you have a moment. Tests are green and it’s had one look already... lmk if you think it needs any changes to better fit the codebase.

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.

3 participants