@earth-app/collegedb
    Preparing search index...

    Function createMappingsForExistingKeys

    • 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.

      Parameters

      • primaryKeys: string[]

        Array of primary key values to create mappings for

      • shardBindings: string[]

        Array of available shard binding names

      • strategy: "round-robin" | "random" | "hash"

        Allocation strategy to use ('hash', 'round-robin', or 'random')

      • mapper: any

        KVShardMapper instance for storing mappings

      Returns Promise<void>

      Promise that resolves when all mappings are created

      If mapping creation fails

      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');