Skip to content

Commit 00ccf08

Browse files
author
Kim Rowan
committed
Add MySQL directory with db schema and seed data
1 parent df12c1a commit 00ccf08

File tree

2 files changed

+161
-0
lines changed

2 files changed

+161
-0
lines changed

Diff for: MySQL/database/blogSchema.sql

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
SET SESSION storage_engine = "InnoDB";
2+
3+
DROP DATABASE IF EXISTS demo_blog;
4+
CREATE DATABASE demo_blog;
5+
6+
USE demo_blog;
7+
ALTER DATABASE demo_blog CHARACTER SET "utf8";
8+
9+
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON `demo_blog`.* TO 'Tester'@'localhost' IDENTIFIED BY 'queries';
10+
11+
DROP TABLE IF EXISTS post;
12+
CREATE TABLE post (
13+
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
14+
author_id INT NOT NULL REFERENCES author(id),
15+
slug VARCHAR(100) NOT NULL UNIQUE,
16+
title VARCHAR(400) NOT NULL,
17+
content MEDIUMTEXT NOT NULL,
18+
published DATETIME NOT NULL,
19+
created DATETIME NOT NULL,
20+
updated TIMESTAMP NOT NULL,
21+
KEY (published)
22+
);
23+
24+
DROP TABLE IF EXISTS author;
25+
CREATE TABLE author (
26+
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
27+
username VARCHAR(100) NOT NULL UNIQUE,
28+
name VARCHAR(100) NOT NULL
29+
);
30+
31+
DROP TABLE IF EXISTS tag;
32+
CREATE TABLE tag (
33+
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
34+
name VARCHAR(100) NOT NULL
35+
);
36+
37+
DROP TABLE IF EXISTS post_tag;
38+
CREATE TABLE post_tag (
39+
post_id INT NOT NULL REFERENCES post(id),
40+
tag_id INT NOT NULL REFERENCES tag(id)
41+
);
42+
43+
DROP TABLE IF EXISTS category;
44+
CREATE TABLE category (
45+
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
46+
parent_id INT,
47+
name VARCHAR(100) NOT NULL
48+
);
49+
50+
DROP TABLE IF EXISTS post_category;
51+
CREATE TABLE post_category (
52+
post_id INT NOT NULL REFERENCES post(id),
53+
category_id INT NOT NULL REFERENCES category(id)
54+
);

Diff for: MySQL/database/seed_data.sql

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Use this file to load in some seed data.
3+
*
4+
* $ mysql -u root -p blog_demo < seed_data.sql
5+
*
6+
*/
7+
8+
/* Enable deletion of rows with foreign key constraints by disabled checks */
9+
10+
SET foreign_key_checks = 0;
11+
12+
13+
/* Delete all Tag records then re-load sample data */
14+
15+
TRUNCATE TABLE `tag`;
16+
17+
INSERT INTO `tag` (id, `name`) VALUES
18+
(1, 'PHP'),
19+
(2, 'Quality Assurance'),
20+
(3, 'MySQL'),
21+
(4, 'php|tek'),
22+
(5, 'Arrays'),
23+
(6, 'PHPUnit'),
24+
(7, 'Refactoring'),
25+
(8, 'Tools'),
26+
(9, 'Build Process'),
27+
(10, 'Deployment'),
28+
(11, 'Integration'),
29+
(12, 'dpc12'),
30+
(13, 'PHPDocumentor'),
31+
(14, 'Security'),
32+
(15, 'Design Patterns'),
33+
(16, 'phpnw11'),
34+
(17, 'dpc11'),
35+
(18, 'Webservices'),
36+
(19, 'Optimisation')
37+
;
38+
39+
40+
/* Delete all author records then re-load sample data */
41+
42+
TRUNCATE TABLE `author`;
43+
44+
INSERT INTO `author` (`id`, `name`, username ) VALUES
45+
(1, 'Joe Blogs','blowFish'),
46+
(2, 'Ann Other','blog_queen'),
47+
(3, 'John Smith','smithie'),
48+
(4, 'Howard Jones','solo')
49+
;
50+
51+
52+
/* Delete all Category records then re-load sample data */
53+
54+
TRUNCATE TABLE `category`;
55+
56+
INSERT INTO `category` (`id`, `parent_id`, `name`) VALUES
57+
(8, NULL, 'PHP'),
58+
(9, 8, 'Quality Assurance'),
59+
(10, NULL, 'Databases'),
60+
(11, 10, 'MySQL'),
61+
(12, 9, 'Test Driven Development'),
62+
(13, 8, 'Object Orientation'),
63+
(14, 13, 'Design Patterns'),
64+
(15, 10, 'CouchDB'),
65+
(16, 8, 'Frameworks'),
66+
(17, 16, 'Zend Framework'),
67+
(18, 16, 'Symfony'),
68+
(19, 16, 'Symfony2'),
69+
(20, 8, 'Webservices')
70+
;
71+
72+
/* Delete all post records then re-load sample data */
73+
74+
TRUNCATE TABLE `post`;
75+
76+
INSERT INTO `post` (author_id, `slug`, title, `content`, published, created, updated) VALUES
77+
(1,
78+
'mysql-queries-the-right-way',
79+
'MySQL queries - the right way',
80+
'Sweet jelly beans bonbon jelly beans dragée. Lollipop I love marshmallow chocolate faworki gingerbread jelly-o icing faworki. Lollipop jelly beans chupa chups fruitcake. Apple pie cheesecake tart. Gummi bears sugar plum soufflé chupa chups. Tiramisu brownie macaroon I love soufflé carrot cake chocolate bar. I love chocolate I love lollipop. Pastry tootsie roll cupcake lollipop dragée marzipan. Tootsie roll liquorice macaroon lollipop gingerbread jelly beans. Soufflé applicake tiramisu sweet roll liquorice lemon drops toffee macaroon. Ice cream oat cake ice cream oat cake. Muffin cookie tiramisu cheesecake danish gingerbread biscuit. I love marshmallow candy sugar plum fruitcake gingerbread chocolate oat cake. Chocolate bar I love tart liquorice halvah pastry wypas I love macaroon. Dragée sweet lemon drops jelly beans wypas cake. Tiramisu danish jelly-o cheesecake topping pie candy. Cotton candy soufflé powder chocolate I love tart brownie. Chocolate bar cake pastry I love chocolate cake topping marshmallow. Croissant jelly beans topping dragée dessert marshmallow gummies biscuit I love. I love icing I love jelly donut topping fruitcake gingerbread topping. Gingerbread dragée bear claw I love bear claw cookie pie brownie I love. Tart dessert bonbon faworki sesame snaps. Bonbon cupcake cookie. Fruitcake toffee I love I love bonbon biscuit jujubes candy canes I love. Halvah cotton candy sugar plum bear claw sesame snaps jujubes carrot cake soufflé muffin. Sugar plum oat cake I love cupcake.',
81+
'08-05-2011 17:54:02',
82+
'08-04-2011 23:04:52',
83+
'00-00-0000 00:00:00')
84+
;
85+
86+
87+
/* Delete all post_category records then re-load sample data */
88+
89+
TRUNCATE TABLE `post_category`;
90+
91+
INSERT INTO post_category (post_id, category_id) VALUES
92+
(1, 11)
93+
;
94+
95+
/* Delete all post_tag records then re-load sample data */
96+
97+
TRUNCATE TABLE `post_tag`;
98+
99+
INSERT INTO post_tag (post_id, tag_id) VALUES
100+
(1, 3),
101+
(1, 19)
102+
;
103+
104+
105+
/* Reenable foreign key constrain checks in MySQL */
106+
107+
SET foreign_key_checks = 1;

0 commit comments

Comments
 (0)