-
BackendPostgreSQL Diesel version2.3.5 Diesel Features"postgres", "numeric", "chrono", "network-address", "r2d2", "uuid" Operating System VersionDebian Testing Third party librariesNo response What do you want to do?I am building a modular application framework. Common features used across many applications are provided by one crate. This crate includes diesel migrations for tables appropriate for these common features; i.e.: authentication, email verification, etc. This module is then used by an application that needs that functionality, but it builds upon it with other arbitrary features which themselves have their own diesel migrations. I am looking for advice on how I should structure this to make diesel migrations relatively painless to manage and run: i.e. centrally managed at the application level. My current thinking is that I will want to use embedded migrations, possibly with some custom migration harness in a build script. I'm thinking that filesystem-based migrations will be tricky without keeping dependency migrations at hardcoded paths, though I might be able to get around that via the Compile time errorNo response What code do you already have?I have separate migrations folders, but I have to run the migrations manually and separately. Additional details#559 (comment) might have a good starting point Checklist
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
I think the most convenient method is to just use
Running different sets of migrations from different places is fine and won't cause problems. Diesel mostly checks that all migrations are applied, so there is no need to run them all at once or even in "order" as long as they don't depend on each other. If there is a dependency, you either need to make sure that you run these migrations first or run tham at least at once so that diesel sorts them for you according to the version. For the second approach a custom |
Beta Was this translation helpful? Give feedback.
-
|
My first step has gone completely painlessly, though I anticipate that I might have some trouble with reverting and redoing migrations in future. I might have been overthinking the problem, though. I made a use diesel::prelude::*;
use diesel_migrations::MigrationHarness;
use common::server::get_database_url;
use auth::backend::MIGRATIONS as AUTH_MIGRATIONS;
use app::backend::MIGRATIONS;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let db_url = get_database_url();
let mut connection = PgConnection::establish(&db_url).expect("Unable to establish a databse connection");
connection.run_pending_migrations(AUTH_MIGRATIONS).expect("Authentication migrations have failed.");
connection.run_pending_migrations(MIGRATIONS).expect("Application migrations have failed.");
println!("Migrations state updated.");
Ok(())
}This is working fine, and I don't currently have any understanding of what a custom implementation of a |
Beta Was this translation helpful? Give feedback.
My first step has gone completely painlessly, though I anticipate that I might have some trouble with reverting and redoing migrations in future. I might have been overthinking the problem, though.
I made a
setup.rsbinary with the following code: