-- Front 10: the 10x15 cm label at Finalizado (Marcus, 2026-11-10). One 'auto' -- print per order, decided by the unique partial index, so two computers -- asking at once cannot both print it; a reprint is always another row. CREATE TABLE IF NOT EXISTS dtf_local.label_prints ( id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, order_id uuid NOT NULL REFERENCES dtf_local.orders(id) ON DELETE CASCADE, reason text NOT NULL CHECK (reason IN ('auto','reprint')), printed_by text NOT NULL, printed_at timestamptz NOT NULL DEFAULT now() ); CREATE UNIQUE INDEX IF NOT EXISTS label_prints_one_auto ON dtf_local.label_prints(order_id) WHERE reason='auto';