SeaQL / SeaQL/sea-orm

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

Open
#2,702 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:migration Area:multi-schema K-Analyzed
Dominant language
Rust
Stars
9.9k
Forks
734
Avg merge
6h 36m
Merged PRs (30d)
8

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the sea migrate up and sea migrate down commands with PostgreSQL, a non-public search_path, and the seaql_migrations table in that schema. Trace the migration-tracking entry point used by the down operation and compare its schema lookup with the up operation. Done means rollback finds the applied migration in the configured schema and drops the users table there.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, rust
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.