Add a Media model
This commit is contained in:
parent
2c33e1612d
commit
0b5eb2c946
|
@ -0,0 +1,2 @@
|
|||
-- This file should undo anything in `up.sql`
|
||||
DROP TABLE medias;
|
|
@ -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 instance;
|
||||
pub mod likes;
|
||||
pub mod medias;
|
||||
pub mod mentions;
|
||||
pub mod notifications;
|
||||
pub mod post_authors;
|
||||
|
|
|
@ -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! {
|
||||
mentions (id) {
|
||||
id -> Int4,
|
||||
|
@ -170,6 +182,7 @@ allow_tables_to_appear_in_same_query!(
|
|||
follows,
|
||||
instances,
|
||||
likes,
|
||||
medias,
|
||||
mentions,
|
||||
notifications,
|
||||
post_authors,
|
||||
|
|
Loading…
Reference in New Issue