add sql files to create DB

This commit is contained in:
Andreas Zweili 2017-02-03 17:37:36 +01:00
parent 077fe49191
commit f12649cfc2
4 changed files with 78 additions and 58 deletions

View File

@ -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 */;

12
sql/add_data.sql Normal file
View File

@ -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');

58
sql/create_db.sql Normal file
View File

@ -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;

8
sql/remove_db.sql Normal file
View File

@ -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;