0a2f4b5b9dc3bca3ae9dd5d60ab57590e310014e
[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  `type` varchar(100) NOT NULL,
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  ipaddress varchar(32) DEFAULT NULL,
46  constraint fk_election_voter foreign key (election_id) references election(id),
47  primary key (id)
48 );
49
50
51 # CREATE tokens TABLE
52 #####################################
53
54 drop table if exists tokens;
55 create table tokens(
56  id int NOT NULL auto_increment,
57  token varchar(100) NOT NULL, 
58  vote_id int NOT NULL, 
59  constraint fk_vote_token foreign key (vote_id) references vote(id),
60  primary key (id)
61 );
62
63 # CREATE votes TABLE
64 #####################################
65
66 drop table if exists votes;
67 create table votes (
68  id int NOT NULL auto_increment,
69  voter_id int DEFAULT NULL,
70  confirmed tinyint NOT NULL DEFAULT 0,
71  time      datetime         DEFAULT NULL,
72  constraint fk_vote_voter foreign key (voter_id) references voters(id),
73  primary key (id)
74 );
75
76 # CREATE rankings TABLE
77 #####################################
78
79 drop table if exists rankings;
80 create table rankings (
81  id int NOT NULL auto_increment,
82  vote_id int DEFAULT NULL,
83  candidate_id int DEFAULT NULL,
84  rank int DEFAULT NULL,
85  primary key (id)
86 );
87
88 # CREATE users TABLE
89 #####################################
90 #DROP TABLE IF EXISTS `users`;
91 #CREATE TABLE `users` (
92 #  `id` int(11) NOT NULL auto_increment,
93 #  `login` varchar(80) NOT NULL default '',
94 #  `salted_password` varchar(40) NOT NULL default '',
95 #  `email` varchar(60) NOT NULL default '',
96 #  `firstname` varchar(40) default NULL,
97 #  `lastname` varchar(40) default NULL,
98 #  `salt` varchar(40) NOT NULL default '',
99 #  `verified` int(11) default '0',
100 #  `role` varchar(40) default NULL,
101 #  `security_token` varchar(40) default NULL,
102 #  `token_expiry` datetime default NULL,
103 #  `created_at` datetime default NULL,
104 #  `updated_at` datetime default NULL,
105 #  `logged_in_at` datetime default NULL,
106 #  `deleted` int(11) default '0',
107 #  `delete_after` datetime default NULL,
108 #  PRIMARY KEY  (`id`)
109 #) ENGINE=InnoDB DEFAULT CHARSET=latin1;
110
111 #Following is the new users table that goes with acts_as_authenticated
112 #Is simpler for now, saving the old table while in transition between 
113 #the two for ideas on what attributes may be helpful/necessary
114 drop table if exists users;
115 create table users (
116         id                        int         not null auto_increment,
117         login                     text,
118         ip                        text not null,
119         email                     text,
120         crypted_password          varchar(40),
121         salt                      varchar(40),
122         created_at                datetime,
123         updated_at                datetime,
124         remember_token            text,
125         remember_token_expires_at datetime,
126         primary key(id)
127 );

Benjamin Mako Hill || Want to submit a patch?