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,
15 constraint fk_user_election foreign key (user_id) references users(id)
18 # CREATE candidates TABLE
19 #####################################
21 drop table if exists candidates;
22 create table candidates (
23 id int NOT NULL auto_increment,
24 election_id int NOT NULL,
25 name varchar(100) NOT NULL,
26 description text NULL,
27 picture_filename varchar(200),
29 picture_type varchar(100),
34 #####################################
36 drop table if exists voters;
38 id int NOT NULL auto_increment,
39 email varchar(100) NOT NULL,
40 password varchar(100) NOT NULL,
41 contacted tinyint NOT NULL DEFAULT 0,
42 election_id int NOT NULL,
43 constraint fk_election_voter foreign key (election_id) references election(id),
48 #####################################
50 drop table if exists tokens;
52 id int NOT NULL auto_increment,
53 token varchar(100) NOT NULL,
55 constraint fk_vote_token foreign key (vote_id) references vote(id),
60 #####################################
62 drop table if exists votes;
64 id int NOT NULL auto_increment,
65 voter_id int DEFAULT NULL,
66 confirmed tinyint NOT NULL DEFAULT 0,
67 constraint fk_vote_voter foreign key (voter_id) references voters(id),
71 # CREATE rankings TABLE
72 #####################################
74 drop table if exists rankings;
75 create table rankings (
76 id int NOT NULL auto_increment,
77 vote_id int DEFAULT NULL,
78 candidate_id int DEFAULT NULL,
79 rank int DEFAULT NULL,
84 #####################################
85 DROP TABLE IF EXISTS `users`;
86 CREATE TABLE `users` (
87 `id` int(11) NOT NULL auto_increment,
88 `login` varchar(80) NOT NULL default '',
89 `salted_password` varchar(40) NOT NULL default '',
90 `email` varchar(60) NOT NULL default '',
91 `firstname` varchar(40) default NULL,
92 `lastname` varchar(40) default NULL,
93 `salt` varchar(40) NOT NULL default '',
94 `verified` int(11) default '0',
95 `role` varchar(40) default NULL,
96 `security_token` varchar(40) default NULL,
97 `token_expiry` datetime default NULL,
98 `created_at` datetime default NULL,
99 `updated_at` datetime default NULL,
100 `logged_in_at` datetime default NULL,
101 `deleted` int(11) default '0',
102 `delete_after` datetime default NULL,
104 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;