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 quickuser varchar(255) NULL, #stores session_id for quickvote creators
15 election_method varchar(100) DEFAULT 'ssd',
16 `type` varchar(100) NOT NULL,
18 constraint fk_user_election foreign key (user_id) references users(id)
21 # CREATE candidates TABLE
22 #####################################
24 drop table if exists candidates;
25 create table candidates (
26 id int NOT NULL auto_increment,
27 election_id int NOT NULL,
28 name varchar(100) NOT NULL,
29 description text NULL,
33 # CREATE pictures TABLE
34 #####################################
36 drop table if exists pictures;
37 create table pictures (
38 id int NOT NULL auto_increment,
39 filename varchar(200),
41 filetype varchar(100),
42 candidate_id int NULL,
43 constraint fk_candidate_picture foreign key (candidate_id) references candidates(id),
48 #####################################
50 drop table if exists voters;
52 id int NOT NULL auto_increment,
53 email varchar(100) NULL,
54 password varchar(100) NULL,
55 contacted tinyint NOT NULL DEFAULT 0,
56 election_id int NOT NULL,
57 session_id varchar(32) DEFAULT NULL,
58 ipaddress varchar(32) DEFAULT NULL,
59 constraint fk_election_voter foreign key (election_id) references election(id),
65 #####################################
67 drop table if exists tokens;
69 id int NOT NULL auto_increment,
70 token varchar(100) NOT NULL,
72 constraint fk_vote_token foreign key (vote_id) references vote(id),
77 #####################################
79 drop table if exists votes;
81 id int NOT NULL auto_increment,
82 voter_id int DEFAULT NULL,
83 confirmed tinyint NOT NULL DEFAULT 0,
84 time datetime DEFAULT NULL,
85 constraint fk_vote_voter foreign key (voter_id) references voters(id),
89 # CREATE rankings TABLE
90 #####################################
92 drop table if exists rankings;
93 create table rankings (
94 id int NOT NULL auto_increment,
95 vote_id int DEFAULT NULL,
96 candidate_id int DEFAULT NULL,
97 rank int DEFAULT NULL,
102 #####################################
103 #DROP TABLE IF EXISTS `users`;
104 #CREATE TABLE `users` (
105 # `id` int(11) NOT NULL auto_increment,
106 # `login` varchar(80) NOT NULL default '',
107 # `salted_password` varchar(40) NOT NULL default '',
108 # `email` varchar(60) NOT NULL default '',
109 # `firstname` varchar(40) default NULL,
110 # `lastname` varchar(40) default NULL,
111 # `salt` varchar(40) NOT NULL default '',
112 # `verified` int(11) default '0',
113 # `role` varchar(40) default NULL,
114 # `security_token` varchar(40) default NULL,
115 # `token_expiry` datetime default NULL,
116 # `created_at` datetime default NULL,
117 # `updated_at` datetime default NULL,
118 # `logged_in_at` datetime default NULL,
119 # `deleted` int(11) default '0',
120 # `delete_after` datetime default NULL,
122 #) ENGINE=InnoDB DEFAULT CHARSET=latin1;
124 #Following is the new users table that goes with acts_as_authenticated
125 #Is simpler for now, saving the old table while in transition between
126 #the two for ideas on what attributes may be helpful/necessary
127 drop table if exists users;
129 id int not null auto_increment,
133 crypted_password varchar(40),
138 remember_token_expires_at datetime,