2 #####################################
4 #drop table if exists users;
6 # id int NOT NULL auto_increment,
7 # login varchar(80) default NULL,
8 # password varchar(40) default NULL,
12 ## Create a default system user to own stage directions
13 ## and similar. Users cannot log in.
14 #insert into users ( id, login ) values ( 1, "System Defaults" );
16 # CREATE elections TABLE
17 #####################################
19 drop table if exists elections;
20 create table elections (
21 id int NOT NULL auto_increment,
22 name varchar(100) NOT NULL,
23 description TEXT NOT NULL,
24 anonymous tinyint NOT NULL DEFAULT 0,
25 startdate datetime NOT NULL,
30 # CREATE candidates TABLE
31 #####################################
33 drop table if exists candidates;
34 create table candidates (
35 id int NOT NULL auto_increment,
36 election_id int NOT NULL,
37 name varchar(100) NOT NULL,
38 picture blob NOT NULL,
43 #####################################
45 drop table if exists voters;
47 id int NOT NULL auto_increment,
48 email varchar(100) NOT NULL,
49 password varchar(100) NOT NULL,
50 contacted tinyint NOT NULL DEFAULT 0,
51 election_id int NOT NULL,
52 constraint fk_election_voter foreign key (election_id) references election(id),
57 #####################################
59 drop table if exists tokens;
61 id int NOT NULL auto_increment,
62 token varchar(100) NOT NULL,
67 #####################################
69 drop table if exists votes;
71 id int NOT NULL auto_increment,
72 voter_id int DEFAULT NULL,
73 token_id int DEFAULT NULL,
74 constraint fk_vote_voter foreign key (voter_id) references voters(id),
75 constraint fk_vote_token foreign key (token_id) references token(id),
79 # CREATE rankings TABLE
80 #####################################
82 drop table if exists rankings;
83 create table rankings (
84 id int NOT NULL auto_increment,
85 vote_id int DEFAULT NULL,
86 candidate_id int DEFAULT NULL,
87 rank int DEFAULT NULL,