File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * Convert payload.release equal to string "null" into real null
3+ * across all per-project events collections (events:{projectId})
4+ */
5+ module . exports = {
6+ async up ( db ) {
7+ const collections = await db . listCollections ( ) . toArray ( ) ;
8+ const targetCollections = collections
9+ . map ( c => c . name )
10+ . filter ( name => name && name . startsWith ( 'events:' ) ) ;
11+
12+ console . log ( `Found ${ targetCollections . length } events collections to normalize "null" string to null` ) ;
13+
14+ for ( const name of targetCollections ) {
15+ const coll = db . collection ( name ) ;
16+
17+ try {
18+ const result = await coll . updateMany (
19+ { 'payload.release' : 'null' } ,
20+ { $set : { 'payload.release' : null } }
21+ ) ;
22+
23+ console . log ( `[${ name } ] matched=${ result . matchedCount } , modified=${ result . modifiedCount } ` ) ;
24+ } catch ( e ) {
25+ console . error ( `[${ name } ] failed to convert "null" string to null:` , e ) ;
26+ }
27+ }
28+ } ,
29+
30+ async down ( ) {
31+ console . log ( 'Down migration is not implemented: cannot reliably restore original "null" string values.' ) ;
32+ } ,
33+ } ;
You can’t perform that action at this time.
0 commit comments