-
Notifications
You must be signed in to change notification settings - Fork 0
/
wormsecmodel.cs
20 lines (17 loc) · 920 Bytes
/
wormsecmodel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const mongoose = require('mongoose');
const versionedRecordSchema = new mongoose.Schema({
originalId: { type: String, required: true }, // Unique ID for the original document
version: { type: Number, required: true }, // Version number
data: { type: Object, required: true }, // Document data
createdAt: { type: Date, required: true, default: Date.now },
locked: { type: Boolean, default: true }, // Immutability flag
author: { type: String, required: true },
auditTrail: [{ // Tracks access and modifications
action: String,
timestamp: { type: Date, default: Date.now },
userId: String
}]
});
// Define indexes for fast retrieval
versionedRecordSchema.index({ originalId: 1, version: -1 }); // Retrieve latest version quickly
const VersionedRecord = mongoose.model('VersionedRecord', versionedRecordSchema);