Compare commits
2 Commits
09ed646c76
...
c4df9ad3af
Author | SHA1 | Date |
---|---|---|
R Tyler Croy | c4df9ad3af | |
R Tyler Croy | 7fc0902d4c |
|
@ -1,11 +1,21 @@
|
|||
CREATE TABLE projects (
|
||||
uuid TEXT NOT NULL PRIMARY KEY,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
created_at DATETIME NOT NULL DEFAULT (DATETIME('now'))
|
||||
);
|
||||
|
||||
CREATE TABLE runs (
|
||||
uuid TEXT NOT NULL PRIMARY KEY,
|
||||
num INTEGER NOT NULL,
|
||||
status INTEGER NOT NULL,
|
||||
log_url TEXT NOT NULL,
|
||||
|
||||
project TEXT NOT NULL,
|
||||
definition TEXT NOT NULL,
|
||||
scm_info TEXT NOT NULL,
|
||||
|
||||
created_at DATETIME NOT NULL DEFAULT (DATETIME('now')),
|
||||
FOREIGN KEY(project) REFERENCES projects(uuid),
|
||||
FOREIGN KEY(scm_info) REFERENCES scm_info(uuid),
|
||||
FOREIGN KEY(definition) REFERENCES run_definition(uuid)
|
||||
);
|
||||
|
|
|
@ -0,0 +1,229 @@
|
|||
{
|
||||
"db": "SQLite",
|
||||
"02211dd3eb7fae06b7aa31f93075705d63715180042e2230741847d771529a72": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Right": 3
|
||||
}
|
||||
},
|
||||
"query": "INSERT INTO projects (uuid, name, created_at) VALUES (?, ?, ?)"
|
||||
},
|
||||
"16aca487288926010cd2bc6ad073343803e27a665aab4929717641b51cfbbdd0": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "uuid",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "created_at",
|
||||
"ordinal": 2,
|
||||
"type_info": "Datetime"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
}
|
||||
},
|
||||
"query": "SELECT * FROM projects WHERE name = ?"
|
||||
},
|
||||
"2538a6ddc8153c8c15689d84d3fa03d35101d0d44ced0fbb914aa9986eb50638": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "uuid",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "definition",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "created_at",
|
||||
"ordinal": 2,
|
||||
"type_info": "Datetime"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
}
|
||||
},
|
||||
"query": "SELECT * FROM run_definition WHERE uuid = ?"
|
||||
},
|
||||
"2805947c9f2f72cfa673c8d4f1adbb96ddbfe2055b7e912b89936436ec17097d": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Right": 4
|
||||
}
|
||||
},
|
||||
"query": "INSERT INTO scm_info (uuid, git_url, ref, created_at) VALUES (?, ?, ?, ?)"
|
||||
},
|
||||
"2d48553d1a6ffbd898f40f0e94a0a472b8d34302af74b886bec3934d225b3bc7": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "uuid",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "num",
|
||||
"ordinal": 1,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "status",
|
||||
"ordinal": 2,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "log_url",
|
||||
"ordinal": 3,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "project",
|
||||
"ordinal": 4,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "definition",
|
||||
"ordinal": 5,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "scm_info",
|
||||
"ordinal": 6,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "created_at",
|
||||
"ordinal": 7,
|
||||
"type_info": "Datetime"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
}
|
||||
},
|
||||
"query": "SELECT * FROM runs WHERE uuid = ?"
|
||||
},
|
||||
"4f4e02e3e0c6e954cad36b001386acc4e208988344b6cc00d78eb0f2e44e0172": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Right": 7
|
||||
}
|
||||
},
|
||||
"query": "INSERT INTO runs (uuid, num, status, log_url, definition, scm_info, project) VALUES (?, ?, ?, ?, ?, ?, ?)"
|
||||
},
|
||||
"53e30732dd99a1729b202e124f96edd308664c2377081d564d34a63c4424e7df": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "uuid",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "git_url",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "ref",
|
||||
"ordinal": 2,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "created_at",
|
||||
"ordinal": 3,
|
||||
"type_info": "Datetime"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
}
|
||||
},
|
||||
"query": "SELECT * FROM scm_info WHERE uuid = ?"
|
||||
},
|
||||
"980b3cb885d26d06b4178df215617e26aecd79f4d813df14770ec8ae540d0ce2": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "uuid",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "created_at",
|
||||
"ordinal": 2,
|
||||
"type_info": "Datetime"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
}
|
||||
},
|
||||
"query": "SELECT * FROM projects WHERE uuid = ?"
|
||||
},
|
||||
"de3900705f74f03e76e4cd3076c6642c1d3585f263db326c9671d794d5b32a63": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Right": 3
|
||||
}
|
||||
},
|
||||
"query": "INSERT INTO run_definition (uuid, definition, created_at) VALUES (?, ?, ?)"
|
||||
}
|
||||
}
|
|
@ -3,32 +3,33 @@
|
|||
*/
|
||||
|
||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||
use sqlx::{FromRow, SqlitePool};
|
||||
use url::Url;
|
||||
use sqlx::{SqlitePool};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Project {
|
||||
uuid: String,
|
||||
name: String,
|
||||
created_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl Default for Project {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
uuid: Uuid::new_v4().hyphenated().to_string(),
|
||||
name: "Default Project".into(),
|
||||
created_at: Utc::now().naive_utc(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Run {
|
||||
run: RunRow,
|
||||
project: Project,
|
||||
scm_info: ScmInfo,
|
||||
definition: RunDefinition,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct RunRow {
|
||||
// Unique identifier for the Run
|
||||
uuid: String,
|
||||
// User-identifiable number for the Run, monotonically increasing
|
||||
num: i64,
|
||||
// Unix status return code from the run, zero is success
|
||||
status: i64,
|
||||
// Globally resolvable URL for fetching raw logs
|
||||
log_url: String,
|
||||
definition: String,
|
||||
scm_info: String,
|
||||
created_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
/* The basic implementation for Run has all the database access operations
|
||||
*/
|
||||
impl Run {
|
||||
|
@ -46,7 +47,14 @@ impl Run {
|
|||
run.scm_info.created_at
|
||||
)
|
||||
.execute(&mut tx)
|
||||
.await;
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
r#"INSERT INTO projects (uuid, name, created_at) VALUES (?, ?, ?)"#,
|
||||
run.project.uuid,
|
||||
run.project.name,
|
||||
run.project.created_at,
|
||||
).execute(&mut tx).await?;
|
||||
|
||||
sqlx::query!(
|
||||
r#"INSERT INTO run_definition (uuid, definition, created_at) VALUES (?, ?, ?)"#,
|
||||
|
@ -58,13 +66,14 @@ impl Run {
|
|||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"INSERT INTO runs (uuid, num, status, log_url, definition, scm_info) VALUES ($1, $2, $3, $4, $5, $6)",
|
||||
"INSERT INTO runs (uuid, num, status, log_url, definition, scm_info, project) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
run.run.uuid,
|
||||
run.run.num,
|
||||
run.run.status,
|
||||
run.run.log_url,
|
||||
run.definition.uuid,
|
||||
run.scm_info.uuid,
|
||||
run.project.uuid,
|
||||
)
|
||||
.execute(&mut tx)
|
||||
.await?;
|
||||
|
@ -85,6 +94,15 @@ impl Run {
|
|||
)
|
||||
.fetch_one(pool)
|
||||
.await?;
|
||||
|
||||
let project = sqlx::query_as!(
|
||||
Project,
|
||||
"SELECT * FROM projects WHERE uuid = ?",
|
||||
row.project
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.await?;
|
||||
|
||||
let definition = sqlx::query_as!(
|
||||
RunDefinition,
|
||||
"SELECT * FROM run_definition WHERE uuid = ?",
|
||||
|
@ -96,6 +114,7 @@ impl Run {
|
|||
Ok(Run {
|
||||
run: row,
|
||||
scm_info,
|
||||
project,
|
||||
definition,
|
||||
})
|
||||
}
|
||||
|
@ -105,12 +124,37 @@ impl Default for Run {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
run: RunRow::default(),
|
||||
project: Project::default(),
|
||||
scm_info: ScmInfo::default(),
|
||||
definition: RunDefinition::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The RunRow is the struct for the deserialization/serialization of the runs table
|
||||
* unfortunately this is a little bit of misdirection due to the inability to make
|
||||
* nested structs with sqlx work well
|
||||
*/
|
||||
#[derive(Clone, Debug)]
|
||||
struct RunRow {
|
||||
// Unique identifier for the Run
|
||||
uuid: String,
|
||||
// User-identifiable number for the Run, monotonically increasing
|
||||
num: i64,
|
||||
// Unix status return code from the run, zero is success
|
||||
status: i64,
|
||||
// Globally resolvable URL for fetching raw logs
|
||||
log_url: String,
|
||||
// Foreign key to projects
|
||||
project: String,
|
||||
// Foreign key to run_definition
|
||||
definition: String,
|
||||
// Foreign key to scm_info
|
||||
scm_info: String,
|
||||
created_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl Default for RunRow {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
@ -119,6 +163,7 @@ impl Default for RunRow {
|
|||
status: 0,
|
||||
log_url: "https://example.com/console.log".into(),
|
||||
definition: Uuid::new_v4().hyphenated().to_string(),
|
||||
project: Uuid::new_v4().hyphenated().to_string(),
|
||||
scm_info: Uuid::new_v4().hyphenated().to_string(),
|
||||
created_at: Utc::now().naive_utc(),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue