drizzle-team / drizzle-team/drizzle-orm
[FEATURE]:Postgres Table Partition Support
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Feature hasn't been suggested before.
- [ ] I have verified this feature I'm about to request hasn't been suggested before.
### Describe the enhancement you want to request
I would strongly support first-class PostgreSQL partitioning in the Drizzle schema API.
Currently, Drizzle is excellent for defining PostgreSQL tables, columns, constraints, indexes, etc., but partitioned tables require custom SQL/migrations. It would be extremely useful if partitioning could be represented directly in the TypeScript schema.
For example:
const orders = pgTable("orders", {
id: uuid().primaryKey(),
tenantId: uuid().notNull(),
createdAt: timestamp({ withTimezone: true }).notNull(),
}, {
partitionBy: {
type: "range",
column: "createdAt",
},
partitions: [
{
name: "orders_2026_09",
from: "2026-09-01",
to: "2026-10-01",
},
{
name: "orders_2026_10",
from: "2026-10-01",
to: "2026-11-01",
},
],
});
Ideally, Drizzle Kit would then be able to:
1. Generate the parent partitioned table.
2. Generate the child partitions.
3. Detect partition changes during schema diff.
4. Generate ATTACH/DETACH PARTITION migrations when appropriate.
5. Support RANGE, LIST, and HASH partitioning.
6. Support DEFAULT partitions.
7. Introspect existing PostgreSQL partitions with "drizzle-kit pull".
8. Handle partition-specific indexes and constraints correctly.
I think this would be especially valuable for large PostgreSQL applications where tables can contain tens/hundreds of millions of rows.
The goal would be to make partitioning a first-class PostgreSQL schema feature rather than requiring users to maintain partition DDL manually in custom migrations.
Contributor guide
Research direction
Start with the TypeScript schema API around pgTable and Drizzle Kit's schema diff, migration-generation, and pull entry points. Review how PostgreSQL tables, indexes, constraints, and custom migrations are currently represented. Done would require an agreed design covering partition creation, changes, introspection, partitioning modes, and partition-specific objects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, typescript
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100