ensureSchemaMatches

open suspend fun ensureSchemaMatches(stream: DestinationStream, tableName: TableName, columnNameMapping: ColumnNameMapping)

Ensures the destination table schema matches the expected stream schema through introspection and reconciliation.

This method performs a comprehensive schema synchronization process:

  1. Introspects the current table schema if it exists

  2. Compares it against the expected stream schema

  3. Identifies required schema modifications (new columns, type changes, constraint updates)

  4. Applies safe schema evolution strategies specific to the database implementation

  5. Handles edge cases like incompatible type changes or constraint violations

The implementation must handle various complexities:

  • Column name normalization and mapping between source and destination naming conventions

  • Type system differences between the source platform and destination database

  • Nullable vs non-nullable column conversions

  • Primary key and unique constraint management during deduplication mode changes

  • Database-specific limitations (e.g., maximum column count, type restrictions)

  • Backward compatibility when schema evolution would break existing data

Parameters

stream

The source stream containing schema definition and sync mode configuration

tableName

The destination table to be synchronized

columnNameMapping

Mapping between logical column names and physical database column names

Throws

if the table exists but is incompatible with Airbyte's requirements

if schema evolution cannot be safely performed