-
Notifications
You must be signed in to change notification settings - Fork 9
chore: grouped prompt-enhancer-percentage and criteria check under ai… #880
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
Open
Anushtha-Rathore
wants to merge
2
commits into
Walkover-Web-Solution:testing
Choose a base branch
from
Anushtha-Rathore:ai-updates-field
base: testing
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { MongoClient } from "mongodb"; | ||
| import dotenv from "dotenv"; | ||
| dotenv.config(); | ||
| /** | ||
| * Migration script for ai_updates field reorganization | ||
| * Moves prompt_enhancer_percentage and criteria_check into ai_updates object for configurations only | ||
| */ | ||
|
|
||
| const MONGODB_CONNECTION_URI = process.env.MONGODB_CONNECTION_URI; | ||
|
|
||
| async function migrateAiUpdatesField() { | ||
| const client = new MongoClient(MONGODB_CONNECTION_URI); | ||
|
|
||
| try { | ||
| await client.connect(); | ||
| console.log("Connected to MongoDB"); | ||
|
|
||
| const db = client.db(); | ||
| const collectionsToMigrate = ["configurations", "configuration_versions"]; | ||
|
|
||
| for (const collectionName of collectionsToMigrate) { | ||
| const collection = db.collection(collectionName); | ||
| console.log(`\nStarting migration for ${collectionName}...`); | ||
|
|
||
| const cursor = collection.find({}); | ||
| const batch = []; | ||
| let processed = 0; | ||
|
|
||
| for await (const doc of cursor) { | ||
| processed++; | ||
|
|
||
| // Skip if ai_updates already exists | ||
| if (doc.ai_updates) { | ||
| console.log(`Skipping document ${doc._id} in ${collectionName} - ai_updates already exists`); | ||
| continue; | ||
| } | ||
|
|
||
| // Create ai_updates object from existing fields | ||
| const ai_updates = { | ||
| prompt_enhancer_percentage: doc.prompt_enhancer_percentage || 0, | ||
| criteria_check: doc.criteria_check || {} | ||
| }; | ||
|
|
||
| const updateOp = { | ||
| $set: { ai_updates: ai_updates }, | ||
| $unset: { | ||
| prompt_enhancer_percentage: 1, | ||
| criteria_check: 1 | ||
| } | ||
| }; | ||
|
|
||
| batch.push({ | ||
| updateOne: { | ||
| filter: { _id: doc._id }, | ||
| update: updateOp | ||
| } | ||
| }); | ||
|
|
||
| // Process batch every 100 documents | ||
| if (batch.length >= 100) { | ||
| await collection.bulkWrite(batch); | ||
| console.log(`Processed batch of ${batch.length} documents in ${collectionName} (total: ${processed})`); | ||
| batch.length = 0; // Clear batch | ||
| } | ||
| } | ||
|
|
||
| // Process remaining documents | ||
| if (batch.length > 0) { | ||
| await collection.bulkWrite(batch); | ||
| console.log(`Processed final batch of ${batch.length} documents in ${collectionName} (total: ${processed})`); | ||
| } | ||
|
|
||
| console.log(`Migration for ${collectionName} completed. Processed ${processed} documents.`); | ||
|
|
||
| // Verification - count documents with ai_updates | ||
| const count = await collection.countDocuments({ ai_updates: { $exists: true } }); | ||
|
|
||
| console.log(`\n=== Migration Summary for ${collectionName} ===`); | ||
| console.log(`Documents with ai_updates: ${count}`); | ||
|
|
||
| // Verify old fields are removed | ||
| const oldCount = await collection.countDocuments({ | ||
| $or: [{ prompt_enhancer_percentage: { $exists: true } }, { criteria_check: { $exists: true } }] | ||
| }); | ||
|
|
||
| console.log(`Documents with old fields remaining: ${oldCount}`); | ||
|
|
||
| if (oldCount === 0) { | ||
| console.log(`✅ Migration for ${collectionName} completed successfully!`); | ||
| } else { | ||
| console.log(`⚠️ Some old fields remain in ${collectionName} - manual cleanup may be required`); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| console.error("Migration failed:", error); | ||
| throw error; | ||
| } finally { | ||
| await client.close(); | ||
| } | ||
| } | ||
|
|
||
| // Run migration if this file is executed directly | ||
| if (require.main === module) { | ||
| migrateAiUpdatesField() | ||
| .then(() => { | ||
| console.log("Migration completed successfully"); | ||
| process.exit(0); | ||
| }) | ||
| .catch((error) => { | ||
| console.error("Migration failed:", error); | ||
| process.exit(1); | ||
| }); | ||
| } | ||
|
|
||
| module.exports = { migrateAiUpdatesField }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.