@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 the target shard differs from the current one, moves the row through the migration journal (see docs/migration-protocol.md)
      4. Updates the KV mapping, and the placement exception set when the target is not the shard placement computes

      A move needs a journal: set journalShard in the configuration. With several shards and none set it throws JOURNAL_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.

      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

      • options: MoveRecordOptions = {}

        Primary-key column, conflict policy, version column and retention

      Returns Promise<void>

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