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

    Function integrateExistingDatabase

    • Performs a complete drop-in integration of an existing database. This is the main function for integrating CollegeDB with an existing database that already contains data. It discovers tables, validates them, creates shard mappings, and optionally adds the shard_mappings table if needed.

      Parameters

      • d1: D1Database

        The existing D1 database to integrate

      • shardName: string

        The shard binding name for this database

      • mapper: KVShardMapper

        KVShardMapper instance for storing mappings

      • options: IntegrationOptions = {}

        Configuration options for the integration

      Returns Promise<IntegrationResult>

      Promise resolving to integration summary

      If integration fails

      import { KVShardMapper } from './kvmap.js';

      const mapper = new KVShardMapper(env.KV);
      const result = await integrateExistingDatabase(env.DB_EXISTING, 'db-existing', mapper, {
      tables: ['users', 'posts'],
      strategy: 'hash',
      addShardMappingsTable: true
      });

      console.log(`Integrated ${result.totalRecords} records from ${result.tablesProcessed} tables`);