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

Benjamin Mako Hill || Want to submit a patch?