CREATE TABLE asset_thumbnail (id INT AUTO_INCREMENT NOT NULL, media_asset_id INT DEFAULT NULL, sequenceNo INT NOT NULL, resWidth BIGINT DEFAULT NULL, resHeight BIGINT DEFAULT NULL, cdnURL VARCHAR(1024) NOT NULL, INDEX IDX_2E6DCEDCABB37F3 (media_asset_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE channel (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE channel_mediapackage (channel_id INT NOT NULL, media_package_id INT NOT NULL, INDEX IDX_D752D06972F5A1AA (channel_id), INDEX IDX_D752D069FE69656B (media_package_id), PRIMARY KEY(channel_id, media_package_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE channel_mediaasset (channel_id INT NOT NULL, media_asset_id INT NOT NULL, INDEX IDX_2A04A50272F5A1AA (channel_id), INDEX IDX_2A04A502ABB37F3 (media_asset_id), PRIMARY KEY(channel_id, media_asset_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE media_asset (id INT AUTO_INCREMENT NOT NULL, title VARCHAR(1024) NOT NULL, locations VARCHAR(512) NOT NULL, description LONGTEXT NOT NULL, shortDescription LONGTEXT NOT NULL, source VARCHAR(1024) NOT NULL, createdDate DATETIME NOT NULL, uploadedDate DATETIME NOT NULL, restrictions VARCHAR(1024) NOT NULL, cdnURL VARCHAR(1024) NOT NULL, fileSizeBytes BIGINT NOT NULL, copyright VARCHAR(1024) NOT NULL, fileType VARCHAR(255) NOT NULL, posterImageCDNURL VARCHAR(1024) NOT NULL, posterImageFileType VARCHAR(255) NOT NULL, posterImageFileSizeBytes BIGINT NOT NULL, views BIGINT NOT NULL, downloads BIGINT NOT NULL, ispublic TINYINT(1) NOT NULL, state VARCHAR(16) NOT NULL, asset_type VARCHAR(255) NOT NULL, tapeTimeSeconds BIGINT DEFAULT NULL, keyFrame BIGINT DEFAULT NULL, srcAspect VARCHAR(255) DEFAULT NULL, sound VARCHAR(255) DEFAULT NULL, slate INT DEFAULT NULL, previewVideoCDNURL VARCHAR(1024) DEFAULT NULL, previewVideoFileSizeBytes BIGINT DEFAULT NULL, previewVideoFileType VARCHAR(255) DEFAULT NULL, resWidth BIGINT DEFAULT NULL, resHeight BIGINT DEFAULT NULL, wordcount INT DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE media_asset_sector (media_asset_id INT NOT NULL, sector_id INT NOT NULL, INDEX IDX_CA7FFC79ABB37F3 (media_asset_id), INDEX IDX_CA7FFC79DE95C867 (sector_id), PRIMARY KEY(media_asset_id, sector_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE media_asset_channel (media_asset_id INT NOT NULL, channel_id INT NOT NULL, INDEX IDX_2570F1B0ABB37F3 (media_asset_id), INDEX IDX_2570F1B072F5A1AA (channel_id), PRIMARY KEY(media_asset_id, channel_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE media_package (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(1024) NOT NULL, description VARCHAR(1024) NOT NULL, createdDate DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE mediaasset_package (media_package_id INT NOT NULL, media_asset_id INT NOT NULL, INDEX IDX_8E2CEEE6FE69656B (media_package_id), INDEX IDX_8E2CEEE6ABB37F3 (media_asset_id), PRIMARY KEY(media_package_id, media_asset_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE sector (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE sector_user (sector_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_5BFDA9A8DE95C867 (sector_id), INDEX IDX_5BFDA9A8A76ED395 (user_id), PRIMARY KEY(sector_id, user_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE tag (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(50) NOT NULL, slug VARCHAR(50) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, UNIQUE INDEX UNIQ_389B7835E237E06 (name), UNIQUE INDEX UNIQ_389B783989D9B62 (slug), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE tagging (id INT AUTO_INCREMENT NOT NULL, tag_id INT DEFAULT NULL, resource_type VARCHAR(50) NOT NULL, resource_id VARCHAR(50) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX IDX_A4AED123BAD26311 (tag_id), UNIQUE INDEX tagging_idx (tag_id, resource_type, resource_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE collection_item (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, media_asset_id INT DEFAULT NULL, addedDate DATETIME NOT NULL, downloadURL LONGTEXT DEFAULT NULL, expiresDate DATETIME DEFAULT NULL, downloaded TINYINT(1) NOT NULL, lastDownloadDate DATETIME DEFAULT NULL, requested TINYINT(1) NOT NULL, requestedDate DATETIME DEFAULT NULL, token VARCHAR(50) DEFAULT NULL, INDEX IDX_556C09F0A76ED395 (user_id), INDEX IDX_556C09F0ABB37F3 (media_asset_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE event (id INT AUTO_INCREMENT NOT NULL, media_asset_id INT DEFAULT NULL, collection_item_id INT DEFAULT NULL, firedDate DATETIME NOT NULL, status VARCHAR(20) NOT NULL, event_type VARCHAR(255) NOT NULL, INDEX IDX_3BAE0AA7ABB37F3 (media_asset_id), INDEX IDX_3BAE0AA74643208F (collection_item_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE mg_user (id INT AUTO_INCREMENT NOT NULL, username VARCHAR(255) NOT NULL, username_canonical VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, email_canonical VARCHAR(255) NOT NULL, enabled TINYINT(1) NOT NULL, salt VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, last_login DATETIME DEFAULT NULL, locked TINYINT(1) NOT NULL, expired TINYINT(1) NOT NULL, expires_at DATETIME DEFAULT NULL, confirmation_token VARCHAR(255) DEFAULT NULL, password_requested_at DATETIME DEFAULT NULL, roles LONGTEXT NOT NULL COMMENT '(DC2Type:array)', credentials_expired TINYINT(1) NOT NULL, credentials_expire_at DATETIME DEFAULT NULL, first_name VARCHAR(512) NOT NULL, last_name VARCHAR(512) NOT NULL, phone_no VARCHAR(128) NOT NULL, mobile_no VARCHAR(128) NOT NULL, company VARCHAR(512) NOT NULL, country VARCHAR(32) NOT NULL, sendNotifications TINYINT(1) NOT NULL, notifyPackage TINYINT(1) NOT NULL, notifyImage TINYINT(1) NOT NULL, notifyText TINYINT(1) NOT NULL, notifyVideo TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_74689CF692FC23A8 (username_canonical), UNIQUE INDEX UNIQ_74689CF6A0D96FBF (email_canonical), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE email_notification (id INT AUTO_INCREMENT NOT NULL, toAddress VARCHAR(512) NOT NULL, subject VARCHAR(1024) NOT NULL, body LONGTEXT NOT NULL, sent TINYINT(1) NOT NULL, sentDate DATETIME DEFAULT NULL, createdDate DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
ALTER TABLE asset_thumbnail ADD CONSTRAINT FK_2E6DCEDCABB37F3 FOREIGN KEY (media_asset_id) REFERENCES media_asset (id);
ALTER TABLE channel_mediapackage ADD CONSTRAINT FK_D752D06972F5A1AA FOREIGN KEY (channel_id) REFERENCES channel (id) ON DELETE CASCADE;
ALTER TABLE channel_mediapackage ADD CONSTRAINT FK_D752D069FE69656B FOREIGN KEY (media_package_id) REFERENCES media_package (id) ON DELETE CASCADE;
ALTER TABLE channel_mediaasset ADD CONSTRAINT FK_2A04A50272F5A1AA FOREIGN KEY (channel_id) REFERENCES channel (id) ON DELETE CASCADE;
ALTER TABLE channel_mediaasset ADD CONSTRAINT FK_2A04A502ABB37F3 FOREIGN KEY (media_asset_id) REFERENCES media_asset (id) ON DELETE CASCADE;
ALTER TABLE media_asset_sector ADD CONSTRAINT FK_CA7FFC79ABB37F3 FOREIGN KEY (media_asset_id) REFERENCES media_asset (id) ON DELETE CASCADE;
ALTER TABLE media_asset_sector ADD CONSTRAINT FK_CA7FFC79DE95C867 FOREIGN KEY (sector_id) REFERENCES sector (id) ON DELETE CASCADE;
ALTER TABLE media_asset_channel ADD CONSTRAINT FK_2570F1B0ABB37F3 FOREIGN KEY (media_asset_id) REFERENCES media_asset (id) ON DELETE CASCADE;
ALTER TABLE media_asset_channel ADD CONSTRAINT FK_2570F1B072F5A1AA FOREIGN KEY (channel_id) REFERENCES channel (id) ON DELETE CASCADE;
ALTER TABLE mediaasset_package ADD CONSTRAINT FK_8E2CEEE6FE69656B FOREIGN KEY (media_package_id) REFERENCES media_package (id) ON DELETE CASCADE;
ALTER TABLE mediaasset_package ADD CONSTRAINT FK_8E2CEEE6ABB37F3 FOREIGN KEY (media_asset_id) REFERENCES media_asset (id) ON DELETE CASCADE;
ALTER TABLE sector_user ADD CONSTRAINT FK_5BFDA9A8DE95C867 FOREIGN KEY (sector_id) REFERENCES sector (id) ON DELETE CASCADE;
ALTER TABLE sector_user ADD CONSTRAINT FK_5BFDA9A8A76ED395 FOREIGN KEY (user_id) REFERENCES mg_user (id) ON DELETE CASCADE;
ALTER TABLE tagging ADD CONSTRAINT FK_A4AED123BAD26311 FOREIGN KEY (tag_id) REFERENCES tag (id);
ALTER TABLE collection_item ADD CONSTRAINT FK_556C09F0A76ED395 FOREIGN KEY (user_id) REFERENCES mg_user (id);
ALTER TABLE collection_item ADD CONSTRAINT FK_556C09F0ABB37F3 FOREIGN KEY (media_asset_id) REFERENCES media_asset (id);
ALTER TABLE event ADD CONSTRAINT FK_3BAE0AA7ABB37F3 FOREIGN KEY (media_asset_id) REFERENCES media_asset (id);
ALTER TABLE event ADD CONSTRAINT FK_3BAE0AA74643208F FOREIGN KEY (collection_item_id) REFERENCES collection_item (id);