Foreign keys to prevent "orphan" file rows in a database for a scenario involving projects, files and downloads
Schematically (out of syntax).

Structures:

CREATE TABLE project ( project_id identity,
                       primary key (project_id),
                       name varchar,
                       unique (name) );

CREATE TABLE file ( file_id identity,
                    primary key (file_id),
                    filelink varchar,
                    content varchar,
                    unique (bf(file_link || content)) );

CREATE TABLE download ( download_id identity,
                        primary key (download_id),
                        project_id,
                        foreign key (project_id) references project (project_id),
                        file_id,
                        foreign key (file_id) references file (file_id),
                        download_timestamp default current_timestamp );


Insertion:

INSERT INTO project (name)
VALUES (@name)
ON CONFLICT (name) DO NOTHING;

INSERT INTO file (filelink, content)
VALUES (@filelink, @content)
ON CONFLICT (filelink, content) DO NOTHING;

INSERT INTO downloads (project_id, file_id)
SELECT project.project_id, file.file_id
FROM project, file
WHERE project.name = @name
  AND file.filelink = @filelink
  AND file.content = @content;