a9d430cf83dbc1b8d753f80762052ed61ea6d7d0
[selectricity] / 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  quickvote tinyint NOT NULL DEFAULT 0,
15  primary key (id),
16  constraint fk_user_election foreign key (user_id) references users(id)
17 );
18
19 # CREATE candidates TABLE
20 #####################################
21
22 drop table if exists candidates;
23 create table candidates (
24  id int NOT NULL auto_increment,
25  election_id int NOT NULL,
26  name varchar(100) NOT NULL, 
27  description text NULL,
28  picture_filename varchar(200),
29  picture_data blob, 
30  picture_type varchar(100), 
31  primary key (id)
32 );
33
34 # CREATE voters TABLE
35 #####################################
36
37 drop table if exists voters;
38 create table voters (
39  id int NOT NULL auto_increment,
40  email varchar(100) NULL, 
41  password varchar(100) NULL, 
42  contacted tinyint NOT NULL DEFAULT 0, 
43  election_id int NOT NULL, 
44  session_id varchar(32) DEFAULT NULL,
45  constraint fk_election_voter foreign key (election_id) references election(id),
46  primary key (id)
47 );
48
49
50 # CREATE tokens TABLE
51 #####################################
52
53 drop table if exists tokens;
54 create table tokens(
55  id int NOT NULL auto_increment,
56  token varchar(100) NOT NULL, 
57  vote_id int NOT NULL, 
58  constraint fk_vote_token foreign key (vote_id) references vote(id),
59  primary key (id)
60 );
61
62 # CREATE votes TABLE
63 #####################################
64
65 drop table if exists votes;
66 create table votes (
67  id int NOT NULL auto_increment,
68  voter_id int DEFAULT NULL,
69  confirmed tinyint NOT NULL DEFAULT 0,
70  constraint fk_vote_voter foreign key (voter_id) references voters(id),
71  primary key (id)
72 );
73
74 # CREATE rankings TABLE
75 #####################################
76
77 drop table if exists rankings;
78 create table rankings (
79  id int NOT NULL auto_increment,
80  vote_id int DEFAULT NULL,
81  candidate_id int DEFAULT NULL,
82  rank int DEFAULT NULL,
83  primary key (id)
84 );
85
86 # CREATE users TABLE
87 #####################################
88 DROP TABLE IF EXISTS `users`;
89 CREATE TABLE `users` (
90   `id` int(11) NOT NULL auto_increment,
91   `login` varchar(80) NOT NULL default '',
92   `salted_password` varchar(40) NOT NULL default '',
93   `email` varchar(60) NOT NULL default '',
94   `firstname` varchar(40) default NULL,
95   `lastname` varchar(40) default NULL,
96   `salt` varchar(40) NOT NULL default '',
97   `verified` int(11) default '0',
98   `role` varchar(40) default NULL,
99   `security_token` varchar(40) default NULL,
100   `token_expiry` datetime default NULL,
101   `created_at` datetime default NULL,
102   `updated_at` datetime default NULL,
103   `logged_in_at` datetime default NULL,
104   `deleted` int(11) default '0',
105   `delete_after` datetime default NULL,
106   PRIMARY KEY  (`id`)
107 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
108

Benjamin Mako Hill || Want to submit a patch?