schema.sql 2.4 KB

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