From c78f84d5c6677551ca32d57187887bfb37d77750 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Thu, 6 Jan 2022 23:47:30 +0100 Subject: [PATCH] DB: Move integrity check to the base.cr file --- src/invidious.cr | 17 +---------------- src/invidious/database/base.cr | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 96e5d348e..d3ad18bd1 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -112,22 +112,7 @@ OUTPUT = CONFIG.output.upcase == "STDOUT" ? STDOUT : File.open(CONFIG.output, mo LOGGER = Invidious::LogHandler.new(OUTPUT, CONFIG.log_level) # Check table integrity -if CONFIG.check_tables - Invidious::Database.check_enum("privacy", PlaylistPrivacy) - - Invidious::Database.check_table("channels", InvidiousChannel) - Invidious::Database.check_table("channel_videos", ChannelVideo) - Invidious::Database.check_table("playlists", InvidiousPlaylist) - Invidious::Database.check_table("playlist_videos", PlaylistVideo) - Invidious::Database.check_table("nonces", Nonce) - Invidious::Database.check_table("session_ids", SessionId) - Invidious::Database.check_table("users", User) - Invidious::Database.check_table("videos", Video) - - if CONFIG.cache_annotations - Invidious::Database.check_table("annotations", Annotation) - end -end +Invidious::Database.check_integrity(CONFIG) # Start jobs diff --git a/src/invidious/database/base.cr b/src/invidious/database/base.cr index a6b38f1ca..0fb1b6af0 100644 --- a/src/invidious/database/base.cr +++ b/src/invidious/database/base.cr @@ -3,6 +3,32 @@ require "pg" module Invidious::Database extend self + # Checks table integrity + # + # Note: config is passed as a parameter to avoid complex + # dependencies between different parts of the software. + def check_integrity(cfg) + return if !cfg.check_tables + Invidious::Database.check_enum("privacy", PlaylistPrivacy) + + Invidious::Database.check_table("channels", InvidiousChannel) + Invidious::Database.check_table("channel_videos", ChannelVideo) + Invidious::Database.check_table("playlists", InvidiousPlaylist) + Invidious::Database.check_table("playlist_videos", PlaylistVideo) + Invidious::Database.check_table("nonces", Nonce) + Invidious::Database.check_table("session_ids", SessionId) + Invidious::Database.check_table("users", User) + Invidious::Database.check_table("videos", Video) + + if cfg.cache_annotations + Invidious::Database.check_table("annotations", Annotation) + end + end + + # + # Table/enum integrity checks + # + def check_enum(enum_name, struct_type = nil) return # TODO