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

    Function reassignShard

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

      1. Validates the target shard exists in configuration
      2. Checks that a mapping exists for the primary key
      3. If target shard differs from current, migrates the data
      4. Updates the KV mapping to point to the new shard

      Note: This operation involves data migration and should be used carefully in production environments. Consider the impact on ongoing queries.

      Parameters

      • primaryKey: string

        Primary key to reassign to a different shard

      • newBinding: string

        New shard binding name where the data should be moved

      • tableName: string

        Name of the table containing the record to migrate

      Returns Promise<void>

      Promise that resolves when reassignment and migration are complete

      If target shard not found, mapping doesn't exist, or migration fails

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