1 # CREATE elections TABLE
2 #####################################
4 drop table if exists elections;
5 create table elections (
6 id int NOT NULL auto_increment,
7 name varchar(100) NOT NULL,
8 description TEXT NOT NULL,
9 anonymous tinyint NOT NULL DEFAULT 1,
11 enddate datetime NOT NULL,
12 active tinyint NOT NULL DEFAULT 0,
13 viewable tinyint NOT NULL DEFAULT 1,
14 notices tinyint NOT NULL DEFAULT 0,
16 quickuser varchar(255) NULL, #stores session_id for quickvote creators
17 election_method varchar(100) DEFAULT 'ssd',
18 `type` varchar(100) NOT NULL,
20 constraint fk_user_election foreign key (user_id) references users(id)
23 # CREATE candidates TABLE
24 #####################################
26 drop table if exists candidates;
27 create table candidates (
28 id int NOT NULL auto_increment,
29 election_id int NOT NULL,
30 name varchar(100) NOT NULL,
31 description text NULL,
35 # CREATE pictures TABLE
36 #####################################
38 drop table if exists pictures;
39 create table pictures (
40 id int NOT NULL auto_increment,
41 filename varchar(200),
43 filetype varchar(100),
44 candidate_id int NULL,
45 constraint fk_candidate_picture foreign key (candidate_id) references candidates(id),
50 #####################################
52 drop table if exists voters;
54 id int NOT NULL auto_increment,
55 email varchar(100) NULL,
56 password varchar(100) NULL,
57 contacted tinyint NOT NULL DEFAULT 0,
58 election_id int NOT NULL,
59 session_id varchar(32) DEFAULT NULL,
60 ipaddress varchar(32) DEFAULT NULL,
61 `type` varchar(100) NOT NULL,
62 constraint fk_election_voter foreign key (election_id) references election(id),
68 #####################################
70 drop table if exists tokens;
72 id int NOT NULL auto_increment,
73 token varchar(100) NOT NULL,
75 constraint fk_vote_token foreign key (vote_id) references vote(id),
80 #####################################
82 drop table if exists votes;
84 id int NOT NULL auto_increment,
85 voter_id int DEFAULT NULL,
86 confirmed tinyint NOT NULL DEFAULT 0,
87 time datetime DEFAULT NULL,
88 constraint fk_vote_voter foreign key (voter_id) references voters(id),
92 # CREATE rankings TABLE
93 #####################################
95 drop table if exists rankings;
96 create table rankings (
97 id int NOT NULL auto_increment,
98 vote_id int DEFAULT NULL,
99 candidate_id int DEFAULT NULL,
100 rank int DEFAULT NULL,
104 # CREATE sessions TABLE
105 ######################################
107 drop table if exists sessions;
108 create table sessions (
109 id int(11) NOT NULL auto_increment,
112 updated_at datetime DEFAULT NULL,
114 index session_index (sessid)
117 drop table if exists users;
119 id int not null auto_increment,
123 crypted_password varchar(40),
128 remember_token_expires_at datetime,