Skip to content
This repository was archived by the owner on Jul 29, 2022. It is now read-only.

Commit 92da90f

Browse files
packapotatoesvitiral
authored andcommitted
Add Schema (vitiral#118)
start full schema for tracker * Started adding full table schema and supporting structs * added database schema dump, and instructions for import * Added 'chrono' dependencies for date stamp * updated database schema
1 parent 74e2a0d commit 92da90f

File tree

7 files changed

+135
-8
lines changed

7 files changed

+135
-8
lines changed

Cargo.lock

+42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ version = "0.6.5"
1111

1212
[dependencies]
1313
ansi_term = "0.7"
14+
chrono = "0.3.0"
1415
difference = "1.0"
1516
fern = "0.3.5"
1617
itertools = "0.5"
@@ -35,7 +36,7 @@ features = ["suggestions", "color", "wrap_help"]
3536
version = "2"
3637

3738
[dependencies.diesel]
38-
features = ["postgres"]
39+
features = ["postgres", "chrono"]
3940
optional = true
4041
version = "0.11.0"
4142

db.dump

7.47 KB
Binary file not shown.

design/tracker/notes.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
### dump database schema
2+
pg_dump <dbname> -s -F c -f <dumpname>
3+
4+
### restore from dump:
5+
pg_restore <dumpname> -d <dbname>
6+
(must specify an existing database to import to)
7+
8+
important: db.dump must be in user `postgres` home directory (or whatever user
9+
accesses postgres)
10+
11+
To find where this is:
12+
13+
* Change to user for postgresql: `sudo -u postgres -i` (for me the user is `postgres`)
14+
15+
* Get actual file location: `readlink -f <anyFileInThisDir>`
16+
17+
This should give you the path to the current directory REMEMBER THIS LOCATION
18+
19+
* `exit` to go back to normal user
20+
21+
* as normal user `mv db.dump <pathGivenByReadlink/db.dump>`
22+
23+
switch back to user postgres again
24+
25+
pg_restore should now work as above (pg_restore <dumpname> -d <dbname>)

src/api/handler.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ impl RpcMethodSync for GetArtifacts {
4242
struct GetTests;
4343
impl RpcMethodSync for GetTests {
4444
fn call(&self, _: Params) -> result::Result<serde_json::Value, RpcError> {
45-
use self::test_name::dsl::*;
45+
use self::test_names::dsl::*;
4646
let connection = establish_connection();
4747
info!("GetTests called");
4848

49-
let result = test_name.load::<TestName>(&connection)
49+
let result = test_names.load::<TestName>(&connection)
5050
.expect("Error loading test names");
5151

5252
Ok(serde_json::to_value(result).expect("serde"))

src/api/types.rs

+62-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,71 @@
1+
extern crate chrono;
12

2-
3-
#[derive(Queryable, Serialize, Deserialize)]
3+
#[derive(Queryable, Insertable, Serialize, Deserialize)]
4+
#[table_name="test_names"]
45
pub struct TestName {
5-
pub id: i32,
66
pub name: String,
77
}
88

9+
#[derive(Queryable, Insertable)]
10+
#[table_name="artifact_names"]
11+
pub struct ArtifactName {
12+
pub name: String,
13+
}
14+
15+
#[derive(Queryable, Insertable)]
16+
#[table_name="version"]
17+
pub struct Version {
18+
pub id: i32,
19+
pub major: String,
20+
pub minor: Option<String>,
21+
pub patch: Option<String>,
22+
pub build: Option<String>,
23+
}
24+
25+
#[derive(Queryable, Insertable)]
26+
#[table_name="test_info"]
27+
pub struct TestInfo {
28+
pub id: i32,
29+
pub test_name: String,
30+
pub passed: bool,
31+
pub artifacts: Vec<String>,
32+
pub date: chrono::NaiveDateTime, // what goes here?
33+
pub version: i32,
34+
pub link: Option<String>,
35+
pub data: Option<Vec<u8>>, // what goes here?
36+
}
37+
38+
table! {
39+
test_names (name) {
40+
name -> Text,
41+
}
42+
}
43+
44+
table! {
45+
artifact_names (name) {
46+
name -> Text,
47+
}
48+
}
49+
50+
table! {
51+
version (id) {
52+
id -> Int4,
53+
major -> Text,
54+
minor -> Nullable<Text>,
55+
patch -> Nullable<Text>,
56+
build -> Nullable<Text>,
57+
}
58+
}
59+
960
table! {
10-
test_name (id) {
61+
test_info (id) {
1162
id -> Int4,
12-
name -> Varchar,
63+
test_name -> Text,
64+
passed -> Bool,
65+
artifacts -> Array<Text>,
66+
date -> Timestamp,
67+
version -> Int4,
68+
link -> Nullable<Text>,
69+
data -> Nullable<Array<Bytea>>,
1370
}
1471
}

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ extern crate diesel;
6161
extern crate diesel_codegen;
6262
#[cfg(feature="server")]
6363
extern crate dotenv;
64+
#[cfg(features="server")]
65+
extern crate chrono;
6466

6567
// serialization
6668
#[macro_use]

0 commit comments

Comments
 (0)