schema.sql 2.0 KB

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