4.0 KiB
4.0 KiB
VEX Raw Migration Rollback Guide
This document describes how to rollback migrations applied to the vex_raw collection.
Migration: 20251127-vex-raw-idempotency-indexes
Description
Adds unique idempotency indexes to enforce content-addressed storage:
idx_provider_sourceUri_digest_unique: Prevents duplicate documents from same provider/sourceidx_digest_providerId: Optimizes evidence queries by digestidx_retrievedAt: Supports time-based queries and future TTL operations
Rollback Steps
Option 1: MongoDB Shell
// Connect to your MongoDB instance
mongosh "mongodb://localhost:27017/excititor"
// Drop the idempotency indexes
db.vex_raw.dropIndex("idx_provider_sourceUri_digest_unique")
db.vex_raw.dropIndex("idx_digest_providerId")
db.vex_raw.dropIndex("idx_retrievedAt")
// Verify indexes are dropped
db.vex_raw.getIndexes()
Option 2: Programmatic Rollback (C#)
using StellaOps.Excititor.Storage.Mongo.Migrations;
// Get the database instance
var database = client.GetDatabase("excititor");
// Execute rollback
await database.RollbackIdempotencyIndexesAsync(cancellationToken);
// Verify rollback
var verified = await database.VerifyIdempotencyIndexesExistAsync(cancellationToken);
Console.WriteLine($"Indexes exist after rollback: {verified}"); // Should be false
Option 3: MongoDB Compass
- Connect to your MongoDB instance
- Navigate to the
excititordatabase - Select the
vex_rawcollection - Go to the "Indexes" tab
- Click "Drop Index" for each of:
idx_provider_sourceUri_digest_uniqueidx_digest_providerIdidx_retrievedAt
Impact of Rollback
Before rollback (indexes present):
- Documents are prevented from being duplicated
- Evidence queries are optimized
- Unique constraint enforced
After rollback (indexes dropped):
- Duplicate documents may be inserted
- Evidence queries may be slower
- No unique constraint enforcement
Re-applying the Migration
To re-apply the migration after rollback:
// MongoDB shell
db.vex_raw.createIndex(
{ "providerId": 1, "sourceUri": 1, "digest": 1 },
{ unique: true, name: "idx_provider_sourceUri_digest_unique", background: true }
)
db.vex_raw.createIndex(
{ "digest": 1, "providerId": 1 },
{ name: "idx_digest_providerId", background: true }
)
db.vex_raw.createIndex(
{ "retrievedAt": 1 },
{ name: "idx_retrievedAt", background: true }
)
Or run the migration runner:
stellaops excititor migrate --run 20251127-vex-raw-idempotency-indexes
Migration: 20251125-vex-raw-json-schema
Description
Adds a JSON Schema validator to the vex_raw collection with validationAction: warn.
Rollback Steps
// MongoDB shell - remove the validator
db.runCommand({
collMod: "vex_raw",
validator: {},
validationAction: "off",
validationLevel: "off"
})
// Verify validator is removed
db.getCollectionInfos({ name: "vex_raw" })[0].options
Impact of Rollback
- Documents will no longer be validated against the schema
- Invalid documents may be inserted
- Existing documents are not affected
General Rollback Guidelines
- Always backup first: Create a backup before any rollback operation
- Test in staging: Verify rollback procedure in a non-production environment
- Monitor performance: Watch for query performance changes after rollback
- Document changes: Log all rollback operations for audit purposes
Troubleshooting
Index Drop Fails
If you see "IndexNotFound" errors, the index may have already been dropped or was never created:
// Check existing indexes
db.vex_raw.getIndexes()
Validator Removal Fails
If the validator command fails, verify you have the correct permissions:
// Check current user roles
db.runCommand({ usersInfo: 1 })