forked from jmug/stoatchat
Migrate to Autumn 1.0.0
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -2475,7 +2475,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "revolt"
|
name = "revolt"
|
||||||
version = "0.4.0-alpha.6"
|
version = "0.4.1-alpha.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-tungstenite",
|
"async-tungstenite",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt"
|
name = "revolt"
|
||||||
version = "0.4.0-alpha.6"
|
version = "0.4.1-alpha.0"
|
||||||
authors = ["Paul Makles <paulmakles@gmail.com>"]
|
authors = ["Paul Makles <paulmakles@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
enum Metadata {
|
enum Metadata {
|
||||||
File,
|
File,
|
||||||
|
Text,
|
||||||
Image { width: isize, height: isize },
|
Image { width: isize, height: isize },
|
||||||
Video { width: isize, height: isize },
|
Video { width: isize, height: isize },
|
||||||
Audio,
|
Audio,
|
||||||
@@ -13,9 +14,18 @@ enum Metadata {
|
|||||||
pub struct File {
|
pub struct File {
|
||||||
#[serde(rename = "_id")]
|
#[serde(rename = "_id")]
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
tag: String,
|
||||||
filename: String,
|
filename: String,
|
||||||
metadata: Metadata,
|
metadata: Metadata,
|
||||||
content_type: String,
|
content_type: String,
|
||||||
|
size: isize,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
message_id: Option<String>,
|
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>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ pub async fn create_database() {
|
|||||||
.await
|
.await
|
||||||
.expect("Failed to create migrations collection.");
|
.expect("Failed to create migrations collection.");
|
||||||
|
|
||||||
|
db.create_collection("attachments", None)
|
||||||
|
.await
|
||||||
|
.expect("Failed to create attachments collection.");
|
||||||
|
|
||||||
db.create_collection(
|
db.create_collection(
|
||||||
"pubsub",
|
"pubsub",
|
||||||
CreateCollectionOptions::builder()
|
CreateCollectionOptions::builder()
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use crate::database::get_collection;
|
use crate::database::get_collection;
|
||||||
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use mongodb::bson::{doc, from_document};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use mongodb::bson::{doc, from_document};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct MigrationInfo {
|
struct MigrationInfo {
|
||||||
@@ -10,7 +10,7 @@ struct MigrationInfo {
|
|||||||
revision: i32,
|
revision: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const LATEST_REVISION: i32 = 0;
|
pub const LATEST_REVISION: i32 = 1;
|
||||||
|
|
||||||
pub async fn migrate_database() {
|
pub async fn migrate_database() {
|
||||||
let migrations = get_collection("migrations");
|
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.");
|
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.
|
// Reminder to update LATEST_REVISION when adding new migrations.
|
||||||
LATEST_REVISION
|
LATEST_REVISION
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,8 @@ pub async fn req(user: User, target: Ref, message: Json<Data>) -> Result<JsonVal
|
|||||||
.find_one(
|
.find_one(
|
||||||
doc! {
|
doc! {
|
||||||
"_id": attachment_id,
|
"_id": attachment_id,
|
||||||
"message_id": {
|
"tag": "attachments",
|
||||||
|
"message": {
|
||||||
"$exists": false
|
"$exists": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -91,7 +92,7 @@ pub async fn req(user: User, target: Ref, message: Json<Data>) -> Result<JsonVal
|
|||||||
},
|
},
|
||||||
doc! {
|
doc! {
|
||||||
"$set": {
|
"$set": {
|
||||||
"message_id": &id
|
"message": &id
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use rocket_contrib::json::JsonValue;
|
|||||||
#[get("/")]
|
#[get("/")]
|
||||||
pub async fn root() -> JsonValue {
|
pub async fn root() -> JsonValue {
|
||||||
json!({
|
json!({
|
||||||
"revolt": "0.4.0-alpha.6",
|
"revolt": "0.4.1-alpha.0",
|
||||||
"features": {
|
"features": {
|
||||||
"registration": !*DISABLE_REGISTRATION,
|
"registration": !*DISABLE_REGISTRATION,
|
||||||
"captcha": {
|
"captcha": {
|
||||||
|
|||||||
Reference in New Issue
Block a user