Record mapping shard names to D1 database instances
Schema SQL to use
Promise that resolves when schema is created on all shards
const shards = {
'db-east': env.DB_EAST,
'db-west': env.DB_WEST,
'db-central': env.DB_CENTRAL
};
try {
await createSchemaAcrossShards(shards);
console.log('Schema created on all shards successfully');
} catch (error) {
console.error('Schema creation failed:', error.message);
// Error will specify which shard failed
}
Applies the schema to all provided D1 database instances in parallel. This is useful for initializing a complete sharded database system where all shards need the same table structure.
The function executes schema creation on all shards concurrently for performance, but provides detailed error reporting that identifies which specific shard failed if any errors occur.