schema.sql 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. create table if not exists ValidPaths (
  2. id integer primary key autoincrement not null,
  3. path text unique not null,
  4. hash text not null,
  5. registrationTime integer not null,
  6. deriver text,
  7. narSize integer
  8. );
  9. create table if not exists Refs (
  10. referrer integer not null,
  11. reference integer not null,
  12. primary key (referrer, reference),
  13. foreign key (referrer) references ValidPaths(id) on delete cascade,
  14. foreign key (reference) references ValidPaths(id) on delete restrict
  15. );
  16. create index if not exists IndexReferrer on Refs(referrer);
  17. create index if not exists IndexReference on Refs(reference);
  18. -- Paths can refer to themselves, causing a tuple (N, N) in the Refs
  19. -- table. This causes a deletion of the corresponding row in
  20. -- ValidPaths to cause a foreign key constraint violation (due to `on
  21. -- delete restrict' on the `reference' column). Therefore, explicitly
  22. -- get rid of self-references.
  23. create trigger if not exists DeleteSelfRefs before delete on ValidPaths
  24. begin
  25. delete from Refs where referrer = old.id and reference = old.id;
  26. end;
  27. create table if not exists DerivationOutputs (
  28. drv integer not null,
  29. id text not null, -- symbolic output id, usually "out"
  30. path text not null,
  31. primary key (drv, id),
  32. foreign key (drv) references ValidPaths(id) on delete cascade
  33. );
  34. create index if not exists IndexDerivationOutputs on DerivationOutputs(path);
  35. create table if not exists FailedPaths (
  36. path text primary key not null,
  37. time integer not null
  38. );