Skip to main content

run_sql_migrations

Function run_sql_migrations 

Source
pub async fn run_sql_migrations<F, Fut>(
    pool: &SqlitePool,
    registry_table: &str,
    steps: &[(i64, &str, &str)],
    detect_existing: F,
) -> Result<(), AdkError>
where F: FnOnce() -> Fut, Fut: Future<Output = Result<bool, AdkError>>,
Expand description

Run all pending migrations for a SQL backend.

registry_table must be an ASCII identifier of at most 63 bytes, starting with a letter or underscore. Step bodies are trusted executable SQL, never user input. Descriptions are bound as values and may contain quotes.

  1. Creates the registry table if it does not exist.
  2. Calls detect_existing to check for pre-existing schema tables. If tables exist but the registry is empty, records version 1 as already applied (baseline).
  3. Reads the maximum applied version from the registry.
  4. If the database version exceeds the compiled-in maximum, returns a version-mismatch error.
  5. Executes each unapplied step inside a transaction and records it in the registry.

Each statement takes a connection from pool. Use run_sql_migrations_on_connection when every statement must run on the connection that holds a session-level lock.