update server table schema
This commit is contained in:
parent
b3477fc2a3
commit
c8d7f0201e
53
server/migrations/001_create_molci_schema.sql
Normal file
53
server/migrations/001_create_molci_schema.sql
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
CREATE TABLE forges (
|
||||||
|
forge_id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
display_name TEXT NOT NULL, -- e.g gitea
|
||||||
|
base_url TEXT NOT NULL -- API base URL
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE users (
|
||||||
|
user_id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
forge_id INT NOT NULL REFERENCES forges(forge_id) ON DELETE CASCADE,
|
||||||
|
forge_user_id TEXT NOT NULL,
|
||||||
|
access_token TEXT NOT NULL, -- OAuth access token
|
||||||
|
token_expires_at TIMESTAMPTZ,
|
||||||
|
UNIQUE(forge_id, forge_user_id) -- Only one account per forge per user
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Repos from forges
|
||||||
|
CREATE TABLE repositories (
|
||||||
|
repo_id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
forge_id INT NOT NULL REFERENCES forges(forge_id) ON DELETE CASCADE,
|
||||||
|
forge_repo_id TEXT NOT NULL,
|
||||||
|
owner_id INT REFERENCES users(user_id) NOT NULL,
|
||||||
|
repo_name TEXT NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
clone_url TEXT NOT NULL,
|
||||||
|
ssh_url TEXT,
|
||||||
|
html_url TEXT, -- might be useful for linking to the repo in our frontend
|
||||||
|
is_private BOOLEAN DEFAULT FALSE,
|
||||||
|
default_branch TEXT DEFAULT 'main', -- need to know the main branch to trigger builds
|
||||||
|
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
||||||
|
UNIQUE(forge_id, forge_repo_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO forges (forge_id, display_name, base_url)
|
||||||
|
VALUES (0, 'gitea', 'http://localhost:3000');
|
||||||
|
|
||||||
|
INSERT INTO users (forge_id, forge_user_id, access_token)
|
||||||
|
VALUES (0, 'testuser', 'dummy_token');
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO repositories (forge_id, forge_repo_id, owner_id, repo_name, description, clone_url, ssh_url, html_url, is_private)
|
||||||
|
VALUES
|
||||||
|
(0, '1', 1, 'my-awesome-project', 'A sample project for testing MOLCI',
|
||||||
|
'http://localhost:3000/testuser/my-awesome-project.git',
|
||||||
|
'git@localhost:testuser/my-awesome-project.git',
|
||||||
|
'http://localhost:3000/testuser/my-awesome-project', false),
|
||||||
|
|
||||||
|
(0, '2', 1,'molci-frontend', 'Frontend for MOLCI CI system',
|
||||||
|
'http://localhost:3000/testuser/molci-frontend.git',
|
||||||
|
'git@localhost:testuser/molci-frontend.git',
|
||||||
|
'http://localhost:3000/testuser/molci-frontend', false);
|
@ -1,56 +0,0 @@
|
|||||||
CREATE TABLE forges (
|
|
||||||
forge_id INTEGER PRIMARY KEY NOT NULL,
|
|
||||||
display_name VARCHAR(255) NOT NULL, -- e.g gitea
|
|
||||||
base_url TEXT NOT NULL, -- API base URL
|
|
||||||
client_id VARCHAR(64) NOT NULL, -- OAuth client ID
|
|
||||||
client_secret VARCHAR(128) NOT NULL -- OAuth secret
|
|
||||||
);
|
|
||||||
|
|
||||||
-- MOLCI users
|
|
||||||
CREATE TABLE users (
|
|
||||||
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
|
||||||
username VARCHAR(255) NOT NULL UNIQUE
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Forge accounts linked to MOLCI users
|
|
||||||
CREATE TABLE user_forge_accounts (
|
|
||||||
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, -- MOLCI internal ID
|
|
||||||
user_id INT NOT NULL REFERENCES users(id) ON DELETE CASCADE, -- Foreign key to the users table, pointing to the MOLCI user that owns this forge account
|
|
||||||
forge_id INT NOT NULL REFERENCES forges(forge_id) ON DELETE CASCADE,
|
|
||||||
forge_user_id VARCHAR(64) NOT NULL,
|
|
||||||
access_token TEXT NOT NULL, -- OAuth access token
|
|
||||||
token_expires_at TIMESTAMP,
|
|
||||||
UNIQUE(user_id, forge_id) -- Only one account per forge per user
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Repos from forges
|
|
||||||
CREATE TABLE repositories (
|
|
||||||
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
|
||||||
forge_id INT NOT NULL REFERENCES forges(forge_id) ON DELETE CASCADE,
|
|
||||||
forge_repo_id VARCHAR(255) NOT NULL,
|
|
||||||
repo_name VARCHAR(500) NOT NULL,
|
|
||||||
description TEXT,
|
|
||||||
clone_url TEXT NOT NULL,
|
|
||||||
ssh_url TEXT,
|
|
||||||
html_url TEXT, -- might be useful for linking to the repo in our frontend
|
|
||||||
is_private BOOLEAN DEFAULT FALSE,
|
|
||||||
default_branch VARCHAR(100) DEFAULT 'main', -- need to know the main branch to trigger builds
|
|
||||||
created_at TIMESTAMP DEFAULT NOW(),
|
|
||||||
updated_at TIMESTAMP DEFAULT NOW(),
|
|
||||||
UNIQUE(forge_id, forge_repo_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO forges (forge_id, display_name, base_url, client_id, client_secret)
|
|
||||||
VALUES (0, 'gitea', 'http://localhost:3000', 'dev_client_id', 'dev_client_secret');
|
|
||||||
|
|
||||||
INSERT INTO repositories (forge_id, forge_repo_id, repo_name, description, clone_url, ssh_url, html_url, is_private)
|
|
||||||
VALUES
|
|
||||||
(0, '1', 'my-awesome-project', 'A sample project for testing MOLCI',
|
|
||||||
'http://localhost:3000/testuser/my-awesome-project.git',
|
|
||||||
'git@localhost:testuser/my-awesome-project.git',
|
|
||||||
'http://localhost:3000/testuser/my-awesome-project', false),
|
|
||||||
|
|
||||||
(0, '2', 'molci-frontend', 'Frontend for MOLCI CI system',
|
|
||||||
'http://localhost:3000/testuser/molci-frontend.git',
|
|
||||||
'git@localhost:testuser/molci-frontend.git',
|
|
||||||
'http://localhost:3000/testuser/molci-frontend', false);
|
|
Loading…
x
Reference in New Issue
Block a user