diff --git a/database/schema.sql b/database/schema.sql index d8fefd9e..82e59e64 100644 --- a/database/schema.sql +++ b/database/schema.sql @@ -1,5 +1,5 @@ -- MySQL Script generated by MySQL Workbench --- Čt 21. leden 2016, 01:17:14 CET +-- Út 26. leden 2016, 21:33:51 CET -- Model: New Model Version: 1.0 -- MySQL Workbench Forward Engineering @@ -33,7 +33,7 @@ COMMENT = 'Table with users who are allowed to log into system'; -- Table `modules` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `modules` ( - `handler` VARCHAR(64) NOT NULL, + `handler` VARCHAR(255) NOT NULL, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `name` VARCHAR(64) NOT NULL, `description` TEXT NULL DEFAULT NULL, @@ -46,11 +46,11 @@ ENGINE = InnoDB; -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `files` ( `id` INT NOT NULL, - `user_id` INT NOT NULL, + `user_id` INT NOT NULL COMMENT 'User, who uploaded this file', `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.', + `mime_type` VARCHAR(64) NOT NULL COMMENT 'MIME type of uploaded file', PRIMARY KEY (`id`), INDEX `fk_file_user1_idx` (`user_id` ASC), CONSTRAINT `fk_file_user1` @@ -68,18 +68,18 @@ COMMENT = 'Table containing files which were uploaded into system.'; CREATE TABLE IF NOT EXISTS `contents` ( `id` INT NOT NULL, `user_id` INT NOT NULL, - `module_handler` VARCHAR(64) NOT NULL, - `title_photo` INT NULL DEFAULT NULL, + `module_handler` VARCHAR(255) NOT 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, + `published_from` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `published_to` TIMESTAMP NULL DEFAULT NULL, + `title_photo` INT NULL DEFAULT NULL, + `title` VARCHAR(64) NOT NULL, + `url` VARCHAR(64) 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, + `module_settings` TEXT NULL COMMENT 'JSON serialized object passed as settings to the module.', `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), @@ -142,7 +142,7 @@ COMMENT = 'Table for holding history of changes on some content.'; -- Table `widget_types` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `widget_types` ( - `handler` VARCHAR(64) NOT NULL COMMENT 'Class wich handles everything about this widget type', + `handler` VARCHAR(255) 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`)) @@ -155,9 +155,10 @@ COMMENT = 'Widget type table contains information about all installed widgets. T -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `widgets` ( `id` INT NOT NULL, - `widget_type_handler` VARCHAR(64) NOT NULL, + `widget_type_handler` VARCHAR(255) NOT NULL, `user_id` INT NOT NULL COMMENT 'User ID who created this widget', `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, `settings` TEXT NOT NULL COMMENT 'JSON serialized values used for initializing given widget.', `description` MEDIUMTEXT NULL, @@ -218,20 +219,40 @@ CREATE TABLE IF NOT EXISTS `widget_in_widget_area` ( ENGINE = InnoDB; +-- ----------------------------------------------------- +-- Table `custom_field_types` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `custom_field_types` ( + `id` INT NOT NULL, + `name` VARCHAR(64) NOT NULL COMMENT 'Name of custom field. Given as a translation string (e.g. as dir/section.translation)', + `handler` VARCHAR(255) NOT NULL COMMENT 'Class for handling this type of custom field', + PRIMARY KEY (`id`), + UNIQUE INDEX `name_UNIQUE` (`name` ASC), + UNIQUE INDEX `handler_UNIQUE` (`handler` ASC)) +ENGINE = InnoDB +COMMENT = 'List of all custom field types.'; + + -- ----------------------------------------------------- -- Table `custom_fields` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `custom_fields` ( `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, + `name` VARCHAR(128) NOT NULL, + `type_id` INT NOT NULL COMMENT 'Foreign key to custom_field_types table', + `description` MEDIUMTEXT NULL DEFAULT NULL COMMENT 'Description used for detailed information about meaning of given custom field', + `default_value` TEXT NULL DEFAULT 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`)) + PRIMARY KEY (`id`), + INDEX `fk_custom_fields_custom_field_types1_idx` (`type_id` ASC), + CONSTRAINT `fk_custom_fields_custom_field_types1` + FOREIGN KEY (`type_id`) + REFERENCES `custom_field_types` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE) ENGINE = InnoDB COMMENT = 'List of all custom fields which may be used for extending some part of content on webpage'; @@ -259,32 +280,12 @@ CREATE TABLE IF NOT EXISTS `user_has_custom_field` ( ENGINE = InnoDB; --- ----------------------------------------------------- --- Table `custom_field_types` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `custom_field_types` ( - `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 `custom_fields` (`id`) - ON DELETE RESTRICT - ON UPDATE NO ACTION) -ENGINE = InnoDB -COMMENT = 'List of all custom field types.'; - - -- ----------------------------------------------------- -- Table `module_has_custom_field` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `module_has_custom_field` ( - `module_handler` VARCHAR(64) NOT NULL, + `module_handler` VARCHAR(255) 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), @@ -298,7 +299,8 @@ CREATE TABLE IF NOT EXISTS `module_has_custom_field` ( REFERENCES `custom_fields` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION) -ENGINE = InnoDB; +ENGINE = InnoDB +COMMENT = 'Table used for assigning different custom fields to different modules. This table does not hold information about any configuration nor values of custom fields. Value is stored in content_has_custom_fields table.'; -- ----------------------------------------------------- @@ -306,7 +308,8 @@ ENGINE = InnoDB; -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `action_log_types` ( `id` INT NOT NULL, - `name` VARCHAR(45) NULL, + `name` VARCHAR(128) NOT NULL, + `value` VARCHAR(128) NOT NULL COMMENT 'Log content - represented as translation string.', PRIMARY KEY (`id`)) ENGINE = InnoDB COMMENT = 'List of all types which can be logged.'; @@ -320,7 +323,7 @@ CREATE TABLE IF NOT EXISTS `action_log` ( `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, ...', + `parameters` MEDIUMTEXT NULL DEFAULT NULL COMMENT 'JSON serialized array/object passed into translation.', PRIMARY KEY (`id`), INDEX `fk_action_log_action_log_type1_idx` (`type_id` ASC), INDEX `fk_action_log_user1_idx` (`user_id` ASC), @@ -338,6 +341,29 @@ ENGINE = InnoDB COMMENT = 'This table contains log of all actions, which happened in administration.'; +-- ----------------------------------------------------- +-- Table `content_has_custom_fields` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `content_has_custom_fields` ( + `contents_id` INT NOT NULL, + `custom_field_id` INT NOT NULL, + `value` TEXT NULL, + PRIMARY KEY (`contents_id`, `custom_field_id`), + INDEX `fk_contents_has_custom_fields_custom_fields1_idx` (`custom_field_id` ASC), + INDEX `fk_contents_has_custom_fields_contents1_idx` (`contents_id` ASC), + CONSTRAINT `fk_contents_has_custom_fields_contents1` + FOREIGN KEY (`contents_id`) + REFERENCES `contents` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `fk_contents_has_custom_fields_custom_fields1` + FOREIGN KEY (`custom_field_id`) + REFERENCES `custom_fields` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + + SET SQL_MODE=@OLD_SQL_MODE; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;