add initial DB schema for server
This commit is contained in:
parent
967c3fdb99
commit
b3477fc2a3
56
server/migrations/1_create_molci_schema.sql
Normal file
56
server/migrations/1_create_molci_schema.sql
Normal file
@ -0,0 +1,56 @@
|
||||
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);
|
@ -23,7 +23,7 @@ api.register({
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
app.get("/ping", async (_req, res) => {
|
||||
app.get("/ping", async (_req, res) => {
|
||||
try {
|
||||
const result = await pool.query("SELECT NOW()");
|
||||
res.json({ success: true, time: result.rows[0].now });
|
||||
@ -33,7 +33,7 @@ app.use(express.json());
|
||||
.status(500)
|
||||
.json({ success: false, error: "Database connection failed" });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
api.init();
|
||||
app.use((req, res) => api.handleRequest(req as Request, req, res));
|
||||
|
Loading…
x
Reference in New Issue
Block a user