repo/fsrepo/migrations/README.md
This directory contains the migration system for IPFS repositories, handling both embedded and external migrations.
Starting from repo version 17, Kubo uses embedded migrations that are built into the binary, eliminating the need to download external migration tools.
migrations.RunEmbeddedMigrations()Parameters:
ctx: Context for cancellation and timeoutstargetVersion: Target repository version to migrate torepoPath: Path to the IPFS repository directoryallowDowngrade: Whether to allow downgrade migrationserr = migrations.RunEmbeddedMigrations(ctx, targetVersion, repoPath, allowDowngrade)
if err != nil {
// Handle migration failure, may fall back to external migrations
}
migrations.RunMigration() with migrations.ReadMigrationConfig()// Read migration configuration for external migrations
migrationCfg, err := migrations.ReadMigrationConfig(repoPath, configFile)
fetcher, err := migrations.GetMigrationFetcher(migrationCfg.DownloadSources, ...)
err = migrations.RunMigration(ctx, fetcher, targetVersion, repoPath, allowDowngrade)
RunEmbeddedMigrations)RunMigration)repo/fsrepo/migrations/
├── README.md # This file
├── embedded.go # Embedded migration system
├── embedded_test.go # Tests for embedded migrations
├── migrations.go # External migration system
├── fs-repo-16-to-17/ # First embedded migration (16→17)
│ ├── migration/
│ │ ├── migration.go # Migration logic
│ │ └── migration_test.go # Migration tests
│ ├── atomicfile/
│ │ └── atomicfile.go # Atomic file operations
│ ├── main.go # Standalone migration binary
│ └── README.md # Migration-specific documentation
└── [other migration utilities]
To add a new embedded migration (e.g., fs-repo-17-to-18):
fs-repo-17-to-18/migration/migration.goEmbeddedMigration interfaceembeddedMigrations map in embedded.goRepoVersion in fsrepo.go// In embedded.go
var embeddedMigrations = map[string]EmbeddedMigration{
"fs-repo-16-to-17": &mg16.Migration{},
"fs-repo-17-to-18": &mg17.Migration{}, // Add new migration
}
Each embedded migration must:
EmbeddedMigration interfaceExternal migrations are maintained for:
The external migration system will continue to work but is not the preferred method for new migrations.
All migrations (embedded and external) include:
Test both embedded and external migration systems:
# Test embedded migrations
go test ./repo/fsrepo/migrations/ -run TestEmbedded
# Test specific migration
go test ./repo/fsrepo/migrations/fs-repo-16-to-17/migration/
# Test migration registration
go test ./repo/fsrepo/migrations/ -run TestHasEmbedded