Primary key to reassign to a different shard
New shard binding name where the data should be moved
Name of the table containing the record to migrate
Primary-key column, conflict policy, version column and retention
Promise that resolves when reassignment and migration are complete
SHARD_NOT_FOUND, MAPPING_NOT_FOUND, JOURNAL_NOT_CONFIGURED,
MIGRATION_IN_PROGRESS, MIGRATION_ABORTED, MIGRATION_PUBLISH_FAILED, or the errors of the move itself
// Move a user from east to west coast for better latency
try {
await reassignShard('user-california-123', 'db-west', 'users');
console.log('User successfully moved to west coast shard');
} catch (error) {
console.error('Reassignment failed:', error.message);
}
// Load balancing: move high-activity user to dedicated shard
await reassignShard('user-enterprise-456', 'db-dedicated', 'users');
Reassigns a primary key to a different shard
Moves a primary key and its associated data from one shard to another. This operation is useful for load balancing, shard maintenance, or geographic redistribution of data.
The reassignment process:
docs/migration-protocol.md)A move needs a journal: set
journalShardin the configuration. With several shards and none set it throwsJOURNAL_NOT_CONFIGURED. A crash at any step is finished or rolled back by recoverMigrations. Only one table row moves; related rows in other tables are the caller's to move.