Skip to content

Add author fields#13

Open
cheeZery wants to merge 2 commits intomainfrom
add-author-fields
Open

Add author fields#13
cheeZery wants to merge 2 commits intomainfrom
add-author-fields

Conversation

@cheeZery
Copy link
Copy Markdown
Member

Damit tauchen dann wieder die Autor-Felder im Payload auf.

Nach Release führe ich eine manuelle Migration der alten Infos direkt in mongosh durch:

// Step 1: Find all collections with old-format createdBy/updatedBy
var collectionsWithAuthorFields = db.getCollectionNames().filter(function(c) {
    return db.getCollection(c).findOne({ 
        $or: [
            { 'createdBy.value': { $exists: true }, 'createdBy.relationTo': 'users' },
            { 'updatedBy.value': { $exists: true }, 'updatedBy.relationTo': 'users' }
        ]
    });
});

print("Collections to migrate: " + JSON.stringify(collectionsWithAuthorFields));
print("");

// Step 2: Flatten each collection
collectionsWithAuthorFields.forEach(function(colName) {
    var collection = db.getCollection(colName);
    var docs = collection.find({
        $or: [
            { 'createdBy.value': { $exists: true }, 'createdBy.relationTo': 'users' },
            { 'updatedBy.value': { $exists: true }, 'updatedBy.relationTo': 'users' }
        ]
    }).toArray();
    
    var updated = 0;
    docs.forEach(function(doc) {
        var updateFields = {};
        
        if (doc.createdBy && doc.createdBy.relationTo === 'users' && doc.createdBy.value) {
            updateFields.createdBy = doc.createdBy.value;
        }
        if (doc.updatedBy && doc.updatedBy.relationTo === 'users' && doc.updatedBy.value) {
            updateFields.updatedBy = doc.updatedBy.value;
        }
        
        if (Object.keys(updateFields).length > 0) {
            collection.updateOne({ _id: doc._id }, { $set: updateFields });
            updated++;
        }
    });
    
    print(colName + ": flattened " + updated + " documents");
});

print("");
print("Migration complete.");

@cheeZery cheeZery requested a review from Haliax February 22, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants