Add migration table for compilations

This commit is contained in:
broquemonsieur
2023-06-28 23:48:43 -07:00
parent 1d209c422e
commit 8c15c1e8cc
3 changed files with 137 additions and 1 deletions

View File

@@ -0,0 +1,49 @@
module Invidious::Database::Migrations
class CreateCompilationsTable < Migration
version 8
def up(conn : DB::Connection)
if !privacy_type_exists?(conn)
conn.exec <<-SQL
CREATE TYPE public.compilation_privacy AS ENUM
(
'Unlisted',
'Private'
);
SQL
end
conn.exec <<-SQL
CREATE TABLE IF NOT EXISTS public.compilations
(
title text,
id text primary key,
author text,
description text,
video_count integer,
created timestamptz,
updated timestamptz,
privacy compilation_privacy,
index int8[]
);
SQL
conn.exec <<-SQL
GRANT ALL ON public.compilations TO current_user;
SQL
end
private def privacy_type_exists?(conn : DB::Connection) : Bool
request = <<-SQL
SELECT 1 AS one
FROM pg_type
INNER JOIN pg_namespace ON pg_namespace.oid = pg_type.typnamespace
WHERE pg_namespace.nspname = 'public'
AND pg_type.typname = 'privacy'
LIMIT 1;
SQL
!conn.query_one?(request, as: Int32).nil?
end
end
end