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

    Function createSchemaAcrossShards

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

      Parameters

      • shards: Record<string, D1Database>

        Record mapping shard names to D1 database instances

      • schema: string

        Schema SQL to use

      Returns Promise<void>

      Promise that resolves when schema is created on all shards

      If schema creation fails on any shard, with shard identification

      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
      }