schema.sql 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. drop table if exists choices;
  2. drop table if exists attachments;
  3. drop table if exists votes;
  4. drop table if exists roles;
  5. drop table if exists users;
  6. create table users (
  7. id INTEGER primary key autoincrement,
  8. email TEXT unique not null,
  9. password TEXT not null,
  10. name TEXT unique,
  11. organization TEXT,
  12. is_admin INTEGER default 0 not null,
  13. key TEXT
  14. );
  15. create table roles (
  16. id INTEGER primary key autoincrement,
  17. name TEXT,
  18. system INTEGER default 0 not null
  19. );
  20. create table votes (
  21. id INTEGER primary key autoincrement,
  22. title TEXT not null,
  23. description TEXT,
  24. category TEXT,
  25. date_begin INTEGER default CURRENT_TIMESTAMP not null,
  26. date_end INTEGER not null,
  27. is_transparent INTEGER default 1 not null,
  28. is_public INTEGER default 1 not null,
  29. is_multiplechoice INTEGER default 1 not null,
  30. is_weighted INTEGER default 0 not null,
  31. is_open INTEGER default 0 not null,
  32. id_author INTEGER, -- :COMMENT:maethor:120528: not null ?
  33. id_role INTEGER default 1 not null,
  34. FOREIGN KEY(id_author) REFERENCES users(id)
  35. FOREIGN KEY(id_role) REFERENCES roles(id)
  36. );
  37. create table attachments (
  38. url TEXT not null,
  39. id_vote INTEGER not null,
  40. FOREIGN KEY(id_vote) REFERENCES vote(id),
  41. PRIMARY KEY(url, id_vote)
  42. );
  43. create table choices (
  44. id INTEGER primary key autoincrement,
  45. name TEXT not null,
  46. id_vote INTEGER not null,
  47. FOREIGN KEY(id_vote) REFERENCES vote(id)
  48. );
  49. -- Test data
  50. insert into users (email, password, name, organization, is_admin, key) values ("admin@admin.fr", "admin", "Toto (admin) Tata", "World corp", 1, "test");
  51. insert into roles (id, name, system) values (1, "Tous", 1);
  52. insert into roles (name) values ("CA");
  53. insert into roles (name) values ("Members");