Testing business logic with sqlx::test and DB extensions

I have a program that's parsing geojson files and then pushing some data to a database using sqlx. I would like to test the business logic around the queries, so I tried using sqlx::test.

#[cfg(test)]
mod tests {
    use super::*;

    #[sqlx::test(migrations = "../backend/supabase/migrations")]
    async fn test_assert(pool: PgPool) {
        assert_eq!(0, 1);
    }
}

My database is Supabase, so I am using their migrations to manage the schema instead of sqlx migrate. This isn't the normal way to do it, but regardless: when I supply the appropriate path to the directory containing the migration files, sqlx finds them, creates a scratch database, and begins to run the migration.

However, it soon fails because I use the PostGIS extension to declare column types in several tables. The error is:

PgDatabaseError {
    severity: Error,
    code: "42704",
    message: "type \"geography\" does not exist",
// ...
}

Does anyone have experience with using sqlx::test in this way? It may be that sqlx::test simply doesn't work if you use any extensions, which would be a real shame. If that's the case, though, how should I implement these tests? I have also asked this question on the sqlx Discussions page, but I haven't heard back yet.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.