From 6df1e3743e3708b130674aa4b19a8c77ac3988f4 Mon Sep 17 00:00:00 2001 From: Kilerd Chan Date: Sun, 28 Apr 2019 16:46:15 +0800 Subject: [PATCH] feat: add keywords support and migration file --- .../down.sql | 2 ++ .../up.sql | 2 ++ src/main.rs | 3 --- src/models/article.rs | 9 +++------ src/schema.rs | 1 + 5 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 migrations/2019-04-28-083722_add_keywords_field_for_article/down.sql create mode 100644 migrations/2019-04-28-083722_add_keywords_field_for_article/up.sql diff --git a/migrations/2019-04-28-083722_add_keywords_field_for_article/down.sql b/migrations/2019-04-28-083722_add_keywords_field_for_article/down.sql new file mode 100644 index 0000000..68ee0fc --- /dev/null +++ b/migrations/2019-04-28-083722_add_keywords_field_for_article/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE "public"."articles" DROP COLUMN keywords; \ No newline at end of file diff --git a/migrations/2019-04-28-083722_add_keywords_field_for_article/up.sql b/migrations/2019-04-28-083722_add_keywords_field_for_article/up.sql new file mode 100644 index 0000000..f01be8f --- /dev/null +++ b/migrations/2019-04-28-083722_add_keywords_field_for_article/up.sql @@ -0,0 +1,2 @@ +-- Your SQL goes here +ALTER TABLE "public"."articles" ADD COLUMN keywords TEXT[] NOT NULL DEFAULT '{}'::text[]; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index fa54bcd..19d798d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,9 +18,6 @@ use dotenv::dotenv; use crate::data::RubbleData; use crate::pg_pool::database_pool_establish; -use actix_web::web::route; -use rand::prelude::*; -use std::rc::Rc; use std::sync::Arc; use tera::compile_templates; use time::Duration; diff --git a/src/models/article.rs b/src/models/article.rs index 7b00c08..b55d5ea 100644 --- a/src/models/article.rs +++ b/src/models/article.rs @@ -18,6 +18,7 @@ pub struct Article { pub user_id: i32, pub publish_at: NaiveDateTime, pub url: Option, + pub keywords: Vec, } #[derive(Debug, Insertable, AsChangeset, Serialize, Deserialize)] @@ -33,14 +34,10 @@ pub struct NewArticle { } impl Article { - pub fn link(&self) -> String { match self.url { - Some(ref to) if to.len() != 0 => { - format!("/{}", to) - }, - _ => format!("/archives/{}", self.id) - + Some(ref to) if to.len() != 0 => format!("/{}", to), + _ => format!("/archives/{}", self.id), } } diff --git a/src/schema.rs b/src/schema.rs index b9aa1d9..5599902 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -7,6 +7,7 @@ table! { user_id -> Int4, publish_at -> Timestamp, url -> Nullable, + keywords -> Array, } }