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

Problem with migrations #21

Closed
kirillsalykin opened this issue Oct 23, 2024 · 3 comments
Closed

Problem with migrations #21

kirillsalykin opened this issue Oct 23, 2024 · 3 comments

Comments

@kirillsalykin
Copy link

kirillsalykin commented Oct 23, 2024

I have next code which creates a db pool and runs a migration:

use sqlx::postgres::{PgConnectOptions, PgPoolOptions};
use sqlx::PgPool;
use underway;

use crate::configuration::DatabaseConfig;

impl From<DatabaseConfig> for PgConnectOptions {
    fn from(config: DatabaseConfig) -> Self {
        PgConnectOptions::new()
            .host(&config.host)
            .port(config.port)
            .username(&config.username)
            .password(&config.password)
            .database(&config.database)
    }
}

pub async fn get_connection_pool(config: DatabaseConfig) -> PgPool {
    let pool = PgPoolOptions::new()
        .connect_with(config.into())
        .await
        .expect("fail to connect to db");

    underway::MIGRATOR.run(&pool).await.unwrap();

    // TODO: handle errors
    sqlx::migrate!("./migrations").run(&pool).await.unwrap();

    pool
}

Unfortunately it keeps failing with this:

thread 'main' panicked at /Users/kirill/Dev/Playground/prostor/src/backend/src/database.rs:27:53:
called `Result::unwrap()` on an `Err` value: VersionMissing(20240921151751)

which is underway migration.

sqlx knows about 20240921151751 migration because it is in _migrations table, but it is missing from the migrations directory.

if you change order of migrators - underway migrator will start to complain about missing migrations from the project.

@kirillsalykin
Copy link
Author

kirillsalykin commented Oct 23, 2024

I dont think there is a way to add multiple sources for migrations in sqlx.

Options to have this working:

  1. turn on ignore-missing in both migrators, which probably nice to have, so not the best option
  2. copy manually migration from the underway
  3. copy automatically migration from the underway
  4. ask sqlx to support multiple sources

@kirillsalykin
Copy link
Author

FYI: launchbadge/sqlx#3573

@maxcountryman
Copy link
Owner

This is a dupe of #11

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

2 participants