CREATE DATABASE `colsecor_play` charset=utf8;

GRANT ALL PRIVILEGES ON `colsecor_play`.* TO 'colsecor'@'localhost' IDENTIFIED BY 'c0ls3c0r_pl4y';

GRANT SELECT ON `colsecor_play`.`users` TO 'exportador'@'localhost' IDENTIFIED BY '3xp0rt4d0r';

USE `colsecor_play`;

CREATE TABLE `users` (
	`uid`				int(11)			auto_increment,
	`datetime`			datetime		NOT NULL default '0000-00-00 00:00:00',
	`user`				int(11)			NOT NULL default 0,
	`username`			varchar(50)		NOT NULL default '',
	`password`			varchar(50)		NOT NULL default '',
	`first_name`		varchar(50)		NOT NULL default '',
	`last_name` 		varchar(50)		NOT NULL default '',
	`email`				varchar(255)	NOT NULL default '',
	`tel`				varchar(30)		NOT NULL default '',
	`dni`				varchar(20)		NOT NULL default '',
	`plan`				varchar(30)		NOT NULL default '',
	`active`			int(1)			NOT NULL default 1,
	PRIMARY KEY (`uid`)
);

CREATE TABLE `groups` (
	`uid`				int(11)			auto_increment,
	`datetime`			datetime		NOT NULL default '0000-00-00 00:00:00',
	`user`				int(11)			NOT NULL default 0,
	`name`				varchar(100)	NOT NULL default '',
	`active`			int(1)			NOT NULL default 1,
	PRIMARY KEY (`uid`)
);

CREATE TABLE `user_groups` (
	`uid`				int(11)			auto_increment,
	`datetime`			datetime		NOT NULL default '0000-00-00 00:00:00',
	`user`				int(11)			NOT NULL default 0,
	`user_id`			int(11)			NOT NULL default 0,
	`group_id`			int(11)			NOT NULL default 0,
	`active`			int(1)			NOT NULL default 1,
	PRIMARY KEY (`uid`)
);

CREATE TABLE `comments` (
	`uid`				int(11)			NOT NULL auto_increment,
	`datetime`			datetime		NOT NULL default '0000-00-00 00:00:00',
	`item`				varchar(255)	NOT NULL default '',
	`user`				varchar(11)		NOT NULL default '0',
	`comment`			blob,
	`group`				int(11)			NOT NULL,
	`active`			int(1)			NOT NULL default 1,
	PRIMARY KEY (`uid`)
);

CREATE TABLE `functions` (
	`uid`				int(11)			auto_increment,
	`function`			varchar(50)		NOT NULL default '',
	`name`				varchar(255)	NOT NULL default '',
	`category`			varchar(50)		NOT NULL default '',
	PRIMARY KEY (`uid`)
);

CREATE TABLE `group_functions` (
	`uid`				int(11)			auto_increment,
	`function`			varchar(50)		NOT NULL default '',
	`group`				int(11)			NOT NULL default 0,
	PRIMARY KEY(`uid`)
);

INSERT INTO `users` (`datetime`, `username`, `password`, `first_name`, `last_name`, `active`) VALUES(NOW(), 'admin', '21232f297a57a5a743894a0e4a801fc3', 'Admin', 'User', 1);
INSERT INTO `groups` (`datetime`, `user`, `name`) VALUES(NOW(), 1, 'Admin');
INSERT INTO `user_groups` (`datetime`, `user`, `user_id`, `group_id`, `active`) VALUES(NOW(), 1, 1, 1, 1);
INSERT INTO `functions` (`function`, `name`, `category`) VALUES('channel_list', 'Home Page', 'General');
INSERT INTO `functions` (`function`, `name`, `category`) VALUES('admin_menu', 'Admin Menu', 'Admin');
INSERT INTO `functions` (`function`, `name`, `category`) VALUES('admin_users', 'User Administration', 'Admin');
INSERT INTO `group_functions` (`function`, `group`) VALUES('channel_list', 1);
INSERT INTO `group_functions` (`function`, `group`) VALUES('admin_menu', 1);
INSERT INTO `group_functions` (`function`, `group`) VALUES('admin_users', 1);

CREATE TABLE `channels`(
	`uid` 				int(11) 		auto_increment,
	`datetime` 			datetime 		NOT NULL default "0000-00-00 00:00:00",
	`user` 				int(11) 		NOT NULL default 0,
	`name` 				varchar(255) 	NOT NULL default "",
	`description` 		varchar(1000) 	NOT NULL default "",
	`supplier_id` 		int(11) 		NOT NULL default 0,
	`logo_url` 			varchar(255) 	NOT NULL default "",
	`active`			int(1)			NOT NULL default 1,
PRIMARY KEY (`uid`));

CREATE TABLE `suppliers`(
	`uid` 				int(11) 			auto_increment,
	`datetime` 			datetime 			NOT NULL default "0000-00-00 00:00:00",
	`user` 				int(11) 			NOT NULL default 0,
	`company` 			varchar(255) 		NOT NULL default "",
	`contact_person` 	varchar(255) 		NOT NULL default "",
	`contact_number` 	varchar(255) 		NOT NULL default "",
	`user_id` 			int(11) 			NOT NULL default 0,
	`active`			int(1)				NOT NULL default 1,
PRIMARY KEY (`uid`));

CREATE TABLE `logos`(
	`uid` 				int(11) 			auto_increment,
	`datetime` 			datetime 			NOT NULL default "0000-00-00 00:00:00",
	`user` 				int(11) 			NOT NULL default 0,
	`channel_id` 		int(11) 			NOT NULL default 0,
	`name` 				varchar(255) 		NOT NULL default "",
	`type` 				varchar(255) 		NOT NULL default "",
	`url` 				varchar(255) 		NOT NULL default "",
	`width`				decimal (10,2) 		NOT NULL default 0,
	`height`			decimal (10,2) 		NOT NULL default 0,
	`active`			int(1)				NOT NULL default 1,
PRIMARY KEY (`uid`));

CREATE TABLE `slider_photographs`(
	`uid` 				int(11) 			auto_increment,
	`datetime` 			datetime 			NOT NULL default "0000-00-00 00:00:00",
	`user` 				int(11) 			NOT NULL default 0,
	`name` 				varchar(255) 		NOT NULL default "",
	`type` 				varchar(255) 		NOT NULL default "",
	`url` 				varchar(255) 		NOT NULL default "",
	`active`			int(1)				NOT NULL default 1,
PRIMARY KEY (`uid`));

CREATE TABLE `most_seen_contents`(
	`uid` 				int(11) 			auto_increment,
	`datetime` 			datetime 			NOT NULL default "0000-00-00 00:00:00",
	`user` 				int(11) 			NOT NULL default 0,
	`name` 				varchar(255) 		NOT NULL default "",
    `description` 		varchar(255) 		NOT NULL default "",
	`type` 				varchar(255) 		NOT NULL default "",
	`url` 				varchar(255) 		NOT NULL default "",
    `channel` 			int(11) 			NOT NULL default 0,
	`active`			int(1)				NOT NULL default 1,
PRIMARY KEY (`uid`));

CREATE TABLE `new_releases`(
	`uid` 				int(11) 			auto_increment,
	`datetime` 			datetime 			NOT NULL default "0000-00-00 00:00:00",
	`user` 				int(11) 			NOT NULL default 0,
	`name` 				varchar(255) 		NOT NULL default "",
    `description` 		varchar(255) 		NOT NULL default "",
	`type` 				varchar(255) 		NOT NULL default "",
	`url` 				varchar(255) 		NOT NULL default "",
    `channel` 			int(11) 			NOT NULL default 0,
	`active`			int(1)				NOT NULL default 1,
PRIMARY KEY (`uid`));

CREATE TABLE `colsecor_contents`(
	`uid` 					int(11) 			auto_increment,
	`datetime` 				datetime 			NOT NULL default "0000-00-00 00:00:00",
	`user` 					int(11) 			NOT NULL default 0,
	`name` 					varchar(255) 		NOT NULL default "",
	`short_description` 	varchar(255) 		NOT NULL default "",
	`description` 			varchar(255) 		NOT NULL default "",
	`photo_url` 			varchar(255) 		NOT NULL default "",
    `trailer_url` 			varchar(255) 		NOT NULL default "",
    `trailer` 				int(1) 				NOT NULL default 0,
    `video_url` 			varchar(255) 		NOT NULL default "",
    `video` 				int(1) 				NOT NULL default 1,
	`start_date` 			date 				NOT NULL default "0000-00-00",
	`end_date` 				date 				NOT NULL default "0000-00-00",
	`start_time` 			time 				NOT NULL default "00:00:00",
	`end_time` 				time 				NOT NULL default "00:00:00",
	`active` 				int(1) 				NOT NULL default 1, 
PRIMARY KEY (`uid`));