From e17c2c2e277ed77d6f7471b2aa3f066db246caf8 Mon Sep 17 00:00:00 2001 From: Gerardo Arriaga Rendon Date: Mon, 21 Mar 2022 02:12:14 -0400 Subject: [PATCH] Add GitHub schema to Postgres --- .../volumes/db/init/05-github-schema.sql | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 docker/supabase/volumes/db/init/05-github-schema.sql diff --git a/docker/supabase/volumes/db/init/05-github-schema.sql b/docker/supabase/volumes/db/init/05-github-schema.sql new file mode 100644 index 0000000000..645b40cc3c --- /dev/null +++ b/docker/supabase/volumes/db/init/05-github-schema.sql @@ -0,0 +1,36 @@ +CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA extensions; + +CREATE TABLE IF NOT EXISTS github_users ( + id serial PRIMARY KEY, + login citext NOT NULL, -- the user name of the user, known as the `login` field in GitHub API responses + type citext check ( type IN ('user', 'organization') ) NOT NULL +); + +CREATE TABLE IF NOT EXISTS github_repositories ( + id serial PRIMARY KEY, + name text NOT NULL, + owner integer NOT NULL references github_users ON DELETE CASCADE, + UNIQUE (owner, name) -- a user cannot have the same repository, but a repository name can be repeated for many users (e.g. forks) +); + +-- In the GitHub API, pull requests are considered issues, too. +-- Therefore, we would group both pull requests and issues in a single +-- table. For more information, read: +-- https://docs.github.com/en/rest/reference/issues and +-- https://docs.github.com/en/rest/reference/pulls +CREATE TABLE IF NOT EXISTS github_issues ( + id serial PRIMARY KEY, + number integer NOT NULL, + repo integer NOT NULL references github_repositories ON DELETE CASCADE, + type citext check ( type IN ('issue', 'pull_request') ) NOT NULL, + UNIQUE (repo, number) -- an issue number is unique across the whole repo, but several repos can have the same number +); + +/* + TODO: + * Add policies to restrict the users who can write into these + tables (preferably, only the search or parser microservice + should write). + * Add bridge tables that connect this GitHub information to + a posts table that contains the posts themselves. + */