Scrollbar if someone creates too many electons to fit within defualt given room for...
[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  viewable tinyint NOT NULL DEFAULT 1,
14  notices tinyint NOT NULL DEFAULT 0,
15  user_id int NULL,
16  quickuser varchar(255) NULL, #stores session_id for quickvote creators
17  election_method varchar(100) DEFAULT 'ssd',
18  `type` varchar(100) NOT NULL,
19  primary key (id),
20  constraint fk_user_election foreign key (user_id) references users(id)
21 );
22
23 # CREATE candidates TABLE
24 #####################################
25
26 drop table if exists candidates;
27 create table candidates (
28  id int NOT NULL auto_increment,
29  election_id int NOT NULL,
30  name varchar(100) NOT NULL, 
31  description text NULL,
32  primary key (id)
33 );
34
35 # CREATE pictures TABLE
36 #####################################
37
38 drop table if exists pictures;
39 create table pictures (
40  id int NOT NULL auto_increment,
41  filename varchar(200),
42  data blob, 
43  filetype varchar(100), 
44  candidate_id int NULL,
45  constraint fk_candidate_picture foreign key (candidate_id) references candidates(id),
46  primary key (id)
47 );
48
49 # CREATE voters TABLE
50 #####################################
51
52 drop table if exists voters;
53 create table voters (
54  id int NOT NULL auto_increment,
55  email varchar(100) NULL, 
56  password varchar(100) NULL, 
57  contacted tinyint NOT NULL DEFAULT 0, 
58  election_id int NOT NULL, 
59  session_id varchar(32) DEFAULT NULL,
60  ipaddress varchar(32) DEFAULT NULL,
61  `type` varchar(100) NOT NULL,
62  constraint fk_election_voter foreign key (election_id) references election(id),
63  primary key (id)
64 );
65
66
67 # CREATE tokens TABLE
68 #####################################
69
70 drop table if exists tokens;
71 create table tokens(
72  id int NOT NULL auto_increment,
73  token varchar(100) NOT NULL, 
74  vote_id int NOT NULL, 
75  constraint fk_vote_token foreign key (vote_id) references vote(id),
76  primary key (id)
77 );
78
79 # CREATE votes TABLE
80 #####################################
81
82 drop table if exists votes;
83 create table votes (
84  id int NOT NULL auto_increment,
85  voter_id int DEFAULT NULL,
86  confirmed tinyint NOT NULL DEFAULT 0,
87  time      datetime         DEFAULT NULL,
88  constraint fk_vote_voter foreign key (voter_id) references voters(id),
89  primary key (id)
90 );
91
92 # CREATE rankings TABLE
93 #####################################
94
95 drop table if exists rankings;
96 create table rankings (
97  id int NOT NULL auto_increment,
98  vote_id int DEFAULT NULL,
99  candidate_id int DEFAULT NULL,
100  rank int DEFAULT NULL,
101  primary key (id)
102 );
103
104 # CREATE sessions TABLE
105 ######################################
106
107 drop table if exists sessions;
108 create table sessions (
109  id         int(11)      NOT NULL auto_increment,
110  sessid     varchar(255),
111  data       text,
112  updated_at datetime     DEFAULT  NULL,
113  primary    key (id),
114  index      session_index (sessid)
115 );
116
117 drop table if exists users;
118 create table users (
119         id                        int         not null auto_increment,
120         login                     text,
121         ip                        text not null,
122         email                     text,
123         crypted_password          varchar(40),
124         salt                      varchar(40),
125         created_at                datetime,
126         updated_at                datetime,
127         remember_token            text,
128         remember_token_expires_at datetime,
129         primary key(id)
130 );

Benjamin Mako Hill || Want to submit a patch?