schema.sql 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 user_role (
  21. id_user INTEGER,
  22. id_role INTEGER,
  23. FOREIGN KEY(id_user) REFERENCES users(id),
  24. FOREIGN KEY(id_role) REFERENCES roles(id),
  25. PRIMARY KEY(id_user, id_role)
  26. );
  27. create table votes (
  28. id INTEGER primary key autoincrement,
  29. title TEXT not null,
  30. description TEXT,
  31. category TEXT,
  32. date_begin INTEGER default CURRENT_TIMESTAMP not null,
  33. date_end INTEGER not null,
  34. is_transparent INTEGER default 1 not null,
  35. is_public INTEGER default 1 not null,
  36. is_multiplechoice INTEGER default 1 not null,
  37. is_weighted INTEGER default 0 not null,
  38. is_open INTEGER default 0 not null,
  39. id_author INTEGER, -- :COMMENT:maethor:120528: not null ?
  40. id_role INTEGER default 1 not null,
  41. FOREIGN KEY(id_author) REFERENCES users(id)
  42. FOREIGN KEY(id_role) REFERENCES roles(id)
  43. );
  44. create table attachments (
  45. url TEXT not null,
  46. id_vote INTEGER not null,
  47. FOREIGN KEY(id_vote) REFERENCES vote(id),
  48. PRIMARY KEY(url, id_vote)
  49. );
  50. create table choices (
  51. id INTEGER primary key autoincrement,
  52. name TEXT not null,
  53. id_vote INTEGER not null,
  54. FOREIGN KEY(id_vote) REFERENCES vote(id)
  55. );
  56. -- Test data
  57. insert into users (email, password, name, organization, is_admin, key) values ("admin@admin.fr", "admin", "Toto (admin) Tata", "World corp", 1, "test");
  58. insert into roles (id, name, system) values (1, "Tous", 1);
  59. insert into roles (name) values ("CA");
  60. insert into roles (name) values ("Members");