CREATE TABLE `watched_repositories` ( `id` int unsigned NOT NULL AUTO_INCREMENT, `type` enum('github','dockerhub') COLLATE utf8mb4_unicode_ci NOT NULL, `org` varchar(39) COLLATE utf8mb4_unicode_ci NOT NULL, `repo` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `tag` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, `latest_entry` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `active` tinyint(1) NOT NULL DEFAULT '1', `missing_checks` tinyint unsigned NOT NULL DEFAULT '0', `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `uq_repository` (`type`,`org`,`repo`,`tag`), KEY `idx_active_type` (`active`,`type`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE `watched_repositories_subscriptions` ( `id` int unsigned NOT NULL AUTO_INCREMENT, `user_id` bigint NOT NULL, `repository_id` int unsigned NOT NULL, `custom_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `active` tinyint(1) NOT NULL DEFAULT '1', `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `uq_user_repository` (`user_id`,`repository_id`), KEY `idx_repository_active` (`repository_id`,`active`), CONSTRAINT `fk_wrs_repository` FOREIGN KEY (`repository_id`) REFERENCES `watched_repositories` (`id`) ON DELETE CASCADE, CONSTRAINT `fk_wrs_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ;