Array of primary key values to create mappings for
Array of available shard binding names
Allocation strategy to use ('hash', 'round-robin', or 'random')
KVShardMapper instance for storing mappings
Promise that resolves when all mappings are created
import { KVShardMapper } from './kvmap.js';
const mapper = new KVShardMapper(env.KV);
const existingIds = await discoverExistingPrimaryKeys(env.DB_EXISTING, 'users');
const shards = ['db-east', 'db-west', 'db-central'];
await createMappingsForExistingKeys(existingIds, shards, 'hash', mapper);
console.log('All existing users mapped to shards');
Takes a list of existing primary keys and creates shard mappings for them using the specified allocation strategy. This allows existing data to be integrated into the CollegeDB sharding system without data migration.