diff --git a/create_db.sql b/create_db.sql deleted file mode 100644 index fca5483..0000000 --- a/create_db.sql +++ /dev/null @@ -1,58 +0,0 @@ --- phpMyAdmin SQL Dump --- version 4.5.1 --- http://www.phpmyadmin.net --- --- Host: 127.0.0.1 --- Generation Time: Jan 31, 2017 at 06:41 PM --- Server version: 10.1.19-MariaDB --- PHP Version: 7.0.13 - -SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; -SET time_zone = "+00:00"; - - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8mb4 */; - --- --- Database: `login` --- - --- -------------------------------------------------------- - --- --- Table structure for table `users` --- - -CREATE TABLE `users` ( - `userId` int(11) NOT NULL, - `userName` varchar(30) NOT NULL, - `userEmail` varchar(60) NOT NULL, - `userPass` varchar(255) NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- --- Indexes for dumped tables --- - --- --- Indexes for table `users` --- -ALTER TABLE `users` - ADD PRIMARY KEY (`userId`), - ADD UNIQUE KEY `userEmail` (`userEmail`); - --- --- AUTO_INCREMENT for dumped tables --- - --- --- AUTO_INCREMENT for table `users` --- -ALTER TABLE `users` - MODIFY `userId` int(11) NOT NULL AUTO_INCREMENT; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/sql/add_data.sql b/sql/add_data.sql new file mode 100644 index 0000000..538c241 --- /dev/null +++ b/sql/add_data.sql @@ -0,0 +1,12 @@ +-- Adds three dummy users to the db +-- +-- Author: Andreas Zweili +-- 2017-02-03 +-- MariaDB 10.0.27 + +use webshopdb; + +insert into users (userLogin, userPass, userEmail) + values ('demander','password','demander@example.com'), + ('provider','password','provider@example.com'), + ('admin','password','admin@example.com'); diff --git a/sql/create_db.sql b/sql/create_db.sql new file mode 100644 index 0000000..8d89f62 --- /dev/null +++ b/sql/create_db.sql @@ -0,0 +1,58 @@ +-- Creates the webshop DB +-- +-- Author: Andreas Zweili +-- 2017-02-03 +-- MariaDB 10.0.27 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + +create database if not exists webshopdb; +grant all on webshopdb.* to + 'webshop'@'localhost' + identified by 'password'; +flush privileges; + +use webshopdb; +CREATE TABLE if not exists `users` ( + `userId` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `userName` varchar(50) DEFAULT NULL, + `userFirstname` varchar(50) DEFAULT NULL, + `userLogin` varchar(50) NOT NULL, + `userEmail` varchar(60) NOT NULL UNIQUE KEY, + `userPass` varchar(255) NOT NULL, + `userIsAdmin` BOOL DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE if not exists `tags` ( + `tagId` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `text` varchar(50) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE if not exists `demands` ( + `demandId` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `text` text, + `piecesMin` int(11) NOT NULL, + `piecesMax` int(11) DEFAULT NULL, + `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `userId` int(11) NOT NULL, + `tagId` int(11) NOT NULL, + CONSTRAINT `fk_demands_userId` + FOREIGN KEY (userId) REFERENCES users (userId), + CONSTRAINT `fk_tagId` + FOREIGN KEY (tagId) REFERENCES tags (tagId) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE if not exists `offers` ( + `offerId` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `text` text CHARACTER SET utf8 COLLATE utf8_bin, + `price` float NOT NULL, + `pieces` int(11) NOT NULL, + `delivery` bool NOT NULL, + `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `userId` int(11) NOT NULL, + CONSTRAINT `fk_offers_userId` + FOREIGN KEY (userId) REFERENCES users (userId) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + diff --git a/sql/remove_db.sql b/sql/remove_db.sql new file mode 100644 index 0000000..a1635af --- /dev/null +++ b/sql/remove_db.sql @@ -0,0 +1,8 @@ +-- Removes the DB and its user +-- +-- Author: Andreas Zweili +-- 2017-02-03 +-- MariaDB 10.0.27 + +drop database if exists webshopdb; +drop user webshop@localhost;