fix: Use correct enum tagging for invites
This commit is contained in:
@@ -4,8 +4,7 @@ use crate::{
|
|||||||
mongodb::{
|
mongodb::{
|
||||||
bson::{doc, from_bson, from_document, to_document, Bson, DateTime, Document},
|
bson::{doc, from_bson, from_document, to_document, Bson, DateTime, Document},
|
||||||
options::FindOptions,
|
options::FindOptions,
|
||||||
},
|
}, Invite, MongoDb, DISCRIMINATOR_SEARCH_SPACE
|
||||||
MongoDb, DISCRIMINATOR_SEARCH_SPACE,
|
|
||||||
};
|
};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
@@ -19,7 +18,7 @@ struct MigrationInfo {
|
|||||||
revision: i32,
|
revision: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const LATEST_REVISION: i32 = 26;
|
pub const LATEST_REVISION: i32 = 27;
|
||||||
|
|
||||||
pub async fn migrate_database(db: &MongoDb) {
|
pub async fn migrate_database(db: &MongoDb) {
|
||||||
let migrations = db.col::<Document>("migrations");
|
let migrations = db.col::<Document>("migrations");
|
||||||
@@ -983,6 +982,56 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
|
|||||||
.expect("Failed to create ratelimit_events index.");
|
.expect("Failed to create ratelimit_events index.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if revision <= 26 {
|
||||||
|
info!("Running migration [revision 26 / 15-05-2024]: fix invites being incorrectly serialized with wrong enum tagging.");
|
||||||
|
|
||||||
|
auto_derived!(
|
||||||
|
pub enum OldInvite {
|
||||||
|
Server {
|
||||||
|
#[serde(rename = "_id")]
|
||||||
|
code: String,
|
||||||
|
server: String,
|
||||||
|
creator: String,
|
||||||
|
channel: String,
|
||||||
|
},
|
||||||
|
Group {
|
||||||
|
#[serde(rename = "_id")]
|
||||||
|
code: String,
|
||||||
|
creator: String,
|
||||||
|
channel: String,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut invites = db.db()
|
||||||
|
.collection::<OldInvite>("channel_invites")
|
||||||
|
.find(doc! {
|
||||||
|
"type": { "$exists": false }
|
||||||
|
}, None)
|
||||||
|
.await
|
||||||
|
.expect("failed to find invites");
|
||||||
|
|
||||||
|
while let Some(Ok(invite)) = invites.next().await {
|
||||||
|
let new_invite = match invite {
|
||||||
|
OldInvite::Server { code, server, creator, channel } => Invite::Server { code, server, creator, channel },
|
||||||
|
OldInvite::Group { code, creator, channel } => Invite::Group { code, creator, channel }
|
||||||
|
};
|
||||||
|
|
||||||
|
db.db()
|
||||||
|
.collection("channel_invites")
|
||||||
|
.replace_one(doc! { "$or": [
|
||||||
|
{
|
||||||
|
"Server._id": new_invite.code()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Group._id": new_invite.code()
|
||||||
|
}
|
||||||
|
]}, new_invite, None)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Need to migrate fields on attachments, change `user_id`, `object_id`, etc to `parent`.
|
// Need to migrate fields on attachments, change `user_id`, `object_id`, etc to `parent`.
|
||||||
|
|
||||||
// Reminder to update LATEST_REVISION when adding new migrations.
|
// Reminder to update LATEST_REVISION when adding new migrations.
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ static ALPHABET: [char; 54] = [
|
|||||||
|
|
||||||
auto_derived!(
|
auto_derived!(
|
||||||
/// Invite
|
/// Invite
|
||||||
|
#[serde(tag = "type")]
|
||||||
pub enum Invite {
|
pub enum Invite {
|
||||||
/// Invite to a specific server channel
|
/// Invite to a specific server channel
|
||||||
Server {
|
Server {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use super::{Channel, File, Server, User};
|
|||||||
|
|
||||||
auto_derived!(
|
auto_derived!(
|
||||||
/// Invite
|
/// Invite
|
||||||
|
#[serde(tag = "type")]
|
||||||
pub enum Invite {
|
pub enum Invite {
|
||||||
/// Invite to a specific server channel
|
/// Invite to a specific server channel
|
||||||
Server {
|
Server {
|
||||||
|
|||||||
Reference in New Issue
Block a user