Working on a step-by-step workflow audit.
[selectricity] / db / create.sql
1 # CREATE users TABLE
2 #####################################
3
4 #drop table if exists users;
5 #create table users (
6 # id int NOT NULL auto_increment,
7 # login varchar(80) default NULL,
8 # password varchar(40) default NULL,
9 # primary key (id)
10 #);
11
12 ## Create a default system user to own stage directions
13 ## and similar. Users cannot log in.
14 #insert into users ( id, login ) values ( 1, "System Defaults" );
15
16 # CREATE elections TABLE
17 #####################################
18
19 drop table if exists elections;
20 create table elections (
21  id int NOT NULL auto_increment,
22  name varchar(100) NOT NULL, 
23  description TEXT NOT NULL, 
24  anonymous tinyint NOT NULL DEFAULT 0, 
25  startdate datetime NOT NULL, 
26  enddate datetime, 
27  user_id int NOT NULL,
28  primary key (id),
29  constraint fk_user_election foreign key (user_id) references users(id)
30 );
31
32 # CREATE candidates TABLE
33 #####################################
34
35 drop table if exists candidates;
36 create table candidates (
37  id int NOT NULL auto_increment,
38  election_id int NOT NULL,
39  name varchar(100) NOT NULL, 
40  description text NULL,
41  picture blob NOT NULL, 
42  primary key (id)
43 );
44
45 # CREATE voters TABLE
46 #####################################
47
48 drop table if exists voters;
49 create table voters (
50  id int NOT NULL auto_increment,
51  email varchar(100) NOT NULL, 
52  password varchar(100) NOT NULL, 
53  contacted tinyint NOT NULL DEFAULT 0, 
54  election_id int NOT NULL, 
55  constraint fk_election_voter foreign key (election_id) references election(id),
56  primary key (id)
57 );
58
59 # CREATE tokens TABLE
60 #####################################
61
62 drop table if exists tokens;
63 create table tokens(
64  id int NOT NULL auto_increment,
65  token varchar(100) NOT NULL, 
66  vote_id int NOT NULL, 
67  constraint fk_vote_token foreign key (vote_id) references vote(id),
68  primary key (id)
69 );
70
71 # CREATE votes TABLE
72 #####################################
73
74 drop table if exists votes;
75 create table votes (
76  id int NOT NULL auto_increment,
77  voter_id int DEFAULT NULL,
78  confirmed tinyint NOT NULL DEFAULT 0,
79  constraint fk_vote_voter foreign key (voter_id) references voters(id),
80  primary key (id)
81 );
82
83 # CREATE rankings TABLE
84 #####################################
85
86 drop table if exists rankings;
87 create table rankings (
88  id int NOT NULL auto_increment,
89  vote_id int DEFAULT NULL,
90  candidate_id int DEFAULT NULL,
91  rank int DEFAULT NULL,
92  primary key (id)
93 );
94
95 # CREATE users TABLE
96 #####################################
97 DROP TABLE IF EXISTS `users`;
98 CREATE TABLE `users` (
99   `id` int(11) NOT NULL auto_increment,
100   `login` varchar(80) NOT NULL default '',
101   `salted_password` varchar(40) NOT NULL default '',
102   `email` varchar(60) NOT NULL default '',
103   `firstname` varchar(40) default NULL,
104   `lastname` varchar(40) default NULL,
105   `salt` varchar(40) NOT NULL default '',
106   `verified` int(11) default '0',
107   `role` varchar(40) default NULL,
108   `security_token` varchar(40) default NULL,
109   `token_expiry` datetime default NULL,
110   `created_at` datetime default NULL,
111   `updated_at` datetime default NULL,
112   `logged_in_at` datetime default NULL,
113   `deleted` int(11) default '0',
114   `delete_after` datetime default NULL,
115   PRIMARY KEY  (`id`)
116 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
117

Benjamin Mako Hill || Want to submit a patch?