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,
29 constraint fk_user_election foreign key (user_id) references users(id)
32 # CREATE candidates TABLE
33 #####################################
35 drop table if exists candidates;
36 create table candidates (
37 id int NOT NULL auto_increment,
38 election_id int NOT NULL,
39 name varchar(100) NOT NULL,
40 description text NULL,
41 picture blob NOT NULL,
46 #####################################
48 drop table if exists voters;
50 id int NOT NULL auto_increment,
51 email varchar(100) NOT NULL,
52 password varchar(100) NOT NULL,
53 contacted tinyint NOT NULL DEFAULT 0,
54 election_id int NOT NULL,
55 constraint fk_election_voter foreign key (election_id) references election(id),
60 #####################################
62 drop table if exists tokens;
64 id int NOT NULL auto_increment,
65 token varchar(100) NOT NULL,
67 constraint fk_vote_token foreign key (vote_id) references vote(id),
72 #####################################
74 drop table if exists votes;
76 id int NOT NULL auto_increment,
77 voter_id int DEFAULT NULL,
78 confirmed tinyint NOT NULL DEFAULT 0,
79 constraint fk_vote_voter foreign key (voter_id) references voters(id),
83 # CREATE rankings TABLE
84 #####################################
86 drop table if exists rankings;
87 create table rankings (
88 id int NOT NULL auto_increment,
89 vote_id int DEFAULT NULL,
90 candidate_id int DEFAULT NULL,
91 rank int DEFAULT NULL,
96 #####################################
97 DROP TABLE IF EXISTS `users`;
98 CREATE TABLE `users` (
99 `id` int(11) NOT NULL auto_increment,
100 `login` varchar(80) NOT NULL default '',
101 `salted_password` varchar(40) NOT NULL default '',
102 `email` varchar(60) NOT NULL default '',
103 `firstname` varchar(40) default NULL,
104 `lastname` varchar(40) default NULL,
105 `salt` varchar(40) NOT NULL default '',
106 `verified` int(11) default '0',
107 `role` varchar(40) default NULL,
108 `security_token` varchar(40) default NULL,
109 `token_expiry` datetime default NULL,
110 `created_at` datetime default NULL,
111 `updated_at` datetime default NULL,
112 `logged_in_at` datetime default NULL,
113 `deleted` int(11) default '0',
114 `delete_after` datetime default NULL,
116 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;