schema.sql 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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,
  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,
  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. id_author INTEGER, -- :COMMENT:maethor:120528: not null ?
  42. id_group INTEGER default 1 not null,
  43. FOREIGN KEY(id_author) REFERENCES users(id)
  44. FOREIGN KEY(id_group) REFERENCES groups(id)
  45. );
  46. create table attachments (
  47. id INTEGER primary key autoincrement,
  48. url TEXT not null,
  49. id_vote INTEGER not null,
  50. FOREIGN KEY(id_vote) REFERENCES vote(id)
  51. );
  52. create table choices (
  53. id INTEGER primary key autoincrement,
  54. name TEXT not null,
  55. id_vote INTEGER not null,
  56. FOREIGN KEY(id_vote) REFERENCES vote(id)
  57. );
  58. create table user_choice (
  59. id_user INTEGER,
  60. id_choice INTEGER,
  61. weight INTEGER,
  62. FOREIGN KEY(id_user) REFERENCES users(id),
  63. FOREIGN KEY(id_choice) REFERENCES choices(id),
  64. PRIMARY KEY(id_user, id_choice)
  65. );
  66. -- Test data
  67. insert into users (email, password, name, organization, is_admin, key) values ("admin@admin.fr", "d033e22ae348aeb5660fc2140aec35850c4da997", "Toto (admin) Tata", "World corp", 1, "test"); -- mdp = admin
  68. insert into groups (id, name, system) values (1, "Tous", 1);
  69. insert into groups (name) values ("CA");
  70. insert into groups (name) values ("Members");