server: Add missing unique indices on lowercase email/group names, fix memberof lookup

This commit is contained in:
Valentin Tolmer
2024-02-26 09:39:12 +01:00
committed by nitnelave
parent 959bb907d8
commit a1eb708cf3
5 changed files with 106 additions and 4 deletions

View File

@@ -1090,6 +1090,47 @@ async fn migrate_to_v9(transaction: DatabaseTransaction) -> Result<DatabaseTrans
Ok(transaction)
}
async fn migrate_to_v10(transaction: DatabaseTransaction) -> Result<DatabaseTransaction, DbErr> {
let builder = transaction.get_database_backend();
if let Err(e) = transaction
.execute(
builder.build(
Index::create()
.if_not_exists()
.name("unique-group-id")
.table(Groups::Table)
.col(Groups::LowercaseDisplayName)
.unique(),
),
)
.await
{
error!(
r#"Found several groups with the same (case-insensitive) display name. Please delete the duplicates"#
);
return Err(e);
}
if let Err(e) = transaction
.execute(
builder.build(
Index::create()
.if_not_exists()
.name("unique-user-lower-email")
.table(Users::Table)
.col(Users::LowercaseEmail)
.unique(),
),
)
.await
{
error!(
r#"Found several users with the same (case-insensitive) email. Please delete the duplicates"#
);
return Err(e);
}
Ok(transaction)
}
// This is needed to make an array of async functions.
macro_rules! to_sync {
($l:ident) => {
@@ -1119,6 +1160,7 @@ pub async fn migrate_from_version(
to_sync!(migrate_to_v7),
to_sync!(migrate_to_v8),
to_sync!(migrate_to_v9),
to_sync!(migrate_to_v10),
];
assert_eq!(migrations.len(), (LAST_SCHEMA_VERSION.0 - 1) as usize);
for migration in 2..=last_version.0 {