feat: add public ID to deployments
This commit is contained in:
parent
f56ca02d39
commit
1f1b21baac
5 changed files with 132 additions and 98 deletions
|
@ -3,8 +3,10 @@ CREATE TABLE IF NOT EXISTS librepages_sites (
|
|||
repo_url VARCHAR(3000) NOT NULL,
|
||||
branch TEXT NOT NULL,
|
||||
hostname VARCHAR(3000) NOT NULL UNIQUE,
|
||||
pub_id uuid NOT NULL UNIQUE,
|
||||
ID SERIAL PRIMARY KEY NOT NULL,
|
||||
owned_by INTEGER NOT NULL references librepages_users(ID) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX librepages_sites_site_secret ON librepages_sites(site_secret);
|
||||
CREATE UNIQUE INDEX librepages_sites_site_pub_id ON librepages_sites(pub_id);
|
||||
|
|
205
sqlx-data.json
205
sqlx-data.json
|
@ -1,5 +1,49 @@
|
|||
{
|
||||
"db": "PostgreSQL",
|
||||
"142525c6d4a5a32ca2419ff19d452722375927f2c1b734092a03106eafd9ef5c": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "site_secret",
|
||||
"ordinal": 0,
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"name": "repo_url",
|
||||
"ordinal": 1,
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"name": "branch",
|
||||
"ordinal": 2,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "hostname",
|
||||
"ordinal": 3,
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"name": "pub_id",
|
||||
"ordinal": 4,
|
||||
"type_info": "Uuid"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
}
|
||||
},
|
||||
"query": "SELECT site_secret, repo_url, branch, hostname, pub_id\n FROM librepages_sites\n WHERE owned_by = (SELECT ID FROM librepages_users WHERE name = $1 );\n "
|
||||
},
|
||||
"14cdc724af64942e93994f97e9eafc8272d15605eff7aab9e5177d01f2bf6118": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
|
@ -15,44 +59,6 @@
|
|||
},
|
||||
"query": "INSERT INTO librepages_site_deploy_events\n (event_type, time, site, pub_id) VALUES (\n (SELECT iD from librepages_deploy_event_type WHERE name = $1),\n $2,\n (SELECT ID from librepages_sites WHERE hostname = $3),\n $4\n );\n "
|
||||
},
|
||||
"1ac91b492001493430c686d9cd7d6be03ada4b4c431d7bc112ef2105eba0e82d": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "repo_url",
|
||||
"ordinal": 0,
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"name": "branch",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "hostname",
|
||||
"ordinal": 2,
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"name": "owned_by",
|
||||
"ordinal": 3,
|
||||
"type_info": "Int4"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
}
|
||||
},
|
||||
"query": "SELECT repo_url, branch, hostname, owned_by\n FROM librepages_sites\n WHERE site_secret = $1\n "
|
||||
},
|
||||
"1be33ea4fe0e6079c88768ff912b824f4b0250193f2d086046c1fd0da125ae0c": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
|
@ -190,22 +196,6 @@
|
|||
},
|
||||
"query": "DELETE FROM librepages_users WHERE name = ($1)"
|
||||
},
|
||||
"67311c6196639edd153b7b7dd56a37703b67abe750b88f5afdcf0d3d779432e7": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Varchar",
|
||||
"Varchar",
|
||||
"Text",
|
||||
"Varchar",
|
||||
"Text"
|
||||
]
|
||||
}
|
||||
},
|
||||
"query": "\n INSERT INTO librepages_sites\n (site_secret, repo_url, branch, hostname, owned_by)\n VALUES ($1, $2, $3, $4, ( SELECT ID FROM librepages_users WHERE name = $5 ));\n "
|
||||
},
|
||||
"6a557f851d4f47383b864085093beb0954e79779f21b655978f07e285281e0ac": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
|
@ -252,7 +242,7 @@
|
|||
},
|
||||
"query": "UPDATE librepages_users set password = $1\n WHERE name = $2"
|
||||
},
|
||||
"9fd163d10860ad4519f9398582aaa0615d6d7b784e844ee71038f77dcd069eed": {
|
||||
"aed3f57305201a19739dfb11cf8780036b992925100de98f0697d76dbea4df65": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
|
@ -274,47 +264,15 @@
|
|||
"name": "hostname",
|
||||
"ordinal": 3,
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"name": "pub_id",
|
||||
"ordinal": 4,
|
||||
"type_info": "Uuid"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
}
|
||||
},
|
||||
"query": "SELECT site_secret, repo_url, branch, hostname\n FROM librepages_sites\n WHERE owned_by = (SELECT ID FROM librepages_users WHERE name = $1 );\n "
|
||||
},
|
||||
"aad26d1f932001cbe49b147348aa528eca5101ec6ef83cb034e1ccd0dbd17878": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "site_secret",
|
||||
"ordinal": 0,
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"name": "repo_url",
|
||||
"ordinal": 1,
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"name": "branch",
|
||||
"ordinal": 2,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "hostname",
|
||||
"ordinal": 3,
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
|
@ -327,7 +285,7 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"query": "SELECT site_secret, repo_url, branch, hostname\n FROM librepages_sites\n WHERE owned_by = (SELECT ID FROM librepages_users WHERE name = $1 )\n AND hostname = $2;\n "
|
||||
"query": "SELECT site_secret, repo_url, branch, hostname, pub_id\n FROM librepages_sites\n WHERE owned_by = (SELECT ID FROM librepages_users WHERE name = $1 )\n AND hostname = $2;\n "
|
||||
},
|
||||
"b48c77db6e663d97df44bf9ec2ee92fd3e02f2dcbcdbd1d491e09fab2da68494": {
|
||||
"describe": {
|
||||
|
@ -355,6 +313,23 @@
|
|||
},
|
||||
"query": "SELECT name, password FROM librepages_users WHERE email = ($1)"
|
||||
},
|
||||
"b8b1b3c5fa205b071f577b2ce9993ddfc7c99ada26aea48aa1c201c8c3c7fcf6": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Varchar",
|
||||
"Varchar",
|
||||
"Text",
|
||||
"Varchar",
|
||||
"Uuid",
|
||||
"Text"
|
||||
]
|
||||
}
|
||||
},
|
||||
"query": "\n INSERT INTO librepages_sites\n (site_secret, repo_url, branch, hostname, pub_id, owned_by)\n VALUES ($1, $2, $3, $4, $5, ( SELECT ID FROM librepages_users WHERE name = $6 ));\n "
|
||||
},
|
||||
"bdd4d2a1b0b97ebf8ed61cfd120b40146fbf3ea9afb5cd0e03c9d29860b6a26b": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
|
@ -395,6 +370,50 @@
|
|||
},
|
||||
"query": "SELECT email FROM librepages_users WHERE name = $1"
|
||||
},
|
||||
"d132d22a214356474d450afc148ae913080119a99e37e089f5df281da151426e": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "repo_url",
|
||||
"ordinal": 0,
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"name": "branch",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "hostname",
|
||||
"ordinal": 2,
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"name": "owned_by",
|
||||
"ordinal": 3,
|
||||
"type_info": "Int4"
|
||||
},
|
||||
{
|
||||
"name": "pub_id",
|
||||
"ordinal": 4,
|
||||
"type_info": "Uuid"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
}
|
||||
},
|
||||
"query": "SELECT repo_url, branch, hostname, owned_by, pub_id\n FROM librepages_sites\n WHERE site_secret = $1\n "
|
||||
},
|
||||
"d2327c1bcb40e18518c2112413a19a9b26eb0f54f83c53e968c9752d70c8dd4e": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
|
|
|
@ -41,12 +41,14 @@ impl AddSite {
|
|||
fn to_site(self, s: &Settings) -> Site {
|
||||
let site_secret = get_random(32);
|
||||
let hostname = get_random_subdomain(s);
|
||||
let pub_id = Uuid::new_v4();
|
||||
Site {
|
||||
site_secret,
|
||||
repo_url: self.repo_url,
|
||||
branch: self.branch,
|
||||
hostname,
|
||||
owner: self.owner,
|
||||
pub_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
17
src/db.rs
17
src/db.rs
|
@ -256,13 +256,14 @@ impl Database {
|
|||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO librepages_sites
|
||||
(site_secret, repo_url, branch, hostname, owned_by)
|
||||
VALUES ($1, $2, $3, $4, ( SELECT ID FROM librepages_users WHERE name = $5 ));
|
||||
(site_secret, repo_url, branch, hostname, pub_id, owned_by)
|
||||
VALUES ($1, $2, $3, $4, $5, ( SELECT ID FROM librepages_users WHERE name = $6 ));
|
||||
",
|
||||
msg.site_secret,
|
||||
msg.repo_url,
|
||||
msg.branch,
|
||||
msg.hostname,
|
||||
msg.pub_id,
|
||||
msg.owner,
|
||||
)
|
||||
.execute(&self.pool)
|
||||
|
@ -278,11 +279,12 @@ impl Database {
|
|||
branch: String,
|
||||
hostname: String,
|
||||
owned_by: i32,
|
||||
pub_id: Uuid,
|
||||
}
|
||||
|
||||
let site = sqlx::query_as!(
|
||||
S,
|
||||
"SELECT repo_url, branch, hostname, owned_by
|
||||
"SELECT repo_url, branch, hostname, owned_by, pub_id
|
||||
FROM librepages_sites
|
||||
WHERE site_secret = $1
|
||||
",
|
||||
|
@ -310,6 +312,7 @@ impl Database {
|
|||
hostname: site.hostname,
|
||||
owner: owner.name,
|
||||
repo_url: site.repo_url,
|
||||
pub_id: site.pub_id,
|
||||
};
|
||||
|
||||
Ok(site)
|
||||
|
@ -318,7 +321,7 @@ impl Database {
|
|||
pub async fn get_site(&self, owner: &str, hostname: &str) -> ServiceResult<Site> {
|
||||
let site = sqlx::query_as!(
|
||||
InnerSite,
|
||||
"SELECT site_secret, repo_url, branch, hostname
|
||||
"SELECT site_secret, repo_url, branch, hostname, pub_id
|
||||
FROM librepages_sites
|
||||
WHERE owned_by = (SELECT ID FROM librepages_users WHERE name = $1 )
|
||||
AND hostname = $2;
|
||||
|
@ -338,7 +341,7 @@ impl Database {
|
|||
pub async fn list_all_sites(&self, owner: &str) -> ServiceResult<Vec<Site>> {
|
||||
let mut sites = sqlx::query_as!(
|
||||
InnerSite,
|
||||
"SELECT site_secret, repo_url, branch, hostname
|
||||
"SELECT site_secret, repo_url, branch, hostname, pub_id
|
||||
FROM librepages_sites
|
||||
WHERE owned_by = (SELECT ID FROM librepages_users WHERE name = $1 );
|
||||
",
|
||||
|
@ -524,6 +527,7 @@ struct InnerSite {
|
|||
repo_url: String,
|
||||
branch: String,
|
||||
hostname: String,
|
||||
pub_id: Uuid,
|
||||
}
|
||||
|
||||
impl InnerSite {
|
||||
|
@ -533,6 +537,7 @@ impl InnerSite {
|
|||
repo_url: self.repo_url,
|
||||
branch: self.branch,
|
||||
hostname: self.hostname,
|
||||
pub_id: self.pub_id,
|
||||
owner,
|
||||
}
|
||||
}
|
||||
|
@ -543,6 +548,7 @@ impl InnerSite {
|
|||
pub struct Site {
|
||||
pub site_secret: String,
|
||||
pub repo_url: String,
|
||||
pub pub_id: Uuid,
|
||||
pub branch: String,
|
||||
pub hostname: String,
|
||||
pub owner: String,
|
||||
|
@ -847,6 +853,7 @@ mod tests {
|
|||
repo_url: "https://git.batsense.net/LibrePages/librepages.git".into(),
|
||||
branch: "librepages".into(),
|
||||
hostname: "db_works.tests.librepages.librepages.org".into(),
|
||||
pub_id: Uuid::new_v4(),
|
||||
owner: p.username.into(),
|
||||
};
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ use serde::Deserialize;
|
|||
use serde::Serialize;
|
||||
#[cfg(not(test))]
|
||||
use tracing::{debug, error, info};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::db::Site;
|
||||
use crate::errors::*;
|
||||
|
@ -39,6 +40,7 @@ pub struct Page {
|
|||
pub path: String,
|
||||
pub branch: String,
|
||||
pub domain: String,
|
||||
pub pub_id: Uuid,
|
||||
}
|
||||
|
||||
impl Page {
|
||||
|
@ -52,6 +54,7 @@ impl Page {
|
|||
.to_owned(),
|
||||
domain: s.hostname,
|
||||
branch: s.branch,
|
||||
pub_id: s.pub_id,
|
||||
}
|
||||
}
|
||||
pub fn open_repo(&self) -> ServiceResult<Repository> {
|
||||
|
@ -277,6 +280,7 @@ mod tests {
|
|||
path: tmp_dir.to_str().unwrap().to_string(),
|
||||
branch: tests::BRANCH.to_string(),
|
||||
domain: "mcaptcha.org".into(),
|
||||
pub_id: Uuid::new_v4(),
|
||||
};
|
||||
|
||||
assert!(
|
||||
|
|
Loading…
Reference in a new issue