ぼざろクリーチャーシリーズ DB 兼 API(自分用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

33 lines
3.1 KiB

  1. -- Create videos table
  2. CREATE TABLE `nizika_nico`.`videos` ( `id` BIGINT NOT NULL AUTO_INCREMENT , `code` VARCHAR(16) NOT NULL COMMENT '動画 Id.' , `title` VARCHAR(256) NOT NULL COMMENT '動画タイトル' , `description` TEXT NOT NULL COMMENT '概要欄' , `uploaded_at` DATETIME NOT NULL COMMENT '投稿日時' , `deleted_at` DATETIME NULL DEFAULT NULL COMMENT '削除日時' , PRIMARY KEY (`id`)) ENGINE = InnoDB COMMENT = '動画';
  3. ALTER TABLE `videos` ADD UNIQUE(`code`);
  4. -- Create tags table
  5. CREATE TABLE `nizika_nico`.`tags` ( `id` BIGINT NOT NULL AUTO_INCREMENT , `name` VARCHAR(64) NOT NULL COMMENT 'タグ名' , PRIMARY KEY (`id`)) ENGINE = InnoDB COMMENT = 'タグ';
  6. ALTER TABLE `tags` ADD UNIQUE(`name`);
  7. -- Create video_tags table
  8. CREATE TABLE `nizika_nico`.`video_tags` ( `id` BIGINT NOT NULL AUTO_INCREMENT , `video_id` BIGINT NOT NULL COMMENT '動画 Id.' , `tag_id` BIGINT NOT NULL COMMENT 'タグ Id.' , `tagged_at` DATE NOT NULL COMMENT 'タグがつけられた日' , `untagged_at` DATE NULL COMMENT 'タグが外された日' , PRIMARY KEY (`id`)) ENGINE = InnoDB COMMENT = '動画とタグの関係';
  9. ALTER TABLE `video_tags` ADD INDEX(`video_id`);
  10. ALTER TABLE `video_tags` ADD FOREIGN KEY (`video_id`) REFERENCES `videos`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
  11. ALTER TABLE `video_tags` ADD INDEX(`tag_id`);
  12. ALTER TABLE `video_tags` ADD FOREIGN KEY (`tag_id`) REFERENCES `tags`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
  13. -- Create users table
  14. CREATE TABLE `nizika_nico`.`users` ( `id` BIGINT NOT NULL AUTO_INCREMENT , `code` VARCHAR(64) NOT NULL COMMENT 'ユーザ・コード' , PRIMARY KEY (`id`)) ENGINE = InnoDB COMMENT = 'ユーザ';
  15. ALTER TABLE `users` ADD UNIQUE(`code`);
  16. -- Create comments table
  17. CREATE TABLE `nizika_nico`.`comments` ( `id` BIGINT NOT NULL AUTO_INCREMENT , `video_id` BIGINT NOT NULL COMMENT '動画 Id.' , `comment_no` INT NOT NULL COMMENT 'コメ番' , `user_id` BIGINT NOT NULL COMMENT 'ユーザ Id.' , `content` VARCHAR(256) NOT NULL COMMENT '内容' , `posted_at` DATETIME NOT NULL COMMENT '投稿日時' , `nico_count` INT NOT NULL DEFAULT '0' COMMENT 'ニコる回数' , PRIMARY KEY (`id`)) ENGINE = InnoDB COMMENT = 'コメント';
  18. ALTER TABLE `comments` ADD INDEX(`video_id`);
  19. ALTER TABLE `comments` ADD FOREIGN KEY (`video_id`) REFERENCES `videos`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
  20. ALTER TABLE `comments` ADD INDEX(`user_id`);
  21. ALTER TABLE `comments` ADD FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
  22. ALTER TABLE `comments` ADD UNIQUE(`video_id`, `comment_no`);
  23. -- Create video_histories table
  24. CREATE TABLE `nizika_nico`.`video_histories` ( `id` BIGINT NOT NULL AUTO_INCREMENT , `video_id` BIGINT NOT NULL COMMENT '動画 Id.' , `fetched_at` DATE NOT NULL COMMENT '取得日' , `views_count` INT NOT NULL COMMENT '再生回数' , PRIMARY KEY (`id`)) ENGINE = InnoDB COMMENT = '動画情報推移';
  25. ALTER TABLE `video_histories` ADD INDEX(`video_id`);
  26. ALTER TABLE `video_histories` ADD FOREIGN KEY (`video_id`) REFERENCES `videos`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
  27. ALTER TABLE `video_histories` ADD UNIQUE(`video_id`, `fetched_at`);