aboutsummaryrefslogtreecommitdiff
path: root/src/db/models.rs
blob: c06c41eff9f27d52ce465e76da0b3ca83d4e6746 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use super::schema::*;
use chrono::naive::NaiveDateTime;

#[derive(Insertable, Queryable, Identifiable, AsChangeset, Debug, Associations)]
#[belongs_to(Audio)]
#[belongs_to(Image)]
#[belongs_to(TextMeme)]
#[belongs_to(ImageMeme)]
#[belongs_to(TextMeme)]
#[table_name="metadata"]
pub struct Metadata {
    pub id: i32,
    pub created: NaiveDateTime,
    pub created_by: i64,
}

#[derive(Insertable, Queryable, Identifiable, PartialEq, AsChangeset, Debug, Associations)]
#[belongs_to(AudioMeme)]
#[belongs_to(TextMeme)]
#[table_name="audio"]
pub struct Audio {
    pub id: i32,
    pub data: Vec<u8>,
    pub metadata_id: i32,
}

#[derive(Insertable, Queryable, Identifiable, PartialEq, AsChangeset, Debug, Associations)]
#[belongs_to(ImageMeme)]
#[belongs_to(TextMeme)]
#[table_name="images"]
pub struct Image {
    pub id: i32,
    pub data: Vec<u8>,
    pub metadata_id: i32,
}

#[derive(Insertable, Queryable, Identifiable, PartialEq, AsChangeset, Debug)]
#[table_name="audio_memes"]
pub struct AudioMeme {
    pub id: i32,
    pub title: String,
    pub audio_id: i32,
    pub metadata_id: i32,
}

#[derive(Insertable, Queryable, Identifiable, PartialEq, AsChangeset, Debug)]
#[table_name="text_memes"]
pub struct TextMeme {
    pub id: i32,
    pub title: String,
    pub content: String,
    pub image_id: Option<i32>,
    pub audio_id: Option<i32>,
    pub metadata_id: i32,
}

#[derive(Insertable, Queryable, Identifiable, PartialEq, AsChangeset, Debug, Associations)]
#[belongs_to(Metadata)]
#[table_name="audit_records"]
pub struct AuditRecord {
    pub id: i32,
    pub updated: NaiveDateTime,
    pub updated_by: i64,
    pub metadata_id: i32,
}