summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/server.rs5
-rw-r--r--src/mass.rs5
-rw-r--r--src/schema.rs1
3 files changed, 8 insertions, 3 deletions
diff --git a/src/bin/server.rs b/src/bin/server.rs
index 708cd3e..9ea1f0d 100644
--- a/src/bin/server.rs
+++ b/src/bin/server.rs
@@ -7,7 +7,7 @@ use std::collections::HashMap;
use std::io::Write;
use std::net::TcpListener;
use std::thread::{sleep, spawn};
-use std::time::{Duration, Instant};
+use std::time::{Duration, Instant, SystemTime};
use space::constants;
use space::mass::{Mass, MassEntry};
@@ -28,8 +28,9 @@ fn populate() -> HashMap<String, Mass> {
fn backup(masses: HashMap<String, Mass>) {
let connection = PgConnection::establish(&get_db_url()).expect("Cannot connect");
+ let timestamp = SystemTime::now();
for (name, mass) in masses {
- let mass_entry = mass.to_mass_entry(name.to_string());
+ let mass_entry = mass.to_mass_entry(name.to_string(), timestamp);
diesel::insert_into(db_masses)
.values(&mass_entry)
.on_conflict(name_column)
diff --git a/src/mass.rs b/src/mass.rs
index 9629e24..b29c372 100644
--- a/src/mass.rs
+++ b/src/mass.rs
@@ -3,6 +3,7 @@ extern crate rand;
use self::rand::distributions::Uniform;
use self::rand::Rng;
use std::collections::HashMap;
+use std::time::SystemTime;
use crate::constants;
use crate::item::{Item, ItemType};
@@ -32,6 +33,7 @@ pub struct MassEntry {
pub id: Option<i32>,
pub name: String,
pub mass: String,
+ pub last_modified: SystemTime,
}
impl MassEntry {
@@ -315,11 +317,12 @@ impl Mass {
}
}
- pub fn to_mass_entry(&self, name: String) -> MassEntry {
+ pub fn to_mass_entry(&self, name: String, last_modified: SystemTime) -> MassEntry {
MassEntry {
id: None,
name,
mass: serde_json::to_string(&self).unwrap(),
+ last_modified,
}
}
}
diff --git a/src/schema.rs b/src/schema.rs
index c258603..f6ec1f7 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -3,5 +3,6 @@ table! {
id -> Nullable<Integer>,
name -> Varchar,
mass -> Varchar,
+ last_modified -> Timestamp,
}
}