The existing D1 database to integrate
The shard binding name for this database
KVShardMapper instance for storing mappings
Configuration options for the integration
Promise resolving to integration summary
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`);
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.