[752] eat(scripts): add MongoDB data migration script for testimonials and table widgets - #200
Conversation
📝 Walkthrough""" WalkthroughA new migration script was added to the website project to convert certain MongoDB document fields from rich content objects to plain strings. Additionally, a utility module and corresponding tests were introduced to support this migration. The project's Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Script
participant MongoDB
User->>Script: Run migration script with URI and DB name
Script->>MongoDB: Connect to database
Script->>MongoDB: Find testimonial documents with object feedback
loop Each testimonial batch
Script->>MongoDB: Update feedback field to string
end
Script->>MongoDB: Find table widget documents with object description in rows
loop Each table widget batch
Script->>MongoDB: Update description field to string
end
Script->>MongoDB: Close connection
Script->>User: Output migration results
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (6)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 7
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
website/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (2)
website/package.json(1 hunks)website/scripts/migrate-field-type.js(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.{js,jsx}`: Use 2 spaces for indentation Maximum line length: 80 characters...
**/*.{js,jsx}: Use 2 spaces for indentation
Maximum line length: 80 characters
Use semicolons at the end of statements
Use single quotes for strings
Add trailing commas in arrays, objects, etc.
No trailing spaces
Use consistent quote properties (either quote all properties or none)
Place line comments above code, not inline
Capitalize all comments
No inline comments
Maximum function length enforced (avoid excessive length)
Maximum depth: 4 levels
Maximum callback nesting: 3 levels
Maximum parameters: 5
Maximum statements per function: 50
Use function declarations with named functions, not function expressions
Always initialize variables at declaration
Maximum lines per file: 300
Use destructuring where possible
Minimum identifier length enforced (no single-letter variables)
No unused variables
No reassignment of function parameters
No invalid 'this' context
No duplicate object keys
No ternary operators (use if/else)
Maximum complexity: 15 (cognitive complexity)
No alerts or console logs
No debugger statements
No identical expressions in conditions
Use optimized regex patterns
Use Unicode regex patterns
No secrets in code
No unsanitized methods or properties (XSS prevention)
Sort imports alphabetically
No unresolved imports
No importing default from a module that doesn't have a default export
Always return in promise chains
📄 Source: CodeRabbit Inference Engine (.cursor/rules/code-conventions.mdc)
List of files the instruction was applied to:
website/scripts/migrate-field-type.js
`**/*.js`: No missing imports in Node.js No missing require statements
**/*.js: No missing imports in Node.js
No missing require statements
📄 Source: CodeRabbit Inference Engine (.cursor/rules/code-conventions.mdc)
List of files the instruction was applied to:
website/scripts/migrate-field-type.js
🧠 Learnings (1)
📓 Common learnings
Learnt from: yuramax
PR: speedandfunction/website#120
File: website/modules/asset/ui/src/index.js:43-67
Timestamp: 2025-05-26T06:19:32.209Z
Learning: When reviewing PRs focused on styling, defer functional JavaScript improvements to separate tasks to maintain clear scope separation.
🪛 Biome (1.9.4)
website/scripts/migrate-field-type.js
[error] 45-45: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: lint
- GitHub Check: unit-tests
- GitHub Check: security-scan
- GitHub Check: e2e-tests
- GitHub Check: Analyze (actions)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
website/package.json (1)
53-53: Dependency version and audit verification
- mongodb@^6.17.0 is up-to-date (npm info shows v6.17.0).
- yargs@^17.7.2 is behind the latest major release (npm info shows v18.0.0). Consider upgrading to ^18.0.0 if there are no breaking-change conflicts.
- No lockfile was detected under
website/, sonpm auditcould not run. Please commit a lockfile (package-lock.jsonoryarn.lock), runnpm audit(oryarn audit), and address any vulnerabilities before merging.website/scripts/migrate-field-type.js (2)
1-17: LGTM! Clean import structure and argument parsing.The imports are properly sorted alphabetically and the yargs configuration provides clear, required command-line arguments with help text.
153-165: Improve error handling and add process exit codes.The main execution block should handle errors more gracefully and use appropriate exit codes.
if (require.main === module) { - (async function () { + (async () => { try { const testimonials = await migrateTestimonialFeedbackToString(); process.stdout.write(`Updated testimonials: ${testimonials}\n`); const tables = await migrateTableDescriptions(); process.stdout.write(`Updated table rows: ${tables}\n`); + process.exit(0); } catch (error) { - process.stdout.write(`Migration error: ${error}\n`); - throw error; + process.stderr.write(`Migration error: ${error.message}\n`); + process.exit(1); } })(); }⛔ Skipped due to learnings
Learnt from: killev PR: speedandfunction/website#21 File: scripts/merged-prs-last-24h.js:0-0 Timestamp: 2025-04-22T06:57:44.687Z Learning: For console scripts like merged-prs-last-24h.js, the preferred approach is to allow fatal errors rather than implementing explicit error handling with try-catch blocks, as this makes errors more visible and provides complete stack traces for debugging.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
website/scripts/migrate-field-type.utils.js (3)
24-24: Consider using optional chaining for safer property access.The static analysis tool correctly identifies that optional chaining would be more concise and safe here.
- if (areaData && areaData.items && areaData.items.length > 0) { + if (areaData?.items?.length > 0) {
26-26: Use arrow function for consistency.The coding guidelines emphasize consistency, and arrow functions would be more consistent with the project style.
- .map(function (item) { + .map((item) => {
88-93: Add missing semicolons to comply with coding guidelines.The coding guidelines require semicolons at the end of statements.
module.exports = { stripHtml, areaToString, updateTestimonialFeedback, updateTableRowsDescriptions, -}; +};
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
website/scripts/migrate-field-type.js(1 hunks)website/scripts/migrate-field-type.test.js(1 hunks)website/scripts/migrate-field-type.utils.js(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- website/scripts/migrate-field-type.js
🧰 Additional context used
📓 Path-based instructions (3)
`**/*.{js,jsx}`: Use 2 spaces for indentation Maximum line length: 80 characters...
**/*.{js,jsx}: Use 2 spaces for indentation
Maximum line length: 80 characters
Use semicolons at the end of statements
Use single quotes for strings
Add trailing commas in arrays, objects, etc.
No trailing spaces
Use consistent quote properties (either quote all properties or none)
Place line comments above code, not inline
Capitalize all comments
No inline comments
Maximum function length enforced (avoid excessive length)
Maximum depth: 4 levels
Maximum callback nesting: 3 levels
Maximum parameters: 5
Maximum statements per function: 50
Use function declarations with named functions, not function expressions
Always initialize variables at declaration
Maximum lines per file: 300
Use destructuring where possible
Minimum identifier length enforced (no single-letter variables)
No unused variables
No reassignment of function parameters
No invalid 'this' context
No duplicate object keys
No ternary operators (use if/else)
Maximum complexity: 15 (cognitive complexity)
No alerts or console logs
No debugger statements
No identical expressions in conditions
Use optimized regex patterns
Use Unicode regex patterns
No secrets in code
No unsanitized methods or properties (XSS prevention)
Sort imports alphabetically
No unresolved imports
No importing default from a module that doesn't have a default export
Always return in promise chains
📄 Source: CodeRabbit Inference Engine (.cursor/rules/code-conventions.mdc)
List of files the instruction was applied to:
website/scripts/migrate-field-type.test.jswebsite/scripts/migrate-field-type.utils.js
`**/*.js`: No missing imports in Node.js No missing require statements
**/*.js: No missing imports in Node.js
No missing require statements
📄 Source: CodeRabbit Inference Engine (.cursor/rules/code-conventions.mdc)
List of files the instruction was applied to:
website/scripts/migrate-field-type.test.jswebsite/scripts/migrate-field-type.utils.js
`**/*.test.{js,jsx}`: Test files have relaxed rules for function length, statements, extraneous requires, and destructuring
**/*.test.{js,jsx}: Test files have relaxed rules for function length, statements, extraneous requires, and destructuring
📄 Source: CodeRabbit Inference Engine (.cursor/rules/code-conventions.mdc)
List of files the instruction was applied to:
website/scripts/migrate-field-type.test.js
🧠 Learnings (1)
website/scripts/migrate-field-type.test.js (2)
Learnt from: CR
PR: speedandfunction/website#0
File: .cursor/rules/code-conventions.mdc:0-0
Timestamp: 2025-07-01T07:44:33.034Z
Learning: Applies to **/*.test.{js,jsx} : Test files have relaxed rules for function length, statements, extraneous requires, and destructuring
Learnt from: CR
PR: speedandfunction/website#0
File: .cursor/rules/code-conventions.mdc:0-0
Timestamp: 2025-07-01T07:44:33.034Z
Learning: Applies to **/*.e2e.{js,jsx} : E2E test files: relaxed import, ternary, and sorting rules
🪛 Biome (1.9.4)
website/scripts/migrate-field-type.utils.js
[error] 24-24: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: e2e-tests
- GitHub Check: lint
- GitHub Check: unit-tests
- GitHub Check: security-scan
🔇 Additional comments (1)
website/scripts/migrate-field-type.test.js (1)
1-107: Excellent test coverage and structure.The test suite comprehensively covers all utility functions with proper edge case handling and database mocking. The tests are well-organized and follow good testing practices by verifying both positive and negative scenarios.
- Refactor main functions to accept mongoUri and dbName as parameters - Move yargs and argument parsing into main block - Export internal functions for direct testing - Add and update tests for new function signatures and exports - Mock MongoDB client in tests for isolation
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
website/scripts/migrate-field-type.js (1)
77-92: Consider adding validation for MongoDB URI format.The script accepts any string as
mongoUribut should validate that it's a valid MongoDB connection string to prevent runtime errors.const { argv } = yargs(hideBin(process.argv)) .option('mongoUri', { describe: 'MongoDB connection URI', type: 'string', demandOption: true, + coerce: (uri) => { + if (!uri.startsWith('mongodb://') && !uri.startsWith('mongodb+srv://')) { + throw new Error('Invalid MongoDB URI format'); + } + return uri; + }, })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
website/scripts/migrate-field-type.js(1 hunks)website/scripts/migrate-field-type.test.js(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- website/scripts/migrate-field-type.test.js
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.{js,jsx}`: Use 2 spaces for indentation Maximum line length: 80 characters...
**/*.{js,jsx}: Use 2 spaces for indentation
Maximum line length: 80 characters
Use semicolons at the end of statements
Use single quotes for strings
Add trailing commas in arrays, objects, etc.
No trailing spaces
Use consistent quote properties (either quote all properties or none)
Place line comments above code, not inline
Capitalize all comments
No inline comments
Maximum function length enforced (avoid excessive length)
Maximum depth: 4 levels
Maximum callback nesting: 3 levels
Maximum parameters: 5
Maximum statements per function: 50
Use function declarations with named functions, not function expressions
Always initialize variables at declaration
Maximum lines per file: 300
Use destructuring where possible
Minimum identifier length enforced (no single-letter variables)
No unused variables
No reassignment of function parameters
No invalid 'this' context
No duplicate object keys
No ternary operators (use if/else)
Maximum complexity: 15 (cognitive complexity)
No alerts or console logs
No debugger statements
No identical expressions in conditions
Use optimized regex patterns
Use Unicode regex patterns
No secrets in code
No unsanitized methods or properties (XSS prevention)
Sort imports alphabetically
No unresolved imports
No importing default from a module that doesn't have a default export
Always return in promise chains
📄 Source: CodeRabbit Inference Engine (.cursor/rules/code-conventions.mdc)
List of files the instruction was applied to:
website/scripts/migrate-field-type.js
`**/*.js`: No missing imports in Node.js No missing require statements
**/*.js: No missing imports in Node.js
No missing require statements
📄 Source: CodeRabbit Inference Engine (.cursor/rules/code-conventions.mdc)
List of files the instruction was applied to:
website/scripts/migrate-field-type.js
🧠 Learnings (1)
website/scripts/migrate-field-type.js (11)
Learnt from: killev
PR: speedandfunction/website#21
File: scripts/merged-prs-last-24h.js:0-0
Timestamp: 2025-04-22T06:57:44.687Z
Learning: For console scripts like merged-prs-last-24h.js, the preferred approach is to allow fatal errors rather than implementing explicit error handling with try-catch blocks, as this makes errors more visible and provides complete stack traces for debugging.
Learnt from: CR
PR: speedandfunction/website#0
File: .cursor/rules/code-conventions.mdc:0-0
Timestamp: 2025-07-01T07:44:33.034Z
Learning: Applies to **/*.{js,jsx} : Use function declarations with named functions, not function expressions
Learnt from: yuramax
PR: speedandfunction/website#120
File: website/modules/asset/ui/src/index.js:43-67
Timestamp: 2025-05-26T06:19:32.209Z
Learning: When reviewing PRs focused on styling, defer functional JavaScript improvements to separate tasks to maintain clear scope separation.
Learnt from: CR
PR: speedandfunction/website#0
File: .cursor/rules/code-conventions.mdc:0-0
Timestamp: 2025-07-01T07:44:33.034Z
Learning: Applies to **/*.{js,jsx} : Use destructuring where possible
Learnt from: CR
PR: speedandfunction/website#0
File: .cursor/rules/code-conventions.mdc:0-0
Timestamp: 2025-07-01T07:44:33.034Z
Learning: Applies to modules/asset/ui/src/index.js : modules/asset/ui/src/index.js: relaxed function lines and style rules
Learnt from: CR
PR: speedandfunction/website#0
File: .cursor/rules/code-conventions.mdc:0-0
Timestamp: 2025-07-01T07:44:33.034Z
Learning: Applies to modules/@apostrophecms/form/index.js : modules/@apostrophecms/form/index.js: relaxed maximum lines rule
Learnt from: CR
PR: speedandfunction/website#0
File: .cursor/rules/code-conventions.mdc:0-0
Timestamp: 2025-07-01T07:44:33.034Z
Learning: Applies to app.js : app.js: relaxed rules for function lines, function style, and quote properties
Learnt from: CR
PR: speedandfunction/website#0
File: .cursor/rules/code-conventions.mdc:0-0
Timestamp: 2025-07-01T07:44:33.034Z
Learning: Applies to **/*.{js,jsx} : Use single quotes for strings
Learnt from: IhorMasechko
PR: speedandfunction/website#154
File: website/modules/case-studies-page/services/UrlService.js:102-116
Timestamp: 2025-06-09T16:52:54.510Z
Learning: When reviewing ApostropheCMS code, eslint-disable comments for `no-underscore-dangle` are often necessary and appropriate when accessing framework-provided properties like `_url`, as they conflict with general JavaScript linting rules but follow ApostropheCMS conventions.
Learnt from: CR
PR: speedandfunction/website#0
File: .cursor/rules/code-conventions.mdc:0-0
Timestamp: 2025-07-01T07:44:33.034Z
Learning: Applies to **/*.{js,jsx} : Maximum complexity: 15 (cognitive complexity)
Learnt from: CR
PR: speedandfunction/website#0
File: .cursor/rules/code-conventions.mdc:0-0
Timestamp: 2025-07-01T07:44:33.034Z
Learning: Applies to modules/asset/ui/src/swipers.js : modules/asset/ui/src/swipers.js: relaxed import rules
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: security-scan
- GitHub Check: e2e-tests
- GitHub Check: lint
- GitHub Check: unit-tests
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
website/scripts/migrate-field-type.js (4)
97-110: Approve the error handling approach for console scripts.The error handling follows the preferred pattern for console scripts by allowing fatal errors to bubble up while providing informative output.
113-122: Good module export structure.The exports provide good modularity and testability by exposing all necessary functions including utility functions imported from the separate module.
1-7: Import paths and module exports verifiedThe file
website/scripts/migrate-field-type.utils.jsexists and itsmodule.exportsincludesstripHtml,areaToString,updateTestimonialFeedback, andupdateTableRowsDescriptions, matching the imports inmigrate-field-type.js. No changes required.
9-18: Add error handling for database connection.The
getCollectionfunction should include error handling for database connection failures to provide better debugging information and prevent resource leaks.const getCollection = async ( mongoUri = 'mongodb://localhost:27017', dbName = 'test', ) => { const client = new MongoClient(mongoUri); - await client.connect(); + try { + await client.connect(); + } catch (error) { + throw new Error(`Failed to connect to MongoDB: ${error.message}`); + } const db = client.db(dbName); const collection = db.collection('aposDocs'); return { client, collection }; };⛔ Skipped due to learnings
Learnt from: killev PR: speedandfunction/website#21 File: scripts/merged-prs-last-24h.js:0-0 Timestamp: 2025-04-22T06:57:44.687Z Learning: For console scripts like merged-prs-last-24h.js, the preferred approach is to allow fatal errors rather than implementing explicit error handling with try-catch blocks, as this makes errors more visible and provides complete stack traces for debugging.
- Replace verbose areaData && areaData.items && areaData.items.length > 0 check - Use areaData?.items?.length > 0 for conciseness and readability
- Update feedback update check to require non-empty string instead of strict inequality
|



Uh oh!
There was an error while loading. Please reload this page.