summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2019-03-22 16:53:16 -0500
committerOmar Roth <omarroth@hotmail.com>2019-03-22 16:53:16 -0500
commit1079c4516c60c2cd71fd00bafcc0de1c28a899be (patch)
tree1d1604ed84da639931578700cb3ca24244453fca /src
parent7381985c79f4a681891e2339e575e3294b628309 (diff)
downloadinvidious-1079c4516c60c2cd71fd00bafcc0de1c28a899be.tar.gz
invidious-1079c4516c60c2cd71fd00bafcc0de1c28a899be.tar.bz2
invidious-1079c4516c60c2cd71fd00bafcc0de1c28a899be.zip
Automatically recreate views with outdated schema
Diffstat (limited to 'src')
-rw-r--r--src/invidious/jobs.cr8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/invidious/jobs.cr b/src/invidious/jobs.cr
index 3c8470a5..9aaa7bd3 100644
--- a/src/invidious/jobs.cr
+++ b/src/invidious/jobs.cr
@@ -129,6 +129,14 @@ def refresh_feeds(db, logger, max_threads = 1)
active_threads += 1
spawn do
begin
+ db.query("SELECT * FROM #{view_name} LIMIT 1") do |rs|
+ # View doesn't contain same number of rows as ChannelVideo
+ if ChannelVideo.from_rs(rs)[0]?.try &.to_a.size.try &.!= rs.column_count
+ db.exec("DROP MATERIALIZED VIEW #{view_name}")
+ raise "valid schema does not exist"
+ end
+ end
+
db.exec("REFRESH MATERIALIZED VIEW #{view_name}")
rescue ex
# Create view if it doesn't exist