Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: DB migration error (revision 29) #378

Closed
TyraVex opened this issue Oct 29, 2024 · 2 comments
Closed

bug: DB migration error (revision 29) #378

TyraVex opened this issue Oct 29, 2024 · 2 comments

Comments

@TyraVex
Copy link

TyraVex commented Oct 29, 2024

What happened?

Hi, i'd like to report that my revolt DB crashes the program;

revolt-backend-1  |  INFO  revolt_database::models::admin_migrations::ops::mongodb::scripts > Starting database migration.
revolt-backend-1  |  INFO  revolt_database::models::admin_migrations::ops::mongodb::scripts > Running migration [revision 29 / 29-09-2024]: Add creator_id to webhooks.
revolt-backend-1  | thread 'main' panicked at crates/core/database/src/models/admin_migrations/ops/mongodb/scripts.rs:1162:70:
revolt-backend-1  | channel: Error { error_type: NotFound, location: "crates/core/database/src/models/channels/ops/mongodb.rs:19:70" }
revolt-backend-1  | stack backtrace:
revolt-backend-1  |    0:     0xaaaaba9a0ccc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hece1148e1500c9a2
revolt-backend-1  |    1:     0xaaaaba9c98dc - core::fmt::write::hb4e3acbf271edb44
revolt-backend-1  |    2:     0xaaaaba99cd4c - std::io::Write::write_fmt::h8ca942adea865c1e
revolt-backend-1  |    3:     0xaaaaba9a0af8 - std::sys_common::backtrace::print::h2b12b67a16e9135f
revolt-backend-1  |    4:     0xaaaaba9a26ac - std::panicking::default_hook::{{closure}}::hf72040aae8f7970a
revolt-backend-1  |    5:     0xaaaaba9a23e0 - std::panicking::default_hook::hff2a626330bfd796
revolt-backend-1  |    6:     0xaaaaba9a2b38 - std::panicking::rust_panic_with_hook::hdbe957ea7e1caf24
revolt-backend-1  |    7:     0xaaaaba9a29e8 - std::panicking::begin_panic_handler::{{closure}}::h5f3c13bf100f9a71
revolt-backend-1  |    8:     0xaaaaba9a119c - std::sys_common::backtrace::__rust_end_short_backtrace::hd8a0426804ef2ca9
revolt-backend-1  |    9:     0xaaaaba9a2788 - rust_begin_unwind
revolt-backend-1  |   10:     0xaaaab8ddd084 - core::panicking::panic_fmt::heae5498d3da202ba
revolt-backend-1  |   11:     0xaaaab8ddd408 - core::result::unwrap_failed::h4905b9ac24a3608b
revolt-backend-1  |   12:     0xaaaab95b08e8 - revolt_database::models::admin_migrations::ops::mongodb::scripts::run_migrations::{{closure}}::h047c459fe8c17af0
revolt-backend-1  |   13:     0xaaaab95ce8d4 - revolt_database::models::admin_migrations::ops::mongodb::<impl revolt_database::models::admin_migrations::ops::AbstractMigrations for revolt_database::drivers::mongodb::MongoDb>::migrate_database::{{closure}}::he411f323f1824aa2
revolt-backend-1  |   14:     0xaaaab8fcbe44 - revolt_delta::main::{{closure}}::heff0a7c2cf7a0cff
revolt-backend-1  |   15:     0xaaaab8f8e5f8 - tokio::runtime::park::CachedParkThread::block_on::h065369aa2639cfb7
revolt-backend-1  |   16:     0xaaaab91252c8 - tokio::runtime::context::runtime::enter_runtime::h4ff13e35583c7f26
revolt-backend-1  |   17:     0xaaaab921ec44 - rocket::async_main::h06ea71ab3d9ca49c
revolt-backend-1  |   18:     0xaaaab936c668 - revolt_delta::main::h2d0f010ccf78b968
revolt-backend-1  |   19:     0xaaaab91f5174 - std::sys_common::backtrace::__rust_begin_short_backtrace::h852d72e574290f5b
revolt-backend-1  |   20:     0xaaaab91f5188 - std::rt::lang_start::{{closure}}::hfe5377c0416d568e
revolt-backend-1  |   21:     0xaaaaba994fc4 - std::rt::lang_start_internal::h0ddfe42b2029814a
revolt-backend-1  |   22:     0xaaaab936c6a0 - main
revolt-backend-1  |   23:     0xffffbbef7780 - <unknown>
revolt-backend-1  |   24:     0xffffbbef7858 - __libc_start_main
revolt-backend-1  |   25:     0xaaaab8ddd6f0 - _start
revolt-backend-1  |   26:                0x0 - <unknown>

Is there any way to fix this? It happens with every db I tried

@TyraVex TyraVex added the bug label Oct 29, 2024
@github-project-automation github-project-automation bot moved this to 🆕 Untriaged in Revolt Project Oct 29, 2024
@TyraVex
Copy link
Author

TyraVex commented Oct 30, 2024

Temporary hacky workaround with sonnet

diff --git a/crates/core/database/src/models/admin_migrations/ops/mongodb/scripts.rs b/crates/core/database/src/models/admin_migrations/ops/mongodb/scripts.rs
index 5a22cd6..d08f6de 100644
--- a/crates/core/database/src/models/admin_migrations/ops/mongodb/scripts.rs
+++ b/crates/core/database/src/models/admin_migrations/ops/mongodb/scripts.rs
@@ -1148,7 +1148,7 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
             channel_id: String,
         }

-        let invites = db
+        let webhooks = db
             .db()
             .collection::<WebhookShell>("channel_webhooks")
             .find(doc! {}, None)
@@ -1158,22 +1158,38 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
             .collect::<Vec<WebhookShell>>()
             .await;

-        for invite in invites {
-            let channel = db.fetch_channel(&invite.channel_id).await.expect("channel");
+        for webhook in webhooks {
+            let channel = match db.fetch_channel(&webhook.channel_id).await {
+                Ok(channel) => channel,
+                Err(_) => {
+                    info!("Skipping webhook {} - channel {} not found", webhook._id, webhook.channel_id);
+                    continue;
+                }
+            };
+
             let creator_id = match channel {
                 Channel::Group { owner, .. } => owner,
                 Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => {
-                    let server = db.fetch_server(&server).await.expect("server");
+                    let server = match db.fetch_server(&server).await {
+                        Ok(server) => server,
+                        Err(_) => {
+                            info!("Skipping webhook {} - server not found", webhook._id);
+                            continue;
+                        }
+                    };
                     server.owner
                 }
-                _ => unreachable!("not server or group channel!"),
+                _ => {
+                    info!("Skipping webhook {} - invalid channel type", webhook._id);
+                    continue;
+                }
             };

             db.db()
                 .collection::<Document>("channel_webhooks")
                 .update_one(
                     doc! {
-                        "_id": invite._id,
+                        "_id": webhook._id,
                     },
                     doc! {
                         "$set" : {
revolt-backend-1  |  INFO  revolt_database::models::admin_migrations::ops::mongodb > Migrating the database.                                      
revolt-backend-1  |  INFO  revolt_database::models::admin_migrations::ops::mongodb::scripts > Starting database migration.                        
revolt-backend-1  |  INFO  revolt_database::models::admin_migrations::ops::mongodb::scripts > Running migration [revision 29 / 29-09-2024]: Add creator_id to webhooks.                                                                                                                             
revolt-backend-1  |  INFO  revolt_database::models::admin_migrations::ops::mongodb::scripts > Skipping webhook 01J4852032H9FZJC064773ZH0N - channel 01J484SAMGS3JS05WJ0KFMX4NE not found                                                                                                            
revolt-backend-1  |  INFO  revolt_database::models::admin_migrations::ops::mongodb::scripts > Running migration [revision 30 / 29-09-2024]: Add index for used_for.id to attachments.                                                                                                               
revolt-backend-1  |  INFO  revolt_database::models::admin_migrations::ops::mongodb::scripts > Migration complete. Currently at revision 30.       

@insertish
Copy link
Member

Definitely won't be another channel type but I've updated the migration to support missing channels.

@github-project-automation github-project-automation bot moved this from 🆕 Untriaged to ✅ Done in Revolt Project Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants