Add a Media model

This commit is contained in:
Bat 2018-09-02 12:34:48 +01:00
parent 2c33e1612d
commit 0b5eb2c946
5 changed files with 57 additions and 2 deletions

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE medias;

View 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
)

View File

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

View 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);
}

View File

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