Skip to content

Commit 93adf0c

Browse files
committed
feat(searches-migration-script): to "all-mine" and "all-public"
1 parent 4ee8959 commit 93adf0c

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Migration: collapse all legacy search domains into the two current domains.
2+
//
3+
// Why: the search bar now only offers "all-mine" and "all-public". Previously
4+
// there were separate domains per resource type. This migration remaps all
5+
// legacy values so existing saved/recent searches keep working:
6+
//
7+
// my-bookmarks → all-mine
8+
// my-notes → all-mine
9+
// my-snippets → all-mine (in case the previous snippet→notes migration was skipped)
10+
// public-bookmarks → all-public
11+
// public-notes → all-public
12+
// public-snippets → all-public (in case the previous snippet→notes migration was skipped)
13+
//
14+
// This updates the `searches` array on every user document in the `users` collection.
15+
//
16+
// Run against ALL users (production):
17+
// mongo <host>/<db> -u <user> -p <password> 1749254400000_migrate-legacy-searches-to-all-mine-all-public.js
18+
//
19+
// Run against a SINGLE user (for testing or partial rollout):
20+
// Set TARGET_USER_ID below and run:
21+
// mongo <host>/<db> -u <user> -p <password> 1749254400000_migrate-legacy-searches-to-all-mine-all-public-single-user.js
22+
23+
var migratedUsers = 0;
24+
var migratedSearches = 0;
25+
26+
db.users.find({}).forEach(function(user) {
27+
var updatedSearches = [];
28+
var needsUpdating = false;
29+
30+
if (user.searches) {
31+
user.searches.forEach(function(search) {
32+
if (search.searchDomain === 'my-bookmarks' ||
33+
search.searchDomain === 'my-notes' ||
34+
search.searchDomain === 'my-snippets') {
35+
search.searchDomain = 'all-mine';
36+
needsUpdating = true;
37+
migratedSearches++;
38+
} else if (search.searchDomain === 'public-bookmarks' ||
39+
search.searchDomain === 'public-notes' ||
40+
search.searchDomain === 'public-snippets') {
41+
search.searchDomain = 'all-public';
42+
needsUpdating = true;
43+
migratedSearches++;
44+
}
45+
updatedSearches.push(search);
46+
});
47+
}
48+
49+
if (needsUpdating) {
50+
db.users.update(
51+
{ _id: user._id },
52+
{ $set: { searches: updatedSearches } }
53+
);
54+
migratedUsers++;
55+
print('Updated searches for userId: ' + user.userId);
56+
}
57+
});
58+
59+
print('Done. Users updated: ' + migratedUsers + ', searches remapped: ' + migratedSearches);

0 commit comments

Comments
 (0)