aboutsummaryrefslogtreecommitdiffstats
path: root/core/db/database.sql
blob: 172fb3a127d7388963aa32d282863a2ff83a6eeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
-- =============================================================================
-- Internal information table for migrations
-- =============================================================================
CREATE TABLE `migration` (`schema_version` smallint(4) NOT NULL)
	ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `migration` (`schema_version`) VALUES (6);

-- =============================================================================
-- Table structure for category entities
-- =============================================================================
CREATE TABLE `category` (
	`id` tinyint(3) UNSIGNED NOT NULL AUTO_INCREMENT,
	`time_insert` datetime NOT NULL,
	`time_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
	`parent` tinyint(3) UNSIGNED DEFAULT NULL,
	`slug` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
	`name` varchar(100) NOT NULL,
	`body` text NOT NULL,
	`argv` varchar(250) DEFAULT NULL,
	PRIMARY KEY (`id`),
	UNIQUE KEY `time_insert` (`time_insert`),
	UNIQUE KEY `slug` (`slug`),
	KEY `category_parent` (`parent`),
	FULLTEXT KEY `search` (`name`, `body`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- =============================================================================
-- Table structure for page entities
-- =============================================================================
CREATE TABLE `page` (
	`id` smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT,
	`time_insert` datetime NOT NULL,
	`time_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
	`user` tinyint(3) UNSIGNED NOT NULL,
	`slug` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
	`name` varchar(100) NOT NULL,
	`body` text NOT NULL,
	`argv` varchar(250) DEFAULT NULL,
	PRIMARY KEY (`id`),
	UNIQUE KEY `time_insert` (`time_insert`),
	UNIQUE KEY `slug` (`slug`),
	KEY `page_user` (`user`),
	FULLTEXT KEY `search` (`name`, `body`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- =============================================================================
-- Table structure for post entities
-- =============================================================================
CREATE TABLE `post` (
	`id` smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT,
	`time_insert` datetime NOT NULL,
	`time_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
	`user` tinyint(3) UNSIGNED NOT NULL,
	`category` tinyint(3) UNSIGNED DEFAULT NULL,
	`slug` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
	`name` varchar(100) NOT NULL,
	`body` text NOT NULL,
	`argv` varchar(250) DEFAULT NULL,
	PRIMARY KEY (`id`),
	UNIQUE KEY `time_insert` (`time_insert`),
	UNIQUE KEY `slug` (`slug`),
	KEY `post_user` (`user`),
	KEY `post_category` (`category`),
	FULLTEXT KEY `search` (`name`, `body`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- =============================================================================
-- Table structure for user entities
-- =============================================================================
CREATE TABLE `user` (
	`id` tinyint(3) UNSIGNED NOT NULL AUTO_INCREMENT,
	`time_insert` datetime NOT NULL,
	`time_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
	`slug` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
	`username` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
	`password` char(64) CHARACTER SET latin1 DEFAULT NULL,
	`fullname` varchar(40) NOT NULL,
	`mailaddr` varchar(60) NOT NULL,
	`body` text NOT NULL,
	`argv` varchar(250) DEFAULT NULL,
	PRIMARY KEY (`id`),
	UNIQUE KEY `time_insert` (`time_insert`),
	UNIQUE KEY `slug` (`slug`),
	UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- =============================================================================
-- Add foreign keys for entity relationships
-- =============================================================================
ALTER TABLE `category` ADD CONSTRAINT `category_parent` FOREIGN KEY (`parent`)
	REFERENCES `category` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;
ALTER TABLE `page` ADD CONSTRAINT `page_user` FOREIGN KEY (`user`)
	REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `post` ADD CONSTRAINT `post_user` FOREIGN KEY (`user`)
	REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `post` ADD CONSTRAINT `post_category` FOREIGN KEY (`category`)
	REFERENCES `category` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- =============================================================================
-- Insert some demo data
-- =============================================================================
INSERT INTO `user` (`id`, `time_insert`, `time_update`, `slug`, `username`, `password`, `fullname`, `mailaddr`, `body`, `argv`) VALUES
(1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'change-me', 'ChangeMe', '$2y$10$jH48L1K1y9dB303aI2biN.ob0biZDuUbMxPKadi3wDqOIxj6yNT6K', 'John Doe', 'mail@example.org', 'Describe yourself.', NULL);
INSERT INTO `page` (`id`, `time_insert`, `time_update`, `user`, `slug`, `name`, `body`, `argv`) VALUES
(1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 1, 'example-page', 'Example Page', 'OK. You discovered that there is also a page functionality. But what is the difference between a **page** and a **post**? This is simple: There is not really much difference. But you can style posts and pages within the themes CSS completely independent from each other. For example, use **pages** for things like your imprint, your terms of use, your FAQ or other stuff. And **posts** for your main blog posts. A **page** (and also a **user**) has exactly the same functionality as already described within the [first post]({POST[1]})! 8)', NULL);
INSERT INTO `post` (`id`, `time_insert`, `time_update`, `user`, `slug`, `name`, `body`, `argv`) VALUES
(1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 1, 'hello-world', 'Hello World!', 'Hello! This is the automatically generated first post on your new blog installation. You can type [Markdown](https://daringfireball.net/projects/markdown/) plaintext into the editor to format your content like you want.\r\n\r\nIn this post you can see several examples to [format your content with Markdown](https://daringfireball.net/projects/markdown/syntax) and with the *special codes* provided by this blog application. After you are familiar with the text formatting and done with the exploration of your new blog application, you can delete this post and create your own one. 😃\r\n\r\n![Demo image: Computer Guy (Public Domain)]({FILE[\"image/content/computer-guy-public-domain.svg\"]})\r\n\r\n## Dynamic internal URLs for items\r\nIf you want to link an item, please do not put the URL to the item hardcoded into your content! What if you want to change your sites address (or the base directory) in the future? Then you have to change all internal links in your content. This is not cool!\r\n\r\nTherefore, you can use the following code **without spaces between the braces** by knowing the unique ID of an item to link it dynamically:\r\n\r\n1. Example: `{ POST[1] }`  \r\n{POST[1]}\r\n\r\n2. Example: `{ PAGE[1] }`  \r\n{PAGE[1]}\r\n\r\n3. Example: `{ USER[1] }`  \r\n{USER[1]}\r\n\r\n## Dynamic internal URLs for other resources\r\nThis also applies to any other resource that exists in the blog system and that you want to link to! You can link any other resource dynamically either relative to your base directory or relative to your resource directory (`/rsrc/`) for static files:\r\n\r\n* Example: `{ BASE[\"foo/bar/\"] }`  \r\n{BASE[\"foo/bar/\"]}\r\n\r\n* Example: `{ FILE[\"foo/bar/\"] }`  \r\n{FILE[\"foo/bar/\"]}', NULL);