feat: add keywords support and migration file

This commit is contained in:
Kilerd Chan 2019-04-28 16:46:15 +08:00
parent 5a18706160
commit 6df1e3743e
5 changed files with 8 additions and 9 deletions

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE "public"."articles" DROP COLUMN keywords;

View File

@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE "public"."articles" ADD COLUMN keywords TEXT[] NOT NULL DEFAULT '{}'::text[];

View File

@ -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;

View File

@ -18,6 +18,7 @@ pub struct Article {
pub user_id: i32,
pub publish_at: NaiveDateTime,
pub url: Option<String>,
pub keywords: Vec<String>,
}
#[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),
}
}

View File

@ -7,6 +7,7 @@ table! {
user_id -> Int4,
publish_at -> Timestamp,
url -> Nullable<Text>,
keywords -> Array<Text>,
}
}