Add Create Database to diesel_migrations
#3129
Replies: 3 comments 2 replies
-
Thanks for writing a post here. Please include more information about what interface you exactly want to add to diesel_migrations, how this interface should work, what alternatives are possible and why you believe that your proposal is the correct solution for the underlying problem. |
Beta Was this translation helpful? Give feedback.
-
in the let conn = establish_connection();
embedded_migrations::run_with_output(&conn, &mut std::io::stdout())?; we have a benefits that we don't need use diesel migrations run Problemnow the real problem is what will happen if my database not exists, in this situation if i use for solve the problem we have two options
Goali want my program handle run migrations and create database independently, because it's easy to export program and use it every where without need any instruction for use, you can just run the program and program decide to create database or run migrations for reach my goal i use my custom functions to check database not exists and create it, after that i'll run migrations like this if !DbHelper::is_database_exists::<PgConnection>(&CONFIG.database_url) {
println!("Database not exits");
DbHelper::create_database::<PgConnection>(&CONFIG.database_url)?;
println!("Database created");
}
let conn = diesel::pg::PgConnection::establish(&CONFIG.database_url)?;
embedded_migrations::run_with_output(&conn, &mut std::io::stdout())?;
println!("Migration Done"); Ideai think it's a good idea if we have these functions in |
Beta Was this translation helpful? Give feedback.
-
+1 for having some more utilities somewhere in Diesel for managing databases.
I think having
I think these sort of utilities make sense as part of
Perhaps I've done something wrong but I'm unable to establish a connection if the database doesn't exist so I can't execute the sql query to create the database.
Sorry but I can't speak to this one 🤷🏼♂️ 😅 Summary of my preferences:
|
Beta Was this translation helpful? Give feedback.
-
in
diesel_migrations
just execute queries and not create database if not exitsi use below code in my project to handle database if not exists before run migrations, i think it's good to have it in
diesel_migrations
and use it like this
Beta Was this translation helpful? Give feedback.
All reactions