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,
14 quickvote tinyint NOT NULL DEFAULT 0,
16 constraint fk_user_election foreign key (user_id) references users(id)
19 # CREATE candidates TABLE
20 #####################################
22 drop table if exists candidates;
23 create table candidates (
24 id int NOT NULL auto_increment,
25 election_id int NOT NULL,
26 name varchar(100) NOT NULL,
27 description text NULL,
28 picture_filename varchar(200),
30 picture_type varchar(100),
35 #####################################
37 drop table if exists voters;
39 id int NOT NULL auto_increment,
40 email varchar(100) NULL,
41 password varchar(100) NULL,
42 contacted tinyint NOT NULL DEFAULT 0,
43 election_id int NOT NULL,
44 session_id varchar(32) DEFAULT NULL,
45 constraint fk_election_voter foreign key (election_id) references election(id),
51 #####################################
53 drop table if exists tokens;
55 id int NOT NULL auto_increment,
56 token varchar(100) NOT NULL,
58 constraint fk_vote_token foreign key (vote_id) references vote(id),
63 #####################################
65 drop table if exists votes;
67 id int NOT NULL auto_increment,
68 voter_id int DEFAULT NULL,
69 confirmed tinyint NOT NULL DEFAULT 0,
70 constraint fk_vote_voter foreign key (voter_id) references voters(id),
74 # CREATE rankings TABLE
75 #####################################
77 drop table if exists rankings;
78 create table rankings (
79 id int NOT NULL auto_increment,
80 vote_id int DEFAULT NULL,
81 candidate_id int DEFAULT NULL,
82 rank int DEFAULT NULL,
87 #####################################
88 DROP TABLE IF EXISTS `users`;
89 CREATE TABLE `users` (
90 `id` int(11) NOT NULL auto_increment,
91 `login` varchar(80) NOT NULL default '',
92 `salted_password` varchar(40) NOT NULL default '',
93 `email` varchar(60) NOT NULL default '',
94 `firstname` varchar(40) default NULL,
95 `lastname` varchar(40) default NULL,
96 `salt` varchar(40) NOT NULL default '',
97 `verified` int(11) default '0',
98 `role` varchar(40) default NULL,
99 `security_token` varchar(40) default NULL,
100 `token_expiry` datetime default NULL,
101 `created_at` datetime default NULL,
102 `updated_at` datetime default NULL,
103 `logged_in_at` datetime default NULL,
104 `deleted` int(11) default '0',
105 `delete_after` datetime default NULL,
107 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;