Skip to content

Commit

Permalink
Add in database structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonspriggs authored May 15, 2017
1 parent 0a30a2e commit a0964b1
Showing 1 changed file with 274 additions and 0 deletions.
274 changes: 274 additions & 0 deletions database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
-- phpMyAdmin SQL Dump
-- version 4.6.6
-- https://www.phpmyadmin.net/

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";

-- --------------------------------------------------------

--
-- Table structure for table `access`
--

CREATE TABLE `access` (
`election` int(11) UNSIGNED NOT NULL COMMENT 'ID of the election',
`user` int(11) UNSIGNED NOT NULL COMMENT 'ID of the user',
`level` tinyint(4) UNSIGNED NOT NULL COMMENT 'Access level, 0 is lowest, 255 is highest',
`data` text COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `audit`
--

CREATE TABLE `audit` (
`id` int(11) UNSIGNED NOT NULL,
`user` int(11) UNSIGNED NOT NULL,
`action` varchar(16) COLLATE utf8_unicode_ci NOT NULL,
`details` text COLLATE utf8_unicode_ci,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `ballots`
--

CREATE TABLE `ballots` (
`id` char(16) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `elections`
--

CREATE TABLE `elections` (
`id` int(11) UNSIGNED NOT NULL COMMENT 'Election ID',
`name` varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Untitled Election' COMMENT 'Title of the election',
`method` varchar(12) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'simple',
`stage` varchar(12) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'created',
`createtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Time election was created',
`end_prep` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`end_election` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `questions`
--

CREATE TABLE `questions` (
`id` int(11) UNSIGNED NOT NULL,
`election` int(11) UNSIGNED NOT NULL,
`order` int(11) NOT NULL,
`data` text COLLATE utf8_unicode_ci
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `stages`
--

CREATE TABLE `stages` (
`id` int(11) UNSIGNED NOT NULL,
`election` int(11) UNSIGNED NOT NULL,
`name` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
`type` varchar(8) COLLATE utf8_unicode_ci NOT NULL,
`starttime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`endtime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
`id` int(11) UNSIGNED NOT NULL COMMENT 'User ID',
`email` varchar(320) CHARACTER SET latin1 NOT NULL COMMENT 'User''s email address',
`password` text CHARACTER SET latin1 NOT NULL COMMENT 'User''s password',
`createdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'User''s creation time',
`updatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'User''s last account update time',
`system_admin` tinyint(3) UNSIGNED NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `voters`
--

CREATE TABLE `voters` (
`id` int(11) UNSIGNED NOT NULL,
`election` int(11) UNSIGNED NOT NULL,
`email` varchar(320) CHARACTER SET latin1 NOT NULL,
`voter_token` varchar(36) COLLATE utf8_unicode_ci DEFAULT NULL,
`has_voted` tinyint(4) UNSIGNED NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `votes`
--

CREATE TABLE `votes` (
`ballot` char(16) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`election` int(11) UNSIGNED NOT NULL,
`question` int(11) UNSIGNED NOT NULL,
`data` text COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `access`
--
ALTER TABLE `access`
ADD UNIQUE KEY `user_2` (`user`,`election`),
ADD KEY `election` (`election`),
ADD KEY `user` (`user`);

--
-- Indexes for table `audit`
--
ALTER TABLE `audit`
ADD UNIQUE KEY `id` (`id`),
ADD KEY `user` (`user`);

--
-- Indexes for table `ballots`
--
ALTER TABLE `ballots`
ADD PRIMARY KEY (`id`);

--
-- Indexes for table `elections`
--
ALTER TABLE `elections`
ADD PRIMARY KEY (`id`);

--
-- Indexes for table `questions`
--
ALTER TABLE `questions`
ADD PRIMARY KEY (`id`),
ADD KEY `FK_questions_elections` (`election`);

--
-- Indexes for table `stages`
--
ALTER TABLE `stages`
ADD PRIMARY KEY (`id`),
ADD KEY `election` (`election`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `email` (`email`);

--
-- Indexes for table `voters`
--
ALTER TABLE `voters`
ADD PRIMARY KEY (`id`),
ADD KEY `email` (`email`),
ADD KEY `FK__elections` (`election`);

--
-- Indexes for table `votes`
--
ALTER TABLE `votes`
ADD KEY `ballot` (`ballot`),
ADD KEY `question` (`question`) USING BTREE,
ADD KEY `election` (`election`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `audit`
--
ALTER TABLE `audit`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=95;
--
-- AUTO_INCREMENT for table `elections`
--
ALTER TABLE `elections`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Election ID', AUTO_INCREMENT=27;
--
-- AUTO_INCREMENT for table `questions`
--
ALTER TABLE `questions`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
--
-- AUTO_INCREMENT for table `stages`
--
ALTER TABLE `stages`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'User ID', AUTO_INCREMENT=19;
--
-- AUTO_INCREMENT for table `voters`
--
ALTER TABLE `voters`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=920;
--
-- Constraints for dumped tables
--

--
-- Constraints for table `access`
--
ALTER TABLE `access`
ADD CONSTRAINT `FK_access_elections` FOREIGN KEY (`election`) REFERENCES `elections` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `FK_access_users` FOREIGN KEY (`user`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `audit`
--
ALTER TABLE `audit`
ADD CONSTRAINT `FK_audit_users` FOREIGN KEY (`user`) REFERENCES `users` (`id`);

--
-- Constraints for table `questions`
--
ALTER TABLE `questions`
ADD CONSTRAINT `FK_questions_elections` FOREIGN KEY (`election`) REFERENCES `elections` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `stages`
--
ALTER TABLE `stages`
ADD CONSTRAINT `stages_ibfk_1` FOREIGN KEY (`election`) REFERENCES `elections` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `voters`
--
ALTER TABLE `voters`
ADD CONSTRAINT `FK__elections` FOREIGN KEY (`election`) REFERENCES `elections` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `votes`
--
ALTER TABLE `votes`
ADD CONSTRAINT `votes_ibfk_2` FOREIGN KEY (`ballot`) REFERENCES `ballots` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `votes_ibfk_3` FOREIGN KEY (`election`) REFERENCES `elections` (`id`);

0 comments on commit a0964b1

Please sign in to comment.