Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*SCRIPT DATABASE GENERATOR*/
- USE FATTO;
- /*CREATE TABLE GENRES*/
- DROP TABLE IF EXISTS `genres`;
- CREATE TABLE `genres` (
- `id_gr` int NOT NULL AUTO_INCREMENT COMMENT'idx',
- `name` varchar(50) NOT NULL COMMENT'the genre type ie. terror, comedy, etc)',
- `description` varchar(100) NOT NULL COMMENT'description of genre',
- KEY `idx_genres_id_gr` (`id_gr`) COMMENT'index',
- PRIMARY KEY (id_gr) COMMENT'unique key'
- )
- ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Contains the genre type:';
- ;
- /*CREATE TABLE GENRES*/
- DROP TABLE IF EXISTS `genres_audit`;
- CREATE TABLE `genres_audit` (
- `id_gr` int NOT NULL AUTO_INCREMENT COMMENT'idx',
- `name_old` varchar(50) NOT NULL COMMENT'the genre type ie. terror, comedy, etc)',
- `name_new` varchar(50) NOT NULL COMMENT'the genre type ie. terror, comedy, etc)',
- `description_old` varchar(100) NOT NULL COMMENT'description of genre',
- `description_new` varchar(100) NOT NULL COMMENT'description of genre',
- KEY `idx_genres_id_gr` (`id_gr`) COMMENT'index',
- PRIMARY KEY (id_gr) COMMENT'unique key'
- )
- ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Contains the genre type:';
- ;
- insert into `genres`(`name`, `description`) values('Ação','');
- insert into `genres`(`name`, `description`) values('Animação','');
- insert into `genres`(`name`, `description`) values('Aventura','');
- insert into `genres`(`name`, `description`) values('Cinema de arte','');
- insert into `genres`(`name`, `description`) values('Chanchada','');
- insert into `genres`(`name`, `description`) values('Cinema catástrofe','');
- insert into `genres`(`name`, `description`) values('Comédia','');
- insert into `genres`(`name`, `description`) values('Comédia romântica','');
- insert into `genres`(`name`, `description`) values('Comédia dramática','');
- insert into `genres`(`name`, `description`) values('Comédia de ação','');
- insert into `genres`(`name`, `description`) values('Cult','');
- insert into `genres`(`name`, `description`) values('Dança','');
- insert into `genres`(`name`, `description`) values('Documentários','');
- insert into `genres`(`name`, `description`) values('Drama','');
- insert into `genres`(`name`, `description`) values('Espionagem','');
- insert into `genres`(`name`, `description`) values('Erótico','');
- insert into `genres`(`name`, `description`) values('Fantasia','');
- insert into `genres`(`name`, `description`) values('Faroeste','');
- insert into `genres`(`name`, `description`) values('Ficção científica','');
- insert into `genres`(`name`, `description`) values('Series','');
- insert into `genres`(`name`, `description`) values('Guerra','');
- insert into `genres`(`name`, `description`) values('Machinima','');
- insert into `genres`(`name`, `description`) values('Masala','');
- insert into `genres`(`name`, `description`) values('Musical','');
- insert into `genres`(`name`, `description`) values('Filme noir','');
- insert into `genres`(`name`, `description`) values('Policial','');
- insert into `genres`(`name`, `description`) values('Pornochanchada','');
- insert into `genres`(`name`, `description`) values('Pornográfico','');
- insert into `genres`(`name`, `description`) values('Robologia','');
- insert into `genres`(`name`, `description`) values('Romance','');
- insert into `genres`(`name`, `description`) values('Seriado','');
- insert into `genres`(`name`, `description`) values('Suspense','');
- insert into `genres`(`name`, `description`) values('Terror','');
- insert into `genres`(`name`, `description`) values('Trash','');
- ==============================================================================================
- /*CREATE TABLE title basics*/
- DROP TABLE IF EXISTS `title.basics`;
- CREATE TABLE `title.basics` (
- `id_tb` int NOT NULL AUTO_INCREMENT COMMENT'idx',
- `tconst` varchar(10) NOT NULL COMMENT'alphanumeric unique identifier of the title',
- `titleType` varchar(50) NOT NULL COMMENT'the type/format of the title (e.g. movie, short, tvseries, tvepisode, video, etc)',
- `primaryTitle` varchar(100) NOT NULL COMMENT'the more popular title / the title used by the filmmakers on promotional materials at the point of release',
- `originalTitle` varchar(100) NOT NULL COMMENT'original title, in the original language',
- `isAdult` tinyint(1) NOT NULL COMMENT'0: non-adult title; 1: adult title',
- `startYear` smallint(4) NOT NULL COMMENT'represents the release year of a title. In the case of TV Series, it is the series start year.',
- `endYear` smallint(4) DEFAULT NULL COMMENT'TV Series end year. ‘\N’ for all other title types',
- `runtimeMinutes` int(5) NOT NULL COMMENT'primary runtime of the title, in minutes genre',
- `genres` SMALLINT COMMENT 'includes up to three genres associated with the title',
- KEY `idx_title.basics_id_tb` (`id_tb`) COMMENT'index',
- KEY `idx_title.basics_tconst` (`tconst`) COMMENT'index',
- PRIMARY KEY (tconst) COMMENT'unique key'
- )
- ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Contains the following information for titles:';
- ;
- ALTER TABLE `title.basics` ADD CONSTRAINT `fk_genre` FOREIGN KEY ( `genres` ) REFERENCES `genres` (`id_gr`);
- -------------------------------------------------------------------------------------------------
- /*CREATE TABLE title basics audit*/
- DROP TABLE IF EXISTS `title.basics.Audit`;
- CREATE TABLE `title.basics.Audit` (
- `id_tba` int NOT NULL AUTO_INCREMENT COMMENT'idx',
- `tconst` varchar(10) NOT NULL COMMENT'alphanumeric unique identifier of the title',
- `titleType_old` varchar(50) NOT NULL COMMENT'the type/format of the title (e.g. movie, short, tvseries, tvepisode, video, etc)',
- `titleType_new` varchar(50) NOT NULL COMMENT'the type/format of the title (e.g. movie, short, tvseries, tvepisode, video, etc)',
- `primaryTitle_old` varchar(100) NOT NULL COMMENT'the more popular title / the title used by the filmmakers on promotional materials at the point of release',
- `primaryTitle_new` varchar(100) NOT NULL COMMENT'the more popular title / the title used by the filmmakers on promotional materials at the point of release',
- `originalTitle_old` varchar(100) NOT NULL COMMENT'original title, in the original language',
- `originalTitle_new` varchar(100) NOT NULL COMMENT'original title, in the original language',
- `isAdult_old` tinyint(1) NOT NULL COMMENT'0: non-adult title; 1: adult title',
- `isAdult_new` tinyint(1) NOT NULL COMMENT'0: non-adult title; 1: adult title',
- `startYear_old` int(4) NOT NULL COMMENT'represents the release year of a title. In the case of TV Series, it is the series start year.',
- `startYear_new` int(4) NOT NULL COMMENT'represents the release year of a title. In the case of TV Series, it is the series start year.',
- `endYear_old` int(4) DEFAULT NULL COMMENT'TV Series end year. ‘\N’ for all other title types',
- `endYear_new` int(4) DEFAULT NULL COMMENT'TV Series end year. ‘\N’ for all other title types',
- `runtimeMinutes_old` int(5) NOT NULL COMMENT'primary runtime of the title, in minutes genre',
- `runtimeMinutes_new` int(5) NOT NULL COMMENT'primary runtime of the title, in minutes genre',
- `genres_old` smallint DEFAULT NULL COMMENT 'includes up to three genres associated with the title',
- `genres_new` smallint DEFAULT NULL COMMENT 'includes up to three genres associated with the title',
- `logged_user` nvarchar(50) COMMENT'user action',
- `oper_type` varchar(10) COMMENT'Operation type',
- `tstamp` datetime,
- KEY `idx_title.basics.Audit_id_tba` (`id_tba`) COMMENT'index',
- KEY `idx_title.basics.Audit_tconst` (`tconst`) COMMENT'index',
- PRIMARY KEY (tconst) COMMENT'unique key'
- )
- ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Contains the following information for titles:';
- ;
- ALTER TABLE `title.basics.Audit` ADD CONSTRAINT `fk_genre_old` FOREIGN KEY ( `genres_old` ) REFERENCES `genres` (`id_gr`);
- ALTER TABLE `title.basics.Audit` ADD CONSTRAINT `fk_genre_new` FOREIGN KEY ( `genres_new` ) REFERENCES `genres` (`id_gr`);
- -------------------------------------------------------------------------------------------------
- /*CREATE TABLE title episode*/
- DROP TABLE IF EXISTS `title.episode`;
- CREATE TABLE `title.episode`(
- `id_te` int NOT NULL AUTO_INCREMENT COMMENT'idx',
- `tconst` varchar(10) NOT NULL COMMENT'alphanumeric identifier of episode',
- `parentTconst` varchar(50) COMMENT'alphanumeric identifier of the parent TV Series',
- `seasonNumber` SMALLINT COMMENT'season number the episode belongs to',
- `episodeNumber` SMALLINT COMMENT'episode number of the tconst in the TV series',
- KEY `idx_title.episode_id_te` (`id_te`) COMMENT'index',
- KEY `idx_title.episode_tconst` (`tconst`) COMMENT'index',
- PRIMARY KEY (tconst) COMMENT'unique key'
- )
- ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT'Contains the tv episode information. Fields include'
- ;
- -------------------------------------------------------------------------------------------------
- /*CREATE TABLE title episode audit*/
- DROP TABLE IF EXISTS `title.episode.Audit`;
- CREATE TABLE `title.episode.Audit`(
- `id_tea` int NOT NULL AUTO_INCREMENT COMMENT'idx',
- `tconst` varchar(10) NOT NULL COMMENT'alphanumeric identifier of episode',
- `parentTconst_old` varchar(50) COMMENT'alphanumeric identifier of the parent TV Series',
- `parentTconst_new` varchar(50) COMMENT'alphanumeric identifier of the parent TV Series',
- `seasonNumber_old` SMALLINT COMMENT'season number the episode belongs to',
- `seasonNumber_new` SMALLINT COMMENT'season number the episode belongs to',
- `episodeNumber_old` SMALLINT COMMENT'episode number of the tconst in the TV series',
- `episodeNumber_new` SMALLINT COMMENT'episode number of the tconst in the TV series',
- `logged_user` nvarchar(50) COMMENT'user action',
- `oper_type` varchar(10) COMMENT'Operation type',
- `tstamp` datetime,
- KEY `idx_title.episode.Audit_id_tea` (`id_tea`) COMMENT'index',
- KEY `idx_title.episode.Audit_tconst` (`tconst`) COMMENT'index',
- PRIMARY KEY (tconst) COMMENT'unique key'
- )
- ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT'Contains the tv episode information. Fields include'
- ;
- -------------------------------------------------------------------------------------------------
- /*CREATE TABLE resources basics*/
- DROP TABLE IF EXISTS `resource.basics`;
- CREATE TABLE `resource.basics`(
- `id_rb` int NOT NULL AUTO_INCREMENT COMMENT'idx',
- `tconst` varchar(10) NOT NULL COMMENT'alphanumeric identifier basic',
- `url` varchar(100) COMMENT'Media URL',
- `poster` varchar(100) COMMENT'Poster URL',
- /*`views` bigint COMMENT'vews count',*/
- KEY `idx_resource.basics_id_rb` (`id_rb`) COMMENT'index',
- KEY `idx_tresource.basics_tconst` (`tconst`) COMMENT'index',
- PRIMARY KEY (tconst) COMMENT'unique key'
- )
- ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT'Contem os recursos para assistir'
- ;
- -------------------------------------------------------------------------------------------------
- /*CREATE TABLE resources basics audit*/
- DROP TABLE IF EXISTS `resource.basics.Audit`;
- CREATE TABLE `resource.basics.Audit`(
- `id_rba` int NOT NULL AUTO_INCREMENT COMMENT'idx',
- `tconst` varchar(10) NOT NULL COMMENT'alphanumeric identifier basic',
- `url_old` varchar(100) COMMENT'Media URL',
- `url_new` varchar(100) COMMENT'Media URL',
- `poster_old` varchar(100) COMMENT'Poster URL',
- `poster_new` varchar(100) COMMENT'Poster URL',
- /*`views` bigint COMMENT'vews count',*/
- `logged_user` nvarchar(50) COMMENT'user action',
- `oper_type` varchar(10) COMMENT'Operation type',
- `tstamp` datetime,
- KEY `idx_resource.basics.Audit_id_rba` (`id_rba`) COMMENT'index',
- KEY `idx_resource.basics.Audit_tconst` (`tconst`) COMMENT'index',
- PRIMARY KEY (tconst) COMMENT'unique key'
- )
- ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT'Contem os recursos para assistir'
- ;
- ==============================================================================================
- /* create trigger audit ins_resource.basics*/
- DELIMITER //
- drop trigger `ins_resource.basics`;
- create trigger `ins_resource.basics`
- after Insert on `resource.basics`
- FOR EACH ROW
- BEGIN
- INSERT INTO `resource.basics.audit`
- (
- `tconst`
- ,`titleType_new`
- ,`primaryTitle_new`
- ,`originalTitle_new`
- ,`isAdult_new`
- ,`startYear_new`
- ,`endYear_new`
- ,`runtimeMinutes_new`
- ,`genres_new`
- ,`logged_user`
- ,`oper_type`
- ,`tstamp`
- )
- Values
- (
- `new.tconst`
- ,`new.titleType_new`
- ,`new.primaryTitle`
- ,`new.originalTitle`
- ,`new.isAdult`
- ,`new.startYear`
- ,`new.endYear`
- ,`new.runtimeMinutes`
- ,`new.genres`
- , current_user()
- ,'Insert'
- ,getDate()
- );
- END//
- -------------------------------------------------------------------------------------------------
- DELIMITER //
- drop trigger `upd_resource.basics`;
- create trigger `upd_resource.basics`
- after update on `resource.basics`
- FOR EACH ROW
- BEGIN
- INSERT INTO `resource.basics.audit`
- (
- `tconst`
- ,`titleType_old`
- ,`titleType_new`
- ,`primaryTitle_old`
- ,`primaryTitle_new`
- ,`originalTitle_old`
- ,`originalTitle_new`
- ,`isAdult_old`
- ,`isAdult_new`
- ,`startYear_old`
- ,`startYear_new`
- ,`endYear_old`
- ,`endYear_new`
- ,`runtimeMinutes_old`
- ,`runtimeMinutes_new`
- ,`genres_old`
- ,`genres_new`
- ,`logged_user`
- ,`oper_type`
- ,`tstamp`
- )
- Values
- (
- `new.tconst`
- ,`old.titleType_new`
- ,`new.titleType_new`
- ,`old.primaryTitle`
- ,`new.primaryTitle`
- ,`old.originalTitle`
- ,`new.originalTitle`
- ,`old.isAdult`
- ,`new.isAdult`
- ,`old.startYear`
- ,`new.startYear`
- ,`old.endYear`
- ,`new.endYear`
- ,`old.runtimeMinutes`
- ,`new.runtimeMinutes`
- ,`old.genres`
- ,`new.genres`
- , current_user()
- ,'update'
- ,getDate()
- );
- END//
- -------------------------------------------------------------------------------------------------
- DELIMITER //
- drop trigger `del_resource.basics`;
- create trigger `del_resource.basics`
- after delete on `resource.basics`
- FOR EACH ROW
- BEGIN
- INSERT INTO `resource.basics.audit`
- (
- `tconst`
- ,`titleType_old`
- ,`primaryTitle_old`
- ,`originalTitle_old`
- ,`isAdult_old`
- ,`startYear_old`
- ,`endYear_old`
- ,`runtimeMinutes_old`
- ,`genres_old`
- ,`logged_user`
- ,`oper_type`
- ,`tstamp`
- )
- Values
- (
- `new.tconst`
- ,`old.titleType_new`
- ,`old.primaryTitle`
- ,`old.originalTitle`
- ,`old.isAdult`
- ,`old.startYear`
- ,`old.endYear`
- ,`old.runtimeMinutes`
- ,`old.genres`
- , current_user()
- ,'delete'
- ,getDate()
- );
- END//
- ==============================================================================================
- /* model #2*/
- DROP TABLE IF EXISTS `title.ratings`;
- CREATE TABLE `title.ratings`(
- `id_tr` int NOT NULL AUTO_INCREMENT COMMENT'idx',
- `tconst` varchar(10) NOT NULL COMMENT'alphanumeric identifier basic',
- `averageRating` decimal(5,2) NOT NULL COMMENT'weighted average of all the individual user ratings',
- `numVotes` int(10) COMMENT'number of votes the title has received',
- KEY `idx_title.ratings_id_tr` (`id_tr`) COMMENT'index',
- KEY `idx_title.ratings_tconst` (`tconst`) COMMENT'index',
- PRIMARY KEY (tconst) COMMENT'unique key'
- )
- ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT' Contains the IMDb rating and votes information for titles'
- ;
- DROP TABLE IF EXISTS `title.crew`;
- CREATE TABLE `title.crew`(
- `id_tc` int NOT NULL AUTO_INCREMENT COMMENT'idx',
- `tconst` varchar(10) NOT NULL COMMENT'alphanumeric identifier basic',
- `directors` varchar(500) NOT NULL COMMENT'(array of nconsts) - director(s) of the given title',
- `writers` varchar(500) NOT NULL COMMENT'(array of nconsts) – writer(s) of the given title',
- KEY `idx_title.crew_iid_tc` (`id_tc`) COMMENT'index',
- KEY `idx_title.crew_tconst` (`tconst`) COMMENT'index',
- PRIMARY KEY (tconst) COMMENT'unique key'
- )
- ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT'Contains the director and writer information for all the titles in IMDb'
- ;
- DROP TABLE IF EXISTS `title.principals`;
- CREATE TABLE `title.principals`(
- `id_tp` int NOT NULL AUTO_INCREMENT COMMENT'idx',
- `tconst` varchar(10) NOT NULL COMMENT'alphanumeric identifier basic',
- `principalCast` varchar(200) NOT NULL COMMENT'(array of nconsts) – title’s top-billed cast/crew',
- KEY `idx_title.principals_id_tp` (`id_tp`) COMMENT'index',
- KEY `idx_title.principals_tconst` (`tconst`) COMMENT'index',
- PRIMARY KEY (tconst) COMMENT'unique key'
- )
- ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT' – Contains the principal cast/crew for titles'
- ;
- DROP TABLE IF EXISTS `name.basics`;
- CREATE TABLE `name.basics`(
- `id_nb` int NOT NULL AUTO_INCREMENT COMMENT'idx',
- `nconst` varchar(10) NOT NULL COMMENT'alphanumeric unique identifier of the name/person',
- `primaryName` varchar(100) NOT NULL COMMENT'(string)– name by which the person is most often credited',
- `birthYear` smallint(4) NULL COMMENT'in YYYY format',
- `deathYear` smallint(4) NULL COMMENT'in YYYY format if applicable, else ‘\N’',
- `primaryProfession` varchar(250) NOT NULL COMMENT'(array of strings)– the top-3 professions of the person',
- `knownForTitles` varchar(1000) NOT NULL COMMENT'(array of tconsts) – titles the person is known for',
- KEY `idx_name.basics_id_nb` (`id_nb`) COMMENT'index',
- KEY `idx_name.basics_tconst` (`nconst`) COMMENT'index',
- PRIMARY KEY (nconst) COMMENT'unique key'
- )
- ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT'Contains the following information for names'
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement