Migrate to Autumn 1.0.0

This commit is contained in:
Paul
2021-04-24 16:00:13 +01:00
parent 9e2250783c
commit f7bcd3ad93
7 changed files with 45 additions and 7 deletions

View File

@@ -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<String>,
#[serde(skip_serializing_if = "Option::is_none")]
user_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
server_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
object_id: Option<String>,
}

View File

@@ -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()

View File

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

View File

@@ -67,7 +67,8 @@ pub async fn req(user: User, target: Ref, message: Json<Data>) -> Result<JsonVal
.find_one(
doc! {
"_id": attachment_id,
"message_id": {
"tag": "attachments",
"message": {
"$exists": false
}
},
@@ -91,7 +92,7 @@ pub async fn req(user: User, target: Ref, message: Json<Data>) -> Result<JsonVal
},
doc! {
"$set": {
"message_id": &id
"message": &id
}
},
None,

View File

@@ -9,7 +9,7 @@ use rocket_contrib::json::JsonValue;
#[get("/")]
pub async fn root() -> JsonValue {
json!({
"revolt": "0.4.0-alpha.6",
"revolt": "0.4.1-alpha.0",
"features": {
"registration": !*DISABLE_REGISTRATION,
"captcha": {