Database Schemas
Marketplace Commerce PostgreSQL Schema: Orders, Ledger, Refunds, Payouts
Multi-seller Postgres schema: orders, stock reservation, shipments, partial refunds, double-entry ledger and seller payouts, with 22 invariant tests.
What you get: 1 file · 36.88 KB · ZIP
See purchase optionsProduct description
A multi-seller commerce schema for PostgreSQL where the database itself guards the money and the stock. Orders can hold items from several sellers, stock is reserved per location, every payment, refund and payout is posted to a double-entry ledger, and seller payouts can never exceed what a seller has earned. Plain SQL and PL/pgSQL, works with any language or ORM.
What is inside
- 6 ordered SQL migrations: catalogue (sellers with commission in basis points, customers, products, variants), inventory (locations, levels, append-only movement journal), orders (multi-seller items, state machine, reservation, cancel, shipments), ledger (accounts, transactions, entries, balance views), payments, refunds and payouts
- 17 tables, 25 foreign keys, 4 views, 20 functions, 14 triggers
- Functions your app calls: reserve_order_stock, cancel_order, capture_payment, create_refund, complete_refund, create_payout, mark_payout_paid, fail_payout, all idempotent where a webhook may retry
- seed/seed.sql: 3 sellers, 2 customers, 6 variants, stock in 3 locations, one order taken through reserve, capture and partial shipment
- tests/invariants_test.sql: 22 tests, each rolled back, with expected output
- docs/erd.svg and erd-dark.svg, generated from the live database catalog by the included tools/erd.py (Python 3.8+ and psql, no pip packages)
- migrate.sh and a README with the money flow, call examples and error codes
Rules enforced by the database
- Order total adds up; subtotal equals the sum of line totals (checked at commit)
- Stock never negative or over-reserved; two checkouts cannot sell the last unit twice (row locks)
- Every ledger transaction sums to zero; ledger entries and stock movements are immutable
- Refunds, pending plus succeeded, never exceed the captured amount; an item refund never exceeds its line
- Payouts never exceed the seller balance; a failed payout returns the money to the balance
- Shipments cannot exceed ordered quantity or use another seller's item or location
Requirements and setup
PostgreSQL 14, 15, 16 or 17 (tested on 15.14). Run DATABASE_URL=... ./migrate.sh --seed --test and expect 22 PASS lines. One currency per order, full captures, marketplace-funded discounts and no row-level security are documented choices with notes on how to change them.
Licence
Commercial licence: use it in unlimited own and client projects, modify it freely. Reselling or redistributing the schema itself as a template is not allowed.
What you get
1 file · 36.88 KB
- Marketplace-Commerce-PostgreSQL-Schema.zipZIP · 36.88 KB
Database Schemas
Marketplace Commerce PostgreSQL Schema: Orders, Ledger, Refunds, Payouts
Multi-seller Postgres schema: orders, stock reservation, shipments, partial refunds, double-entry ledger and seller payouts, with 22 invariant tests.
Getly opened the uploaded files and found nothing that would stop them opening. It is not a virus scan or a quality rating.
Tags
Frequently asked questions
Do I get access instantly?
Yes. This is a digital product - you can download it right after checkout, straight from your library.
Can I use it for commercial projects?
Yes. Commercial use is allowed: use it in your own business and in things you sell. You may not resell or redistribute the file itself.
What's your refund policy?
You can request a refund within 30 days. If something isn't right, request it from your order and the Getly team reviews it.
What file formats and sizes will I get?
You'll download 1 file - ZIP - 36.88 KB in total.
Do I get free updates?
Yes - when the seller ships a new version, you can re-download the latest files from your library at no extra cost. Check the changelog for recent updates.
Price
$24.00



