Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve database migrations to pair sql and rust migration code #7311

Open
adrianbenavides opened this issue Jan 2, 2024 · 0 comments
Open

Comments

@adrianbenavides
Copy link
Member

Current behavior

The current implementation runs all the sql migrations and then the rust migrations for post-migration code. We should refactor this function so that we can run a pair of sql+rust migrations at a time.

Desired behavior

The sqlx::migrate!(); macro returns a Migrator instance that returns the migration names (name+version given in the file name). The Migrator struct is pretty limited and doesn't allow running migrations one by one.

We should consider writing a wrapper around this struct to have more control over migrations and add the functionality to run arbitrary rust code given a migration name.

// within a function like 
// https://github.com/launchbadge/sqlx/blob/main/sqlx-core/src/migrate/migrator.rs#L118
let rust_migrator = RustMigrator::new(..);
for migration in self.iter() {
    // ..
    conn.apply(migration).await?;
    rust_migrator.apply(migration).await?;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant