I'm building Commitment, a small Android app (iOS is in review) for counts that two people share: milk deliveries, a maid's attendance, money lent to a friend, a gym streak. The whole product is one rule: an entry only counts once the other person confirms it.
That rule turned out to be a nice little data-modeling problem. Here is how it ended up in Postgres on Supabase, with the actual constraints from the migration.
The mark table
Every "this happened" is a row in marks , with a small state machine in a check constraint:
create table public . marks ( id uuid primary key default gen_random_uuid ( ) , commitment_id uuid not null references public . commitments ( id ) on delete cascade , day date not null , marked_by uuid not null references public . profiles ( id ) on delete cascade , marked_at timestamptz not null default now ( ) , status text not null default 'waiting' check ( status in ( 'waiting' , 'confirmed' , 'rejected' , 'expired' ) ) , responded_by uuid references public .…