Add a database migration for channel tag enum.

This commit is contained in:
Paul Makles
2021-01-19 21:11:38 +00:00
parent 81de29e723
commit 1d390d483d

View File

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