Prompt
When changing identifier systems (e.g., from using getInternalId() to getSequence()), implement comprehensive migration strategies to preserve data integrity and backward compatibility. For each change:
- Create explicit migration scripts to update or rename existing resources
- Implement fallback mechanisms for transitional periods
- Update all related queries, metrics, and references consistently
- Test thoroughly with real data before deploying
// Example migration for collection renaming:
public function migrateCollections(): void
{
$buckets = $this->dbForProject->find('buckets');
foreach ($buckets as $bucket) {
$oldName = 'bucket_' . $bucket->getInternalId();
$newName = 'bucket_' . $bucket->getSequence();
if ($this->dbForProject->hasCollection($oldName) && !$this->dbForProject->hasCollection($newName)) {
// Rename collection to preserve existing data
$this->dbForProject->renameCollection($oldName, $newName);
Console::success("Migrated collection {$oldName} → {$newName}");
}
}
}
Without proper migration planning, changes to identifier systems often result in orphaned data, broken queries, and critical production issues.