personal-website/database_schema.sql

113 lines
4.6 KiB
SQL

-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Aug 21, 2024 at 11:22 PM
-- Server version: 11.4.2-MariaDB
-- PHP Version: 8.3.10
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
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: `zdenekborovec`
--
-- --------------------------------------------------------
--
-- Table structure for table `blogposts`
--
CREATE TABLE IF NOT EXISTS `blogposts` (
`blogpost_id` uuid NOT NULL DEFAULT uuid() COMMENT 'uuid of the blogpost',
`readable_address` varchar(64) NOT NULL COMMENT 'Human-readable addressing alternative for an article. For example, blogpost with readable_address = "example" can be accessed by blog/article/example.',
`title` varchar(64) DEFAULT NULL COMMENT 'title of the blogpost',
`abstract` varchar(512) DEFAULT NULL COMMENT 'short version of the blogpost to be displayed as preview, usually the first paragraph of the real article.',
`content` text DEFAULT NULL COMMENT 'html for the article',
`date_posted` datetime NOT NULL DEFAULT current_timestamp() COMMENT 'Datetime at which the article was posted.',
`date_edited` datetime NOT NULL DEFAULT current_timestamp() COMMENT 'Timestamp at the lasted edit.',
PRIMARY KEY (`blogpost_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
--
-- Table structure for table `blogpost_comments`
--
CREATE TABLE IF NOT EXISTS `blogpost_comments` (
`comment_id` uuid NOT NULL DEFAULT uuid() COMMENT 'ID of the comment, PK.',
`parent_id` uuid DEFAULT NULL COMMENT 'If this is a response to a comment, this is the id of that parent comment.',
`blogpost_id` uuid NOT NULL COMMENT 'ID of the blogpost this comment is under.',
`poster_id` uuid DEFAULT NULL COMMENT ' ID of the user who posted this comment. ',
`timestamp` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Timestamp when the comment was posted.',
`content` mediumtext NOT NULL COMMENT 'Content of the comment. Stored as markdown.',
PRIMARY KEY (`comment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Comments on blogposts.';
-- --------------------------------------------------------
--
-- Table structure for table `blogpost_has_tag`
--
CREATE TABLE IF NOT EXISTS `blogpost_has_tag` (
`blogpost_id` uuid NOT NULL,
`tag_id` int(11) NOT NULL,
KEY `blogpost_id` (`blogpost_id`),
KEY `tag_id` (`tag_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
--
-- Table structure for table `blogpost_tags`
--
CREATE TABLE IF NOT EXISTS `blogpost_tags` (
`tag_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID of the tag, primary key.',
`name` varchar(32) NOT NULL COMMENT 'Name of the tag, will be displayed.',
`color` varchar(32) NOT NULL COMMENT 'CSS color string, will be displayed.',
PRIMARY KEY (`tag_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Tags that can be used to tag and filter blogposts.';
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`user_id` uuid NOT NULL DEFAULT uuid() COMMENT 'UUID of the user. Primary key.',
`username` varchar(64) NOT NULL COMMENT 'Display name of the user.',
`password` varchar(255) NOT NULL COMMENT 'password encrypted by password_hash().',
`created_at` datetime NOT NULL DEFAULT current_timestamp() COMMENT 'Timestamp at account creation.',
`permissions` bit(8) NOT NULL DEFAULT b'0' COMMENT 'Permission mask for the user. Rules (from left to right):\r\n0: Can post blogposts.\r\n1: reserved\r\n2: reserved\r\n3: reserved\r\n4: reserved\r\n5: reserved\r\n6: reserved\r\n7: reserved',
PRIMARY KEY (`user_id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Constraints for dumped tables
--
--
-- Constraints for table `blogpost_has_tag`
--
ALTER TABLE `blogpost_has_tag`
ADD CONSTRAINT `blogpost_has_tag_ibfk_1` FOREIGN KEY (`blogpost_id`) REFERENCES `blogposts` (`blogpost_id`),
ADD CONSTRAINT `blogpost_has_tag_ibfk_2` FOREIGN KEY (`tag_id`) REFERENCES `blogpost_tags` (`tag_id`);
COMMIT;
/*!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 */;