Remove ap_url from mention (#362)

This commit is contained in:
fdb-hiroshima 2018-12-18 15:03:47 +01:00 committed by GitHub
parent 9e799f2cf2
commit ce08346487
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 6 deletions

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE mentions ADD COLUMN ap_url VARCHAR NOT NULL DEFAULT '';

View File

@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE mentions DROP COLUMN ap_url;

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE mentions ADD COLUMN ap_url VARCHAR NOT NULL DEFAULT '';

View File

@ -0,0 +1,11 @@
-- Your SQL goes here
CREATE TABLE mentions2 (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
mentioned_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
post_id INTEGER REFERENCES posts(id) ON DELETE CASCADE,
comment_id INTEGER REFERENCES comments(id) ON DELETE CASCADE
);
INSERT INTO mentions2 SELECT id,mentioned_id,post_id,comment_id FROM mentions;
DROP TABLE mentions;
ALTER TABLE mentions2 RENAME TO mentions;

View File

@ -15,7 +15,6 @@ pub struct Mention {
pub mentioned_id: i32, pub mentioned_id: i32,
pub post_id: Option<i32>, pub post_id: Option<i32>,
pub comment_id: Option<i32>, pub comment_id: Option<i32>,
pub ap_url: String, // TODO: remove, since mentions don't have an AP URL actually, this field was added by mistake
} }
#[derive(Insertable)] #[derive(Insertable)]
@ -24,13 +23,11 @@ pub struct NewMention {
pub mentioned_id: i32, pub mentioned_id: i32,
pub post_id: Option<i32>, pub post_id: Option<i32>,
pub comment_id: Option<i32>, pub comment_id: Option<i32>,
pub ap_url: String,
} }
impl Mention { impl Mention {
insert!(mentions, NewMention); insert!(mentions, NewMention);
get!(mentions); get!(mentions);
find_by!(mentions, find_by_ap_url, ap_url as &str);
list_by!(mentions, list_for_user, mentioned_id as i32); list_by!(mentions, list_for_user, mentioned_id as i32);
list_by!(mentions, list_for_post, post_id as i32); list_by!(mentions, list_for_post, post_id as i32);
list_by!(mentions, list_for_comment, comment_id as i32); list_by!(mentions, list_for_comment, comment_id as i32);
@ -103,7 +100,6 @@ impl Mention {
mentioned_id: mentioned.id, mentioned_id: mentioned.id,
post_id: Some(post.id), post_id: Some(post.id),
comment_id: None, comment_id: None,
ap_url: ment.link_props.href_string().unwrap_or_default(),
}, },
); );
if notify { if notify {
@ -119,7 +115,6 @@ impl Mention {
mentioned_id: mentioned.id, mentioned_id: mentioned.id,
post_id: None, post_id: None,
comment_id: Some(comment.id), comment_id: Some(comment.id),
ap_url: ment.link_props.href_string().unwrap_or_default(),
}, },
); );
if notify { if notify {

View File

@ -115,7 +115,6 @@ table! {
mentioned_id -> Int4, mentioned_id -> Int4,
post_id -> Nullable<Int4>, post_id -> Nullable<Int4>,
comment_id -> Nullable<Int4>, comment_id -> Nullable<Int4>,
ap_url -> Varchar,
} }
} }