Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub schema to Postgres #3297

Merged
merged 1 commit into from
Mar 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions docker/supabase/volumes/db/init/05-github-schema.sql
Original file line number Diff line number Diff line change
@@ -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,
JerryHue marked this conversation as resolved.
Show resolved Hide resolved
JerryHue marked this conversation as resolved.
Show resolved Hide resolved
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:
humphd marked this conversation as resolved.
Show resolved Hide resolved
* Add policies to restrict the users who can write into these
JerryHue marked this conversation as resolved.
Show resolved Hide resolved
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.
*/