fix: broken index migration
feat: add new index
This commit is contained in:
@@ -108,6 +108,13 @@ pub async fn create_database() {
|
|||||||
"channel": 1
|
"channel": 1
|
||||||
},
|
},
|
||||||
"name": "channel"
|
"name": "channel"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"channel": 1,
|
||||||
|
"_id": 1
|
||||||
|
},
|
||||||
|
"name": "channel_id_compound"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -119,7 +126,7 @@ pub async fn create_database() {
|
|||||||
get_db()
|
get_db()
|
||||||
.run_command(
|
.run_command(
|
||||||
doc! {
|
doc! {
|
||||||
"createIndexes": "messages",
|
"createIndexes": "channel_unreads",
|
||||||
"indexes": [
|
"indexes": [
|
||||||
{
|
{
|
||||||
"key": {
|
"key": {
|
||||||
@@ -144,7 +151,7 @@ pub async fn create_database() {
|
|||||||
get_db()
|
get_db()
|
||||||
.run_command(
|
.run_command(
|
||||||
doc! {
|
doc! {
|
||||||
"createIndexes": "messages",
|
"createIndexes": "server_members",
|
||||||
"indexes": [
|
"indexes": [
|
||||||
{
|
{
|
||||||
"key": {
|
"key": {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ struct MigrationInfo {
|
|||||||
revision: i32,
|
revision: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const LATEST_REVISION: i32 = 12;
|
pub const LATEST_REVISION: i32 = 13;
|
||||||
|
|
||||||
pub async fn migrate_database() {
|
pub async fn migrate_database() {
|
||||||
let migrations = get_collection("migrations");
|
let migrations = get_collection("migrations");
|
||||||
@@ -396,7 +396,7 @@ pub async fn run_migrations(revision: i32) -> i32 {
|
|||||||
get_db()
|
get_db()
|
||||||
.run_command(
|
.run_command(
|
||||||
doc! {
|
doc! {
|
||||||
"createIndexes": "messages",
|
"createIndexes": "channel_unreads",
|
||||||
"indexes": [
|
"indexes": [
|
||||||
{
|
{
|
||||||
"key": {
|
"key": {
|
||||||
@@ -421,7 +421,7 @@ pub async fn run_migrations(revision: i32) -> i32 {
|
|||||||
get_db()
|
get_db()
|
||||||
.run_command(
|
.run_command(
|
||||||
doc! {
|
doc! {
|
||||||
"createIndexes": "messages",
|
"createIndexes": "server_members",
|
||||||
"indexes": [
|
"indexes": [
|
||||||
{
|
{
|
||||||
"key": {
|
"key": {
|
||||||
@@ -444,6 +444,29 @@ pub async fn run_migrations(revision: i32) -> i32 {
|
|||||||
.expect("Failed to create server_members index.");
|
.expect("Failed to create server_members index.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if revision <= 12 {
|
||||||
|
info!("Running migration [revision 12 / 2021-11-21]: Add indexes to database.");
|
||||||
|
|
||||||
|
get_db()
|
||||||
|
.run_command(
|
||||||
|
doc! {
|
||||||
|
"createIndexes": "messages",
|
||||||
|
"indexes": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"channel": 1,
|
||||||
|
"_id": 1
|
||||||
|
},
|
||||||
|
"name": "channel_id_compound"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("Failed to create message index.");
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
|||||||
Reference in New Issue
Block a user