@Julian I filtered out the null names and the upgrade went through:
"use strict";
const db = require("../../database");
const meta = require("../../meta");
const categories = require("../../categories");
const slugify = require("../../slugify");
module.exports = {
name: "Setting up default configs/privileges re: ActivityPub",
timestamp: Date.UTC(2024, 1, 22),
method: async () => {
// Disable ActivityPub (upgraded installs have to opt-in to AP)
meta.configs.set("activitypubEnabled", 0);
// Set default privileges for world category
const install = require("../../install");
await install.giveWorldPrivileges();
// Run through all categories and ensure their slugs are unique (incl. users/groups too)
const cids = await db.getSortedSetMembers("categories:cid");
const names = await db.getObjectsFields(
cids.map((cid) => `category:${cid}`),
cids.map(() => "name"),
);
const nullIndexes = names
.map((element, index) => (element["name"] === null ? index : -1)) // mark null elements
.filter((index) => index !== -1);
let filteredNames = names.filter(element => element["name"] !== null);
let filteredCids = cids.filter((_, index) => !nullIndexes.includes(index));
const handles = await Promise.all(
filteredCids.map(async (cid, idx) => {
const { name } = filteredNames[idx];
const handle = await categories.generateHandle(slugify(name));
return handle;
}),
);
await Promise.all([
db.setObjectBulk(
filteredCids.map((cid, idx) => [`category:${cid}`, { handle: handles[idx] }]),
),
db.sortedSetAdd("categoryhandle:cid", filteredCids, handles),
]);
},
};