Mostly worked on the candidate adding feature to include pictures and
[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 NOT NULL,
14  primary key (id),
15  constraint fk_user_election foreign key (user_id) references users(id)
16 );
17
18 # CREATE candidates TABLE
19 #####################################
20
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),
28  picture_data blob, 
29  picture_type varchar(100), 
30  primary key (id)
31 );
32
33 # CREATE voters TABLE
34 #####################################
35
36 drop table if exists voters;
37 create table 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),
44  primary key (id)
45 );
46
47 # CREATE tokens TABLE
48 #####################################
49
50 drop table if exists tokens;
51 create table tokens(
52  id int NOT NULL auto_increment,
53  token varchar(100) NOT NULL, 
54  vote_id int NOT NULL, 
55  constraint fk_vote_token foreign key (vote_id) references vote(id),
56  primary key (id)
57 );
58
59 # CREATE votes TABLE
60 #####################################
61
62 drop table if exists votes;
63 create table 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),
68  primary key (id)
69 );
70
71 # CREATE rankings TABLE
72 #####################################
73
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,
80  primary key (id)
81 );
82
83 # CREATE users TABLE
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,
103   PRIMARY KEY  (`id`)
104 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
105

Benjamin Mako Hill || Want to submit a patch?