View Source Plausible.Release (Plausible v0.0.1)
Summary
Functions
interweave_migrate/0
is a migration function that:
- Lists all pending migrations across multiple repositories.
- Sorts these migrations into a single list.
- Groups consecutive migrations by repository into "streaks".
- Executes the migrations in the correct order by processing each streak sequentially.
Why Use This Approach?
This function resolves dependencies between migrations that span across different repositories.
The default migrate/0
function migrates each repository independently, which may result in
migrations running in the wrong order when there are cross-repository dependencies.
Consider the following example (adapted from reality, not 100% accurate):
- Migration 1: The PostgreSQL (PG) repository creates a table named
site_imports
. - Migration 2: The ClickHouse (CH) repository creates
import_id
columns inimported_*
tables. - Migration 3: The PG repository runs a data migration that utilizes both PG and CH databases,
reading from the
import_id
column inimported_*
tables.
The default migrate/0
would execute these migrations by repository, resulting in the following order:
- Migration 1 (PG)
- Migration 3 (PG)
- Migration 2 (CH)
This sequence would fail at Migration 3, as the import_id
columns in the CH repository have not been created yet.
interweave_migrate/0
addresses this issue by consolidating all pending migrations into a single, ordered queue:
- Migration 1 (PG)
- Migration 2 (CH)
- Migration 3 (PG)
This ensures all dependencies are resolved in the correct order.