summaryrefslogtreecommitdiff
path: root/src/db
diff options
context:
space:
mode:
authorNathan Perry <avaglir@gmail.com>2018-04-04 22:09:13 -0400
committerNathan Perry <avaglir@gmail.com>2018-04-04 22:09:13 -0400
commitbf6745af21f82562af0b85de566f4e7b7ef5df8c (patch)
treea7b70656c84b7a9cf1d71a67921b5d171308234b /src/db
parent180ef480c0037cfcb5735fdfd2c60f910bf5ba5a (diff)
revamp database structure
Diffstat (limited to 'src/db')
-rw-r--r--src/db/models.rs55
-rw-r--r--src/db/schema.rs103
2 files changed, 133 insertions, 25 deletions
diff --git a/src/db/models.rs b/src/db/models.rs
index 899fa1e..c06c41e 100644
--- a/src/db/models.rs
+++ b/src/db/models.rs
@@ -1,18 +1,65 @@
use super::schema::*;
+use chrono::naive::NaiveDateTime;
-#[derive(Insertable, Queryable, Identifiable, AsChangeset)]
+#[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 link: String,
+ pub audio_id: i32,
+ pub metadata_id: i32,
}
-#[derive(Insertable, Queryable, Identifiable, AsChangeset)]
+#[derive(Insertable, Queryable, Identifiable, PartialEq, AsChangeset, Debug)]
#[table_name="text_memes"]
pub struct TextMeme {
pub id: i32,
pub title: String,
pub content: String,
- pub pic_related: 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,
}
diff --git a/src/db/schema.rs b/src/db/schema.rs
index b29a1ca..40891a5 100644
--- a/src/db/schema.rs
+++ b/src/db/schema.rs
@@ -1,21 +1,82 @@
-table! {
- audio_memes (id) {
- id -> Int4,
- title -> Varchar,
- link -> Varchar,
- }
-}
-
-table! {
- text_memes (id) {
- id -> Int4,
- title -> Varchar,
- content -> Text,
- pic_related -> Varchar,
- }
-}
-
-allow_tables_to_appear_in_same_query!(
- audio_memes,
- text_memes,
-);
+table! {
+ audio (id) {
+ id -> Int4,
+ data -> Bytea,
+ metadata_id -> Int4,
+ }
+}
+
+table! {
+ audio_memes (id) {
+ id -> Int4,
+ title -> Varchar,
+ audio_id -> Int4,
+ metadata_id -> Int4,
+ }
+}
+
+table! {
+ audit_records (id) {
+ id -> Int4,
+ updated -> Timestamp,
+ updated_by -> Int8,
+ metadata_id -> Int4,
+ }
+}
+
+table! {
+ image_memes (id) {
+ id -> Int4,
+ title -> Varchar,
+ image_id -> Int4,
+ metadata_id -> Int4,
+ }
+}
+
+table! {
+ images (id) {
+ id -> Int4,
+ data -> Bytea,
+ metadata_id -> Int4,
+ }
+}
+
+table! {
+ metadata (id) {
+ id -> Int4,
+ created -> Timestamp,
+ created_by -> Int8,
+ }
+}
+
+table! {
+ text_memes (id) {
+ id -> Int4,
+ title -> Varchar,
+ content -> Text,
+ image_id -> Nullable<Int4>,
+ audio_id -> Nullable<Int4>,
+ metadata_id -> Int4,
+ }
+}
+
+joinable!(audio -> metadata (metadata_id));
+joinable!(audio_memes -> audio (audio_id));
+joinable!(audio_memes -> metadata (metadata_id));
+joinable!(audit_records -> metadata (metadata_id));
+joinable!(image_memes -> images (image_id));
+joinable!(image_memes -> metadata (metadata_id));
+joinable!(images -> metadata (metadata_id));
+joinable!(text_memes -> audio (audio_id));
+joinable!(text_memes -> images (image_id));
+joinable!(text_memes -> metadata (metadata_id));
+
+allow_tables_to_appear_in_same_query!(
+ audio,
+ audio_memes,
+ audit_records,
+ image_memes,
+ images,
+ metadata,
+ text_memes,
+);