-
Notifications
You must be signed in to change notification settings - Fork 185
feat: change mid to string array #745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9bd708d
0453ffb
fbd630c
d7f9ecd
b86fbe7
6ecfbc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright © 2024 Hexastack. All rights reserved. | ||
| * Copyright © 2025 Hexastack. All rights reserved. | ||
| * | ||
| * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: | ||
| * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. | ||
|
|
@@ -20,11 +20,11 @@ import { StdIncomingMessage, StdOutgoingMessage } from './types/message'; | |
| @Schema({ timestamps: true }) | ||
| export class MessageStub extends BaseSchema { | ||
| @Prop({ | ||
| type: String, | ||
| type: [String], | ||
| required: false, | ||
| //TODO : add default value for mid | ||
| }) | ||
| mid?: string; | ||
| mid?: string | string[]; | ||
|
Comment on lines
+23
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix schema type inconsistency. There's a mismatch between the Mongoose schema definition and TypeScript type:
This could cause runtime errors when saving string values. Apply this diff to fix the schema definition: @Prop({
- type: [String],
+ type: MongooseSchema.Types.Mixed,
required: false,
//TODO : add default value for mid
})Or use a custom schema type that handles both cases: @Prop({
- type: [String],
+ type: MongooseSchema.Types.Mixed,
+ validate: {
+ validator: function(v: any) {
+ return typeof v === 'string' || (Array.isArray(v) && v.every(item => typeof item === 'string'));
+ },
+ message: 'mid must be a string or array of strings'
+ },
required: false,
//TODO : add default value for mid
})🤖 Prompt for AI Agents |
||
|
|
||
| @Prop({ | ||
| type: MongooseSchema.Types.ObjectId, | ||
|
|
@@ -96,9 +96,12 @@ export class MessageFull extends MessageStub { | |
| sentBy?: string; // sendBy is never populate | ||
| } | ||
|
|
||
| const MessageSchema = SchemaFactory.createForClass(MessageStub); | ||
| MessageSchema.index({ mid: 1 }); | ||
|
Comment on lines
+99
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainConsider database migration strategy. The schema change from string to array may require migrating existing data. Verify how existing messages with string 🏁 Script executed: #!/bin/bash
# Description: Check for existing database migration scripts or strategies
# Expected: Migration scripts should handle converting string mid to array format
fd -e js -e ts migration | xargs grep -l "mid\|message"Length of output: 204 🏁 Script executed: #!/bin/bash
# Inspect migration files for handling of converting string mid to array
# 1. Show occurrences of 'mid' in all migration-related code
grep -R "mid" -n api/src/migration
# 2. Show occurrences of 'message' in the specific versioned migration
grep -R "message" -n api/src/migration/migrations/1735836154221-v-2-2-0.migration.ts
# 3. Dump the first 200 lines of the migration to review its up/down logic
sed -n '1,200p' api/src/migration/migrations/1735836154221-v-2-2-0.migration.tsLength of output: 9834 Add migration to convert existing message.mid values from string to array We didn’t find any migration handling the • File: // Convert string mid to array
const MessageModel = mongoose.model<Message>(Message.name, messageSchema);
await MessageModel.updateMany(
{ mid: { $type: 'string' } },
[
{ $set: { mid: { $cond: { if: { $isArray: '$mid' }, then: '$mid', else: ['$mid'] } } } }
]
);
logger.log('Migrated string mid to array for existing messages');🤖 Prompt for AI Agents |
||
|
|
||
| export const MessageModel: ModelDefinition = LifecycleHookManager.attach({ | ||
| name: Message.name, | ||
| schema: SchemaFactory.createForClass(MessageStub), | ||
| schema: MessageSchema, | ||
| }); | ||
|
|
||
| export default MessageModel.schema; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix validation decorator for union type.
The
@IsString()decorator only validates string types, but themidproperty now acceptsstring | string[]. This will cause validation failures whenmidis provided as an array.Apply this diff to fix the validation:
Or use a custom validation approach:
🤖 Prompt for AI Agents