Skip to main content

upgrade_data_lake_schema_v8

Function upgrade_data_lake_schema_v8 

Source
pub async fn upgrade_data_lake_schema_v8(
    tr: &mut Transaction<'_, Postgres>,
) -> Result<(), Error>
Expand description

Upgrades the data lake schema to version 8.

Adds a nullable audience column to processes, streams, and blocks: the write audience the row was stamped with at insert time. No DEFAULT and no backfill – a NULL column means the row predates this stage and resolves to the deployment’s MICROMEGAS_DEFAULT_AUDIENCE at read time, exactly as an unstamped row does today.

The CHECK constraints are added NOT VALID so ALTER TABLE does not scan and lock every existing row on blocks, the largest table in the lake; the constraint only applies to rows written from this point on (WriteAudience::new already validates the charset in Rust).

No index: nothing queries Postgres by audience, so one would be pure write cost.

sql_telemetry_db.rs’s create_tables (the v1 shape) is not touched – a fresh database walks every upgrade in turn, so adding the column there too would double-apply it.