-- The back of a card: an ID card's or a work permit card's two sides are -- two documents, the back pointing at the front, and they print together -- on one A4 sheet. Uploaded together, the second file is the back. ALTER TABLE documents ADD COLUMN back_of BIGINT UNIQUE REFERENCES documents (id) ON DELETE SET NULL, ADD CONSTRAINT documents_back_of_other CHECK (back_of <> id);