From 1d390d483dbf94a52c582d811c57dc105b28e28f Mon Sep 17 00:00:00 2001 From: Paul Makles <paulmakles@gmail.com> Date: Tue, 19 Jan 2021 21:11:38 +0000 Subject: [PATCH] Add a database migration for channel tag enum. --- src/database/migrations/scripts.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/database/migrations/scripts.rs b/src/database/migrations/scripts.rs index 4f57000..f952e74 100644 --- a/src/database/migrations/scripts.rs +++ b/src/database/migrations/scripts.rs @@ -12,7 +12,7 @@ struct MigrationInfo { revision: i32, } -pub const LATEST_REVISION: i32 = 3; +pub const LATEST_REVISION: i32 = 4; pub async fn migrate_database() { let migrations = get_collection("migrations"); @@ -148,6 +148,23 @@ pub async fn run_migrations(revision: i32) -> i32 { .expect("Failed to create username index."); } + if revision <= 3 { + info!("Running migration [revision 3]: Changed enum tag type to channel_type."); + + get_collection("channels") + .update_many( + doc! { }, + doc! { + "$rename": { + "type": "channel_type" + } + }, + None + ) + .await + .expect("Failed to migrate channel type."); + } + // Reminder to update LATEST_REVISION when adding new migrations. LATEST_REVISION } -- GitLab