Skip to content

Commit

Permalink
invidious-postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
aceberg committed Nov 22, 2023
1 parent d6e9a3c commit 6c23b83
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/invidious-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: invidious-postgres

on:
workflow_dispatch:
push:
branches: [ "main" ]
paths:
- 'invidious-postgres/**'

env:
IMAGE_NAME: invidious-postgres

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Build and Push Docker Image to docker.io
uses: mr-smithers-excellent/[email protected]
with:
image: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}
addLatest: true
dockerfile: ${{ env.IMAGE_NAME }}/Dockerfile
directory: ${{ env.IMAGE_NAME }}
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Sync README.md to DockerHub
uses: ms-jpq/sync-dockerhub-readme@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}
readme: "./${{ env.IMAGE_NAME }}/README.md"
4 changes: 4 additions & 0 deletions invidious-postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM postgres:14

COPY config /config
COPY docker-entrypoint-initdb.d /docker-entrypoint-initdb.d
6 changes: 6 additions & 0 deletions invidious-postgres/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# invidious-postgres





12 changes: 12 additions & 0 deletions invidious-postgres/config/sql/annotations.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Table: public.annotations

-- DROP TABLE public.annotations;

CREATE TABLE IF NOT EXISTS public.annotations
(
id text NOT NULL,
annotations xml,
CONSTRAINT annotations_id_key UNIQUE (id)
);

GRANT ALL ON TABLE public.annotations TO current_user;
30 changes: 30 additions & 0 deletions invidious-postgres/config/sql/channel_videos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- Table: public.channel_videos

-- DROP TABLE public.channel_videos;

CREATE TABLE IF NOT EXISTS public.channel_videos
(
id text NOT NULL,
title text,
published timestamp with time zone,
updated timestamp with time zone,
ucid text,
author text,
length_seconds integer,
live_now boolean,
premiere_timestamp timestamp with time zone,
views bigint,
CONSTRAINT channel_videos_id_key UNIQUE (id)
);

GRANT ALL ON TABLE public.channel_videos TO current_user;

-- Index: public.channel_videos_ucid_idx

-- DROP INDEX public.channel_videos_ucid_idx;

CREATE INDEX IF NOT EXISTS channel_videos_ucid_idx
ON public.channel_videos
USING btree
(ucid COLLATE pg_catalog."default");

25 changes: 25 additions & 0 deletions invidious-postgres/config/sql/channels.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Table: public.channels

-- DROP TABLE public.channels;

CREATE TABLE IF NOT EXISTS public.channels
(
id text NOT NULL,
author text,
updated timestamp with time zone,
deleted boolean,
subscribed timestamp with time zone,
CONSTRAINT channels_id_key UNIQUE (id)
);

GRANT ALL ON TABLE public.channels TO current_user;

-- Index: public.channels_id_idx

-- DROP INDEX public.channels_id_idx;

CREATE INDEX IF NOT EXISTS channels_id_idx
ON public.channels
USING btree
(id COLLATE pg_catalog."default");

22 changes: 22 additions & 0 deletions invidious-postgres/config/sql/nonces.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Table: public.nonces

-- DROP TABLE public.nonces;

CREATE TABLE IF NOT EXISTS public.nonces
(
nonce text,
expire timestamp with time zone,
CONSTRAINT nonces_id_key UNIQUE (nonce)
);

GRANT ALL ON TABLE public.nonces TO current_user;

-- Index: public.nonces_nonce_idx

-- DROP INDEX public.nonces_nonce_idx;

CREATE INDEX IF NOT EXISTS nonces_nonce_idx
ON public.nonces
USING btree
(nonce COLLATE pg_catalog."default");

19 changes: 19 additions & 0 deletions invidious-postgres/config/sql/playlist_videos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- Table: public.playlist_videos

-- DROP TABLE public.playlist_videos;

CREATE TABLE IF NOT EXISTS public.playlist_videos
(
title text,
id text,
author text,
ucid text,
length_seconds integer,
published timestamptz,
plid text references playlists(id),
index int8,
live_now boolean,
PRIMARY KEY (index,plid)
);

GRANT ALL ON TABLE public.playlist_videos TO current_user;
29 changes: 29 additions & 0 deletions invidious-postgres/config/sql/playlists.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- Type: public.privacy

-- DROP TYPE public.privacy;

CREATE TYPE public.privacy AS ENUM
(
'Public',
'Unlisted',
'Private'
);

-- Table: public.playlists

-- DROP TABLE public.playlists;

CREATE TABLE IF NOT EXISTS public.playlists
(
title text,
id text primary key,
author text,
description text,
video_count integer,
created timestamptz,
updated timestamptz,
privacy privacy,
index int8[]
);

GRANT ALL ON public.playlists TO current_user;
23 changes: 23 additions & 0 deletions invidious-postgres/config/sql/session_ids.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Table: public.session_ids

-- DROP TABLE public.session_ids;

CREATE TABLE IF NOT EXISTS public.session_ids
(
id text NOT NULL,
email text,
issued timestamp with time zone,
CONSTRAINT session_ids_pkey PRIMARY KEY (id)
);

GRANT ALL ON TABLE public.session_ids TO current_user;

-- Index: public.session_ids_id_idx

-- DROP INDEX public.session_ids_id_idx;

CREATE INDEX IF NOT EXISTS session_ids_id_idx
ON public.session_ids
USING btree
(id COLLATE pg_catalog."default");

29 changes: 29 additions & 0 deletions invidious-postgres/config/sql/users.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- Table: public.users

-- DROP TABLE public.users;

CREATE TABLE IF NOT EXISTS public.users
(
updated timestamp with time zone,
notifications text[],
subscriptions text[],
email text NOT NULL,
preferences text,
password text,
token text,
watched text[],
feed_needs_update boolean,
CONSTRAINT users_email_key UNIQUE (email)
);

GRANT ALL ON TABLE public.users TO current_user;

-- Index: public.email_unique_idx

-- DROP INDEX public.email_unique_idx;

CREATE UNIQUE INDEX IF NOT EXISTS email_unique_idx
ON public.users
USING btree
(lower(email) COLLATE pg_catalog."default");

23 changes: 23 additions & 0 deletions invidious-postgres/config/sql/videos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Table: public.videos

-- DROP TABLE public.videos;

CREATE UNLOGGED TABLE IF NOT EXISTS public.videos
(
id text NOT NULL,
info text,
updated timestamp with time zone,
CONSTRAINT videos_pkey PRIMARY KEY (id)
);

GRANT ALL ON TABLE public.videos TO current_user;

-- Index: public.id_idx

-- DROP INDEX public.id_idx;

CREATE UNIQUE INDEX IF NOT EXISTS id_idx
ON public.videos
USING btree
(id COLLATE pg_catalog."default");

14 changes: 14 additions & 0 deletions invidious-postgres/docker-entrypoint-initdb.d/init-invidious-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
echo "Runing init script for INVIDIOUS"

set -eou pipefail

psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/channels.sql
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/videos.sql
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/channel_videos.sql
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/users.sql
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/session_ids.sql
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/nonces.sql
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/annotations.sql
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlists.sql
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlist_videos.sql

0 comments on commit 6c23b83

Please sign in to comment.