Skip to content

search path not worked for rollback while it works with up migration #2702

@deathcodebind

Description

@deathcodebind

Description

running migrations in specific schema, by setting search path, it actually works when running up, but down operation check the public schema no matter which search path you set.

Steps to Reproduce

manually created a seaql_migrations table in the schema that set as search path.
and here is some code that might causing this:

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        let db = manager.get_connection();
        db.execute_unprepared(
            r#"
            SET search_path = 'user_service';
        "#,
        )
        .await?;
        manager
            .create_table(
                Table::create()
                    .table(User::Table)
                    .if_not_exists()
                    .col(pk_uuid(User::Id))
                    .col(string(User::Username).not_null())
                    .col(string(User::Email).not_null().unique_key())
                    .col(timestamp(User::CreatedAt))
                    .col(timestamp(User::UpdatedAt))
                    .to_owned(),
            )
            .await
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        let db = manager.get_connection();
        db.execute_unprepared(
            r#"
            SET search_path = 'user_service';
        "#,
        )
        .await?;
        manager
            .drop_table(
                Table::drop()
                    .table(User::Table)
                    .if_exists()
                    .cascade()
                    .to_owned(),
            )
            .await
    }
}

#[derive(DeriveIden)]
pub(crate) enum User {
    Table,
    Id,
    Username,
    Email,
    CreatedAt,
    UpdatedAt,
}

Expected Behavior

sea migrate up got:
Applying migration 'm20250820_020446_users_table'
Migration 'm20250820_020446_users_table' has been applied
and could found a table call users in schema user_service

sea migrate down got:
Rolling back 1 applied migrations
Rolling back migration 'm20250820_020446_users_table'
and users table got dropped

Actual Behavior

sea migrate up just works as expected.
but migrate down got this:
Rolling back 1 applied migrations
No applied migrations

Reproduces How Often

every time running those commands

Workarounds

migrate down always look up seaql_migrations in public schema, even when a search path is set, and if there is not a one, it will create a one and tell me there is no applied migrations.

Versions

sea-orm-migration version is 1.1.0
postgresql version is 17.2
got a citus 13 extension installed

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions