Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. ┌──────────┐ ┌──────────────────┐ ┌────────┐
  2. │projects │ │downloads │ │files │
  3. ├──────────┤ ├──────────────────┤ ├────────┤
  4. │project_id│ │download_id │ │file_id │
  5. │name │ │project_id │ │contents│
  6. │(FK?) │ │download_timestamp│ │(FK?) │
  7. └──────────┘ │file_id │ └────────┘
  8. │(FK?) │
  9. └──────────────────┘
  10.  
  11. CREATE TABLE project ( project_id identity,
  12. primary key (project_id),
  13. name varchar,
  14. unique (name) );
  15.  
  16. CREATE TABLE file ( file_id identity,
  17. primary key (file_id),
  18. filelink varchar,
  19. content varchar,
  20. unique (bf(file_link || content)) );
  21.  
  22. CREATE TABLE download ( download_id identity,
  23. primary key (download_id),
  24. project_id,
  25. foreign key (project_id) references project (project_id),
  26. file_id,
  27. foreign key (file_id) references file (file_id),
  28. download_timestamp default current_timestamp );
  29.  
  30. INSERT INTO project (name)
  31. VALUES (@name)
  32. ON CONFLICT (name) DO NOTHING;
  33.  
  34. INSERT INTO file (filelink, content)
  35. VALUES (@filelink, @content)
  36. ON CONFLICT (filelink, content) DO NOTHING;
  37.  
  38. INSERT INTO downloads (project_id, file_id)
  39. SELECT project.project_id, file.file_id
  40. FROM project, file
  41. WHERE project.name = @name
  42. AND file.filelink = @filelink
  43. AND file.content = @content;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement