Browse Source

Add timestamp to gists

master
Dylan Baker 5 years ago
parent
commit
c4171ae006

+ 3
- 0
Cargo.lock View File

@@ -121,6 +121,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
121 121
 dependencies = [
122 122
  "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
123 123
  "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
124
+ "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
124 125
  "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
125 126
 ]
126 127
 
@@ -184,6 +185,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
184 185
 dependencies = [
185 186
  "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
186 187
  "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
188
+ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
187 189
  "diesel_derives 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
188 190
  "pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
189 191
 ]
@@ -286,6 +288,7 @@ dependencies = [
286 288
 name = "gist-server"
287 289
 version = "0.1.0"
288 290
 dependencies = [
291
+ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
289 292
  "diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
290 293
  "dotenv 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
291 294
  "r2d2 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)",

+ 2
- 1
Cargo.toml View File

@@ -5,7 +5,8 @@ authors = ["Dylan Baker"]
5 5
 edition = "2018"
6 6
 
7 7
 [dependencies]
8
-diesel = { version = "1.0.0", features = ["postgres"] }
8
+chrono = { version = "0.4.6", features = ["serde"] }
9
+diesel = { version = "1.0.0", features = ["postgres", "chrono"] }
9 10
 dotenv = "0.9.0"
10 11
 r2d2 = "0.8.3"
11 12
 r2d2-diesel = "1.0.0"

+ 1
- 0
migrations/2019-05-01-183414_add_timestamp_to_gists/down.sql View File

@@ -0,0 +1 @@
1
+ALTER TABLE gists DROP COLUMN created_at;

+ 1
- 0
migrations/2019-05-01-183414_add_timestamp_to_gists/up.sql View File

@@ -0,0 +1 @@
1
+ALTER TABLE gists ADD COLUMN created_at TIMESTAMP DEFAULT NOW();

+ 4
- 2
src/gists/mod.rs View File

@@ -1,16 +1,18 @@
1
+use chrono::NaiveDateTime;
1 2
 use diesel::pg::PgConnection as PGC;
2 3
 use diesel::prelude::*;
3 4
 
4 5
 use crate::schema::gists;
5 6
 
6
-#[derive(Queryable, AsChangeset, Serialize, Deserialize)]
7
+#[derive(Queryable, Serialize, Deserialize)]
7 8
 pub struct Gist {
8 9
     pub id: i32,
9 10
     pub title: String,
10 11
     pub body: String,
12
+    pub created_at: Option<NaiveDateTime>,
11 13
 }
12 14
 
13
-#[derive(Insertable, Serialize, Deserialize)]
15
+#[derive(Insertable, AsChangeset, Serialize, Deserialize)]
14 16
 #[table_name = "gists"]
15 17
 pub struct InsertableGist {
16 18
     pub title: String,

+ 1
- 0
src/main.rs View File

@@ -1,5 +1,6 @@
1 1
 #![feature(proc_macro_hygiene, decl_macro)]
2 2
 
3
+extern crate chrono;
3 4
 #[macro_use]
4 5
 extern crate diesel;
5 6
 extern crate dotenv;

+ 1
- 0
src/schema.rs View File

@@ -3,5 +3,6 @@ table! {
3 3
         id -> Int4,
4 4
         title -> Varchar,
5 5
         body -> Text,
6
+        created_at -> Nullable<Timestamp>,
6 7
     }
7 8
 }

Loading…
Cancel
Save