Sfoglia il codice sorgente

Add migration script for rollback

Shun Miyazawa 10 mesi fa
parent
commit
5bce22f23f

+ 11 - 2
apps/app/src/migrations/20250522105040-delete-old-index-for-vector-store-file-relation.js

@@ -32,7 +32,16 @@ module.exports = {
     await collection.createIndex({ vectorStoreRelationId: 1, page: 1, attachment: 1 }, { unique: true });
 
   },
-  async down() {
-    // No rollback
+  async down(db) {
+    logger.info('Rollback migration');
+
+    await mongoose.connect(getMongoUri(), mongoOptions);
+
+    // Drop new index
+    await dropIndexIfExists(db, 'vectorstorefilerelations', 'vectorStoreRelationId_1_page_1_attachment_1');
+
+    // Recreate old index
+    const collection = mongoose.connection.collection('vectorstorefilerelations');
+    await collection.createIndex({ vectorStoreRelationId: 1, page: 1 }, { unique: true });
   },
 };