Made the results page 'modular,' and all the necessary adaptations.
[selectricity-live] / db / create.sql
1 # CREATE elections TABLE
2 #####################################
3
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, 
10  startdate datetime, 
11  enddate datetime NOT NULL, 
12  active tinyint NOT NULL DEFAULT 0,
13  user_id int NULL,
14  election_method varchar(100) DEFAULT 'ssd',
15  `type` varchar(100) NOT NULL,
16  primary key (id),
17  constraint fk_user_election foreign key (user_id) references users(id)
18 );
19
20 # CREATE candidates TABLE
21 #####################################
22
23 drop table if exists candidates;
24 create table candidates (
25  id int NOT NULL auto_increment,
26  election_id int NOT NULL,
27  name varchar(100) NOT NULL, 
28  description text NULL,
29  picture_filename varchar(200),
30  picture_data blob, 
31  picture_type varchar(100), 
32  primary key (id)
33 );
34
35 # CREATE voters TABLE
36 #####################################
37
38 drop table if exists voters;
39 create table voters (
40  id int NOT NULL auto_increment,
41  email varchar(100) NULL, 
42  password varchar(100) NULL, 
43  contacted tinyint NOT NULL DEFAULT 0, 
44  election_id int NOT NULL, 
45  session_id varchar(32) DEFAULT NULL,
46  ipaddress varchar(32) DEFAULT NULL,
47  constraint fk_election_voter foreign key (election_id) references election(id),
48  primary key (id)
49 );
50
51
52 # CREATE tokens TABLE
53 #####################################
54
55 drop table if exists tokens;
56 create table tokens(
57  id int NOT NULL auto_increment,
58  token varchar(100) NOT NULL, 
59  vote_id int NOT NULL, 
60  constraint fk_vote_token foreign key (vote_id) references vote(id),
61  primary key (id)
62 );
63
64 # CREATE votes TABLE
65 #####################################
66
67 drop table if exists votes;
68 create table votes (
69  id int NOT NULL auto_increment,
70  voter_id int DEFAULT NULL,
71  confirmed tinyint NOT NULL DEFAULT 0,
72  time      datetime         DEFAULT NULL,
73  constraint fk_vote_voter foreign key (voter_id) references voters(id),
74  primary key (id)
75 );
76
77 # CREATE rankings TABLE
78 #####################################
79
80 drop table if exists rankings;
81 create table rankings (
82  id int NOT NULL auto_increment,
83  vote_id int DEFAULT NULL,
84  candidate_id int DEFAULT NULL,
85  rank int DEFAULT NULL,
86  primary key (id)
87 );
88
89 # CREATE users TABLE
90 #####################################
91 #DROP TABLE IF EXISTS `users`;
92 #CREATE TABLE `users` (
93 #  `id` int(11) NOT NULL auto_increment,
94 #  `login` varchar(80) NOT NULL default '',
95 #  `salted_password` varchar(40) NOT NULL default '',
96 #  `email` varchar(60) NOT NULL default '',
97 #  `firstname` varchar(40) default NULL,
98 #  `lastname` varchar(40) default NULL,
99 #  `salt` varchar(40) NOT NULL default '',
100 #  `verified` int(11) default '0',
101 #  `role` varchar(40) default NULL,
102 #  `security_token` varchar(40) default NULL,
103 #  `token_expiry` datetime default NULL,
104 #  `created_at` datetime default NULL,
105 #  `updated_at` datetime default NULL,
106 #  `logged_in_at` datetime default NULL,
107 #  `deleted` int(11) default '0',
108 #  `delete_after` datetime default NULL,
109 #  PRIMARY KEY  (`id`)
110 #) ENGINE=InnoDB DEFAULT CHARSET=latin1;
111
112 #Following is the new users table that goes with acts_as_authenticated
113 #Is simpler for now, saving the old table while in transition between 
114 #the two for ideas on what attributes may be helpful/necessary
115 drop table if exists users;
116 create table users (
117         id                        int         not null auto_increment,
118         login                     text,
119         ip                        text not null,
120         email                     text,
121         crypted_password          varchar(40),
122         salt                      varchar(40),
123         created_at                datetime,
124         updated_at                datetime,
125         remember_token            text,
126         remember_token_expires_at datetime,
127         primary key(id)
128 );

Benjamin Mako Hill || Want to submit a patch?