finds.dev← search

// the find

rkrage/pg_party

★ 529 · Ruby · MIT · updated Aug 2026

ActiveRecord PostgreSQL Partitioning

pg_party wraps PostgreSQL's native partitioning (range, list, hash, with subpartitions) in ActiveRecord migration methods and model helpers, so Rails apps can create and query partitioned tables without writing raw DDL. It's for teams on Postgres 10+ who need partitioning now and don't want to maintain a pile of custom SQL migrations by hand.

The migration API is genuinely thorough: range/list/hash creation, attach/detach of existing tables as partitions, subpartitioning, and a concurrent add_index_on_all_partitions helper that walks the whole partition tree with threading support — that last one alone saves real pain on big tables. The template-table mechanism for Postgres 10 (where partitioned tables can't have indexes directly) is a clean workaround, and it correctly defers to Postgres 11+'s native index cascading when available instead of always using the workaround. Test matrix is solid — Appraisals across three Rails versions, three-ish Ruby versions, and five Postgres versions, run through CircleCI with coverage tracked on Code Climate.

schema.rb can't represent partitioned tables correctly, so adopting this gem forces you onto the :sql schema format — a real infra change (pg_dump needs to be available everywhere migrations run, and you lose human-readable schema diffs in PRs). The author has explicitly said migration functionality is being split out into pg_ha_migrations and model functionality into its own gem eventually, so anyone adopting this today is building on something mid-deprecation with no firm timeline. Partition/class caching is in-memory per process with no cross-process invalidation — fine for a single dev box, but on a multi-process Puma or Sidekiq fleet you're stuck tuning a TTL or disabling caching outright, which eats the performance benefit it exists for. Composite primary keys (needed if you want create_with_primary_key on a partitioned table) aren't natively supported by ActiveRecord, so you're pushed toward a third-party gem like composite_primary_keys just to get a clean setup.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →