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

Run database migrations from distributed binary #254

Open
walkah opened this issue Mar 18, 2024 · 1 comment
Open

Run database migrations from distributed binary #254

walkah opened this issue Mar 18, 2024 · 1 comment

Comments

@walkah
Copy link
Member

walkah commented Mar 18, 2024

Summary

Problem

Unless I'm mistaken, we currently need a clone of the repo / source to run the diesel migrations. It looks, though, like we're embedding the migrations in the binary - but I can't see any way to trigger them.

Impact

Need source to run migrations (can't just use the distributed binary).

Solution

I don't know enough about diesel, but it looks like automigrations are a possibility (should be the simplest, near term solution).

@matheus23
Copy link
Member

We already run migrations inside the binary for test purposes (because they're stood up on-the-fly), here:

let mut conn = PgConnection::establish(&format!("{}/{}", base_url, db_name))
.context("Cannot connect to postgres database.")?;
conn.run_pending_migrations(MIGRATIONS)
.map_err(|e| anyhow!(e))
.context("Could not run migrations")?;

We need to make that code invokable from the binary CLI, too.

I'm pretty sure that actually embeds the migrations in the binary, given this:

use diesel_migrations::EmbeddedMigrations;
/// The migrations available at compile-time
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations/");

So I'm 90% sure that's an easy task.

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