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

Benjamin Mako Hill || Want to submit a patch?