Foreign keys to prevent "orphan" file rows in a database for a scenario involving projects, files and downloads In a system that monitors a file mirror by regularly downloading a file, I want to store a history of the results. So I have three tables:

┌──────────┐ ┌──────────────────┐ ┌────────┐
│projects  │ │downloads         │ │files   │
├──────────┤ ├──────────────────┤ ├────────┤
│project_id│ │download_id       │ │file_id │
│name      │ │project_id        │ │contents│
│(FK?)     │ │download_timestamp│ │(FK?)   │
└──────────┘ │file_id           │ └────────┘
             │(FK?)             │
             └──────────────────┘



All downloads and files belong to a project. 
Everytime a file is downloaded, a new download is inserted.  
If the same contents already exists in the files table for the same project, the new download will point to the existing file, otherwise a new file is also inserted.


I have two foreign keys in downloads, project_id and file_id. Is there a better structure, especially one that prevents orphaned files (files without an associated download)?
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;