diff --git a/Cargo.lock b/Cargo.lock index 908f3902..4aef0e43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2475,7 +2475,7 @@ dependencies = [ [[package]] name = "revolt" -version = "0.4.0-alpha.6" +version = "0.4.1-alpha.0" dependencies = [ "async-std", "async-tungstenite", diff --git a/Cargo.toml b/Cargo.toml index c51af081..ab57cf57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "revolt" -version = "0.4.0-alpha.6" +version = "0.4.1-alpha.0" authors = ["Paul Makles "] edition = "2018" diff --git a/src/database/entities/autumn.rs b/src/database/entities/autumn.rs index 8b42c439..a0ae82f9 100644 --- a/src/database/entities/autumn.rs +++ b/src/database/entities/autumn.rs @@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize}; #[serde(tag = "type")] enum Metadata { File, + Text, Image { width: isize, height: isize }, Video { width: isize, height: isize }, Audio, @@ -13,9 +14,18 @@ enum Metadata { pub struct File { #[serde(rename = "_id")] pub id: String, + tag: String, filename: String, metadata: Metadata, content_type: String, + size: isize, + #[serde(skip_serializing_if = "Option::is_none")] message_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] + user_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] + server_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] + object_id: Option, } diff --git a/src/database/migrations/init.rs b/src/database/migrations/init.rs index 4ced3423..3a57826e 100644 --- a/src/database/migrations/init.rs +++ b/src/database/migrations/init.rs @@ -29,6 +29,10 @@ pub async fn create_database() { .await .expect("Failed to create migrations collection."); + db.create_collection("attachments", None) + .await + .expect("Failed to create attachments collection."); + db.create_collection( "pubsub", CreateCollectionOptions::builder() diff --git a/src/database/migrations/scripts.rs b/src/database/migrations/scripts.rs index 2c8d6eab..ace6f91a 100644 --- a/src/database/migrations/scripts.rs +++ b/src/database/migrations/scripts.rs @@ -1,8 +1,8 @@ use crate::database::get_collection; use log::info; -use mongodb::bson::{doc, from_document}; use serde::{Deserialize, Serialize}; +use mongodb::bson::{doc, from_document}; #[derive(Serialize, Deserialize)] struct MigrationInfo { @@ -10,7 +10,7 @@ struct MigrationInfo { revision: i32, } -pub const LATEST_REVISION: i32 = 0; +pub const LATEST_REVISION: i32 = 1; pub async fn migrate_database() { let migrations = get_collection("migrations"); @@ -53,6 +53,29 @@ pub async fn run_migrations(revision: i32) -> i32 { info!("Running migration [revision 0]: Test migration system."); } + if revision <= 1 { + info!("Running migration [revision 1 / 2021-04-24]: Migrate to Autumn v1.0.0."); + + let messages = get_collection("messages"); + let attachments = get_collection("attachments"); + + messages.update_many( + doc! { "attachment": { "$exists": 1 } }, + doc! { "$set": { "attachment.tag": "attachments", "attachment.size": 0 } }, + None + ) + .await + .expect("Failed to update messages."); + + attachments.update_many( + doc! { }, + doc! { "$set": { "tag": "attachments", "size": 0 } }, + None + ) + .await + .expect("Failed to update attachments."); + } + // Reminder to update LATEST_REVISION when adding new migrations. LATEST_REVISION } diff --git a/src/routes/channels/message_send.rs b/src/routes/channels/message_send.rs index 8a4d30b7..0cfa5f18 100644 --- a/src/routes/channels/message_send.rs +++ b/src/routes/channels/message_send.rs @@ -67,7 +67,8 @@ pub async fn req(user: User, target: Ref, message: Json) -> Result) -> Result JsonValue { json!({ - "revolt": "0.4.0-alpha.6", + "revolt": "0.4.1-alpha.0", "features": { "registration": !*DISABLE_REGISTRATION, "captcha": {