FEATURE: add database schema

This commit is contained in:
Michal Kváček
2016-01-20 19:52:13 +01:00
parent 6fd00cc993
commit d08c7ab744
+348
View File
@@ -0,0 +1,348 @@
-- MySQL Script generated by MySQL Workbench
-- St 20. leden 2016, 19:50:50 CET
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Schema minicms
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema minicms
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `minicms` DEFAULT CHARACTER SET utf8 ;
USE `minicms` ;
-- -----------------------------------------------------
-- Table `minicms`.`user`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`user` (
`id` INT NOT NULL AUTO_INCREMENT,
`email` VARCHAR(64) NOT NULL COMMENT 'E-mail is used as a contact and also as a username',
`username` VARCHAR(64) NOT NULL,
`password` VARCHAR(128) NOT NULL COMMENT 'Password hash',
`remember_token` VARCHAR(128) NULL DEFAULT NULL COMMENT 'Token used for \"remember me\" feature',
`name` VARCHAR(128) NULL DEFAULT NULL,
`status` ENUM('deleted', 'blocked', 'active') NULL DEFAULT 'active' COMMENT 'Username can be used also for login. Default value is users email.',
PRIMARY KEY (`id`),
UNIQUE INDEX `email_UNIQUE` (`email` ASC))
ENGINE = InnoDB
COMMENT = 'Table with users who are allowed to log into system';
-- -----------------------------------------------------
-- Table `minicms`.`module`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`module` (
`handler` VARCHAR(64) NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`name` VARCHAR(64) NOT NULL,
`description` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`handler`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `minicms`.`file`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`file` (
`id` INT NOT NULL,
`user_id` INT NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`filename` VARCHAR(128) NOT NULL,
`sha256_hash` VARCHAR(64) NOT NULL COMMENT 'SHA hash of file content.',
`mime_type` VARCHAR(64) NOT NULL COMMENT 'User, who uploaded this file.',
PRIMARY KEY (`id`),
INDEX `fk_file_user1_idx` (`user_id` ASC),
CONSTRAINT `fk_file_user1`
FOREIGN KEY (`user_id`)
REFERENCES `minicms`.`user` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
COMMENT = 'Table containing files which were uploaded into system.';
-- -----------------------------------------------------
-- Table `minicms`.`content`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`content` (
`id` INT NOT NULL,
`user_id` INT NOT NULL,
`module_handler` VARCHAR(64) NOT NULL,
`title_photo` INT NULL DEFAULT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`title` VARCHAR(45) NOT NULL,
`url` VARCHAR(45) NOT NULL,
`meta_keywords` VARCHAR(128) NULL DEFAULT NULL,
`meta_description` MEDIUMTEXT NULL DEFAULT NULL,
`module_settings` TEXT NULL COMMENT 'JSON serialized object passed as settings to the module.',
`content` TEXT NULL DEFAULT NULL,
`published_from` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`published_to` TIMESTAMP NULL DEFAULT NULL,
`status` ENUM('deleted', 'draft', 'protected', 'public') NULL DEFAULT 'draft' COMMENT 'This photo is supposed to be displayed e.g. on list of all pages.',
PRIMARY KEY (`id`),
INDEX `fk_content_user1_idx` (`user_id` ASC),
INDEX `url` (`url` ASC),
FULLTEXT INDEX `content_fulltext` (`content` ASC),
UNIQUE INDEX `url_UNIQUE` (`url` ASC),
INDEX `fk_content_module1_idx` (`module_handler` ASC),
INDEX `fk_content_file1_idx` (`title_photo` ASC),
CONSTRAINT `fk_content_user1`
FOREIGN KEY (`user_id`)
REFERENCES `minicms`.`user` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_content_module1`
FOREIGN KEY (`module_handler`)
REFERENCES `minicms`.`module` (`handler`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_content_file1`
FOREIGN KEY (`title_photo`)
REFERENCES `minicms`.`file` (`id`)
ON DELETE SET NULL
ON UPDATE CASCADE)
ENGINE = InnoDB
COMMENT = 'Table with all content pages.';
-- -----------------------------------------------------
-- Table `minicms`.`content_history`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`content_history` (
`id` INT NOT NULL,
`user_id` INT NOT NULL,
`content_id` INT NOT NULL,
`changed_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`edit_batch` VARCHAR(16) NOT NULL COMMENT 'This field holds identical values for all historical entries edited as one update.',
`column` VARCHAR(64) NOT NULL,
`new_value` TEXT NULL DEFAULT NULL,
`old_value` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `edit_batch` (`edit_batch` ASC),
INDEX `column` (`column` ASC),
INDEX `fk_content_history_users_idx` (`user_id` ASC),
INDEX `fk_content_history_content1_idx` (`content_id` ASC),
CONSTRAINT `fk_content_history_users`
FOREIGN KEY (`user_id`)
REFERENCES `minicms`.`user` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_content_history_content1`
FOREIGN KEY (`content_id`)
REFERENCES `minicms`.`content` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
COMMENT = 'Table for holding history of changes on some content.';
-- -----------------------------------------------------
-- Table `minicms`.`widget_type`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`widget_type` (
`handler` VARCHAR(64) NOT NULL COMMENT 'Class wich handles everything about this widget type',
`name` VARCHAR(64) NOT NULL COMMENT 'Name is used only in admin for better readability.',
`description` TEXT NULL DEFAULT NULL COMMENT 'This field also improves readability.',
PRIMARY KEY (`handler`))
ENGINE = InnoDB
COMMENT = 'Widget type table contains information about all installed widgets. This is something like \"class\" to widgets.';
-- -----------------------------------------------------
-- Table `minicms`.`widget`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`widget` (
`id` INT NOT NULL,
`widget_type_handler` VARCHAR(64) NOT NULL,
`user_id` INT NOT NULL COMMENT 'User ID who created this widget',
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`name` VARCHAR(64) NOT NULL,
`settings` TEXT NOT NULL COMMENT 'JSON serialized values used for initializing given widget.',
`description` MEDIUMTEXT NULL,
PRIMARY KEY (`id`),
INDEX `fk_widget_user1_idx` (`user_id` ASC),
INDEX `fk_widget_widget_type1_idx` (`widget_type_handler` ASC),
CONSTRAINT `fk_widget_user1`
FOREIGN KEY (`user_id`)
REFERENCES `minicms`.`user` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_widget_widget_type1`
FOREIGN KEY (`widget_type_handler`)
REFERENCES `minicms`.`widget_type` (`handler`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
COMMENT = 'Widget is a small piece of content, which can be inserted into widget area. Example of widgets: menu (with links), banner, some static html code. This table contains real \"instances\" of widgets.';
-- -----------------------------------------------------
-- Table `minicms`.`widget_area`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`widget_area` (
`id` INT NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`name` VARCHAR(64) NOT NULL COMMENT 'Used for user overview.',
`code` VARCHAR(32) NOT NULL COMMENT 'Value of this field is used for replacing placeholder text in templates with content of real widget area.',
`description` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `code_UNIQUE` (`code` ASC))
ENGINE = InnoDB
COMMENT = 'Widget area is container for widgets. This container is inserted into templates/content and populated by widgets.';
-- -----------------------------------------------------
-- Table `minicms`.`widget_in_widget_area`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`widget_in_widget_area` (
`widget_id` INT NOT NULL,
`widget_area_id` INT NOT NULL,
`position` INT NOT NULL COMMENT 'Which position should the widget take?',
PRIMARY KEY (`widget_id`, `widget_area_id`),
INDEX `fk_widget_has_widget_area_widget_area1_idx` (`widget_area_id` ASC),
INDEX `fk_widget_has_widget_area_widget1_idx` (`widget_id` ASC),
INDEX `position` (`position` ASC),
CONSTRAINT `fk_widget_has_widget_area_widget1`
FOREIGN KEY (`widget_id`)
REFERENCES `minicms`.`widget` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_widget_has_widget_area_widget_area1`
FOREIGN KEY (`widget_area_id`)
REFERENCES `minicms`.`widget_area` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `minicms`.`custom_field`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`custom_field` (
`id` INT NOT NULL,
`handler` VARCHAR(64) NOT NULL COMMENT 'Class name, which handles saving and retrieving given custom field.',
`name` VARCHAR(128) NULL,
`description` MEDIUMTEXT NULL,
`default_value` TEXT NULL,
`regexp` MEDIUMTEXT NULL DEFAULT NULL,
`min_length` INT(11) NULL DEFAULT NULL,
`max_length` INT(11) NULL DEFAULT NULL,
`required` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`))
ENGINE = InnoDB
COMMENT = 'List of all custom fields which may be used for extending some part of content on webpage';
-- -----------------------------------------------------
-- Table `minicms`.`user_has_custom_field`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`user_has_custom_field` (
`user_id` INT NOT NULL,
`custom_field_id` INT NOT NULL,
`value` TEXT NOT NULL,
PRIMARY KEY (`user_id`, `custom_field_id`),
INDEX `fk_user_has_custom_field_custom_field1_idx` (`custom_field_id` ASC),
INDEX `fk_user_has_custom_field_user1_idx` (`user_id` ASC),
CONSTRAINT `fk_user_has_custom_field_user1`
FOREIGN KEY (`user_id`)
REFERENCES `minicms`.`user` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_user_has_custom_field_custom_field1`
FOREIGN KEY (`custom_field_id`)
REFERENCES `minicms`.`custom_field` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `minicms`.`custom_field_type`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`custom_field_type` (
`id` INT NOT NULL,
`name` VARCHAR(45) NOT NULL,
`custom_field_id` INT NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `name_UNIQUE` (`name` ASC),
INDEX `fk_custom_field_type_custom_field1_idx` (`custom_field_id` ASC),
CONSTRAINT `fk_custom_field_type_custom_field1`
FOREIGN KEY (`custom_field_id`)
REFERENCES `minicms`.`custom_field` (`id`)
ON DELETE RESTRICT
ON UPDATE NO ACTION)
ENGINE = InnoDB
COMMENT = 'List of all custom field types.';
-- -----------------------------------------------------
-- Table `minicms`.`module_has_custom_field`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`module_has_custom_field` (
`module_handler` VARCHAR(64) NOT NULL,
`custom_field_id` INT NOT NULL,
`value` TEXT NOT NULL,
PRIMARY KEY (`module_handler`, `custom_field_id`),
INDEX `fk_module_has_custom_field_custom_field1_idx` (`custom_field_id` ASC),
INDEX `fk_module_has_custom_field_module1_idx` (`module_handler` ASC),
CONSTRAINT `fk_module_has_custom_field_module1`
FOREIGN KEY (`module_handler`)
REFERENCES `minicms`.`module` (`handler`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_module_has_custom_field_custom_field1`
FOREIGN KEY (`custom_field_id`)
REFERENCES `minicms`.`custom_field` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `minicms`.`action_log_type`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`action_log_type` (
`id` INT NOT NULL,
`name` VARCHAR(45) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB
COMMENT = 'List of all types which can be logged.';
-- -----------------------------------------------------
-- Table `minicms`.`action_log`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `minicms`.`action_log` (
`id` INT NOT NULL,
`type_id` INT NOT NULL,
`user_id` INT NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`item_id` INT(11) NULL DEFAULT NULL COMMENT 'ID of changed item. Item may be content, widget, custom field, ...',
PRIMARY KEY (`id`),
INDEX `fk_action_log_action_log_type1_idx` (`type_id` ASC),
INDEX `fk_action_log_user1_idx` (`user_id` ASC),
CONSTRAINT `fk_action_log_action_log_type1`
FOREIGN KEY (`type_id`)
REFERENCES `minicms`.`action_log_type` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_action_log_user1`
FOREIGN KEY (`user_id`)
REFERENCES `minicms`.`user` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
COMMENT = 'This table contains log of all actions, which happened in administration.';
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;