CyberCCNuts
• 1 min read • CyberCCNuts Team

Hybrid PostgreSQL + JSONB Modeling in the CCarNuts DMS

How we pair strict relational tables for inventory and contracts with GIN-indexed JSONB columns for vehicle trims and trade-in checklists in CCarNuts.

While engineering CCarNuts, our database layer had to reconcile two competing requirements:

  1. Strict ACID transactional integrity for VIN-centric multi-branch inventory, partner workshop service orders, bank financing schedules, and legal contracts.
  2. High schema flexibility for attributes that vary wildly across makes and models — factory trim options, inspection checklists, and trade-in appraisal notes.

Best of Both Worlds with JSONB + GIN Indexes

Rather than building slow Entity-Attribute-Value (EAV) join tables, we keep core accounting and inventory state strictly normalized while storing variable vehicle attributes in GIN-indexed JSONB columns:

CREATE TABLE vehicles (
  id UUID PRIMARY KEY,
  vin VARCHAR(17) UNIQUE NOT NULL,
  branch_id UUID NOT NULL,
  acquisition_cost_cents BIGINT NOT NULL,
  status VARCHAR(32) NOT NULL,
  specs JSONB NOT NULL DEFAULT '{}'::jsonb,
  inspection_checklist JSONB NOT NULL DEFAULT '{}'::jsonb,
  created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX idx_vehicles_specs_gin ON vehicles USING GIN (specs jsonb_path_ops);

Multi-store queries filtering available inventory by trim features run in milliseconds over the GIN index, while every service order cost roll-up and sale contract remains protected by relational foreign keys and ACID transactions.