fix: use partial index for status page customDomain
Replace the sparse unique index with a partial index so multiple status pages without a custom domain no longer collide on null values.
This commit is contained in:
1 parent
187c8eaba1
commit
0aef8b652f
3 files changed
+39
-9
No files matched your search
@@ -67,11 +67,8 @@ const StatusPageSchema = new Schema<StatusPageDocument>(
|
||||
},
|
||||
customDomain: {
|
||||
type: String,
|
||||
default: null,
|
||||
lowercase: true,
|
||||
trim: true,
|
||||
sparse: true,
|
||||
unique: true,
|
||||
},
|
||||
timezone: {
|
||||
type: String,
|
||||
@@ -136,6 +133,14 @@ const StatusPageSchema = new Schema<StatusPageDocument>(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
StatusPageSchema.index(
|
||||
{ customDomain: 1 },
|
||||
{
|
||||
unique: true,
|
||||
partialFilterExpression: { customDomain: { $type: "string" } },
|
||||
}
|
||||
);
|
||||
|
||||
const StatusPageModel = model<StatusPageDocument>("StatusPage", StatusPageSchema);
|
||||
|
||||
export type { StatusPageDocument };
|
||||
|
||||
Reference in new issue
Block a user