Add a Media model
This commit is contained in:
parent
2c33e1612d
commit
0b5eb2c946
2
migrations/2018-09-02-111458_create_medias/down.sql
Normal file
2
migrations/2018-09-02-111458_create_medias/down.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
-- This file should undo anything in `up.sql`
|
||||||
|
DROP TABLE medias;
|
10
migrations/2018-09-02-111458_create_medias/up.sql
Normal file
10
migrations/2018-09-02-111458_create_medias/up.sql
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
-- Your SQL goes here
|
||||||
|
CREATE TABLE medias (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
file_path TEXT NOT NULL DEFAULT '',
|
||||||
|
alt_text TEXT NOT NULL DEFAULT '',
|
||||||
|
is_remote BOOLEAN NOT NULL DEFAULT 'f',
|
||||||
|
remote_url TEXT,
|
||||||
|
sensitive BOOLEAN NOT NULL DEFAULT 'f',
|
||||||
|
content_warning TEXT
|
||||||
|
)
|
@ -111,6 +111,7 @@ pub mod db_conn;
|
|||||||
pub mod follows;
|
pub mod follows;
|
||||||
pub mod instance;
|
pub mod instance;
|
||||||
pub mod likes;
|
pub mod likes;
|
||||||
|
pub mod medias;
|
||||||
pub mod mentions;
|
pub mod mentions;
|
||||||
pub mod notifications;
|
pub mod notifications;
|
||||||
pub mod post_authors;
|
pub mod post_authors;
|
||||||
|
29
plume-models/src/medias.rs
Normal file
29
plume-models/src/medias.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
use diesel::{self, PgConnection, QueryDsl, ExpressionMethods, RunQueryDsl};
|
||||||
|
use schema::medias;
|
||||||
|
|
||||||
|
#[derive(Queryable)]
|
||||||
|
pub struct Media {
|
||||||
|
pub id: i32,
|
||||||
|
pub file_path: String,
|
||||||
|
pub alt_text: String,
|
||||||
|
pub is_remote: bool,
|
||||||
|
pub remote_url: Option<String>,
|
||||||
|
pub sensitive: bool,
|
||||||
|
pub content_warning: Option<String>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable)]
|
||||||
|
#[table_name = "medias"]
|
||||||
|
pub struct NewMedia {
|
||||||
|
pub file_path: String,
|
||||||
|
pub alt_text: String,
|
||||||
|
pub is_remote: bool,
|
||||||
|
pub remote_url: Option<String>,
|
||||||
|
pub sensitive: bool,
|
||||||
|
pub content_warning: Option<String>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Media {
|
||||||
|
insert!(medias, NewMedia);
|
||||||
|
get!(medias);
|
||||||
|
}
|
@ -72,6 +72,18 @@ table! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table! {
|
||||||
|
medias (id) {
|
||||||
|
id -> Int4,
|
||||||
|
file_path -> Text,
|
||||||
|
alt_text -> Text,
|
||||||
|
is_remote -> Bool,
|
||||||
|
remote_url -> Nullable<Text>,
|
||||||
|
sensitive -> Bool,
|
||||||
|
content_warning -> Nullable<Text>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
mentions (id) {
|
mentions (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
@ -170,6 +182,7 @@ allow_tables_to_appear_in_same_query!(
|
|||||||
follows,
|
follows,
|
||||||
instances,
|
instances,
|
||||||
likes,
|
likes,
|
||||||
|
medias,
|
||||||
mentions,
|
mentions,
|
||||||
notifications,
|
notifications,
|
||||||
post_authors,
|
post_authors,
|
||||||
|
Loading…
Reference in New Issue
Block a user