Skip to content

TwilightCoders/active_record-progresql

Repository files navigation

active_record-progresql

ActiveRecord adapter extension for ProgreSQL — teaches ActiveRecord to express and round-trip the fork's schema features so schema.rb stays canonical.

ProgreSQL is a PostgreSQL fork that adds GLOBAL spanning indexes (true cross-partition / cross-inheritance-child PRIMARY KEY / UNIQUE) and cross-child foreign keys (a FK to an inheritance/partition root that resolves into any typed child). Those features need DDL that vanilla ActiveRecord can neither emit nor dump. active_record-progresql closes that gap.

Composes with active_record-mti (which owns the inherits: DSL). active_record-mti provides the inheritance hierarchy; active_record-progresql provides the spanning/GLOBAL primitives over it (and over declarative partitioning, independently).

What it adds

create_table :data, id: :uuid, primary_key: { global: true }   # PRIMARY KEY (id) GLOBAL
add_index :entity, :id, unique: true, global: true             # UNIQUE (id) GLOBAL
t.index :id, unique: true, global: true
  • global: on indexes / primary keys → appends the GLOBAL keyword. Omitted → a normal LOCAL index (unchanged).
  • Schema-dumper round-tripdb:schema:dump re-emits global: true, so schema.rb doesn't silently lose the fork features (the reason you'd otherwise be forced onto schema_format = :sql). This is the load-bearing feature.
  • Cross-child FKs need no new DSL — a standard add_foreign_key to a root resolves into children automatically because the referenced index is GLOBAL. The only primitive is global:.

Spanning-index placement (validated rule)

Auto-derivable from the inheritance tree + FK graph (or declarable explicitly):

Table role Index
inheritance / partition root PRIMARY KEY (id) GLOBAL
FK-target sub-root with children UNIQUE (id) GLOBAL
FK-target leaf LOCAL UNIQUE (id) — cheaper, ON CONFLICT-able; auto-satisfied by the root GLOBAL PK
leaf that later gains time-bucket children upgrade its UNIQUE (id) LOCAL → GLOBAL

Golden fixture

The validated target output is db/structure.sql in the claudepilot monorepo — the real fact-web schema (23 tables / 101 FKs / 3 spanning indexes), already loaded clean against ProgreSQL. The gem's DSL → SQL output should reproduce it, and a dump of a database built from it should round-trip back to the same schema.rb.

Status

🚧 Scaffold. Structure + design are in place; implementation is TODO (see the TODO(agent) markers in lib/active_record/progresql/connection_adapters/postgresql/). Build TDD against the golden fixture.

Build order:

  1. global: on add_index / index DDL emit (schema_statements.rb).
  2. global primary key on create_table.
  3. schema-dumper round-trip (schema_dumper.rb) — the bit that unlocks schema.rb.
  4. (optional) auto-placement from the inheritance + FK graph.

Development

bundle install
rake spec        # rspec (combustion test app against a ProgreSQL instance)

Integration specs run against a live ProgreSQL build (>= the progresql-c1 root-first-GLOBAL fix). active_record-mti is a dev dependency for the inheritance-hierarchy fixtures.

License

MIT — see LICENSE.txt.

About

ActiveRecord adapter extension for ProgreSQL — GLOBAL spanning indexes & cross-child foreign keys

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages