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 constraint fk_election_voter foreign key (election_id) references election(id),
67 #####################################
69 drop table if exists tokens;
71 id int NOT NULL auto_increment,
72 token varchar(100) NOT NULL,
74 constraint fk_vote_token foreign key (vote_id) references vote(id),
79 #####################################
81 drop table if exists votes;
83 id int NOT NULL auto_increment,
84 voter_id int DEFAULT NULL,
85 confirmed tinyint NOT NULL DEFAULT 0,
86 time datetime DEFAULT NULL,
87 constraint fk_vote_voter foreign key (voter_id) references voters(id),
91 # CREATE rankings TABLE
92 #####################################
94 drop table if exists rankings;
95 create table rankings (
96 id int NOT NULL auto_increment,
97 vote_id int DEFAULT NULL,
98 candidate_id int DEFAULT NULL,
99 rank int DEFAULT NULL,
104 #####################################
105 #DROP TABLE IF EXISTS `users`;
106 #CREATE TABLE `users` (
107 # `id` int(11) NOT NULL auto_increment,
108 # `login` varchar(80) NOT NULL default '',
109 # `salted_password` varchar(40) NOT NULL default '',
110 # `email` varchar(60) NOT NULL default '',
111 # `firstname` varchar(40) default NULL,
112 # `lastname` varchar(40) default NULL,
113 # `salt` varchar(40) NOT NULL default '',
114 # `verified` int(11) default '0',
115 # `role` varchar(40) default NULL,
116 # `security_token` varchar(40) default NULL,
117 # `token_expiry` datetime default NULL,
118 # `created_at` datetime default NULL,
119 # `updated_at` datetime default NULL,
120 # `logged_in_at` datetime default NULL,
121 # `deleted` int(11) default '0',
122 # `delete_after` datetime default NULL,
124 #) ENGINE=InnoDB DEFAULT CHARSET=latin1;
126 #Following is the new users table that goes with acts_as_authenticated
127 #Is simpler for now, saving the old table while in transition between
128 #the two for ideas on what attributes may be helpful/necessary
129 drop table if exists users;
131 id int not null auto_increment,
135 crypted_password varchar(40),
140 remember_token_expires_at datetime,