mirror of
				https://github.com/johrpan/musicus.git
				synced 2025-10-26 11:47:25 +01:00 
			
		
		
		
	server: Embed migrations
This commit is contained in:
		
							parent
							
								
									f960971fdb
								
							
						
					
					
						commit
						6a40921ac4
					
				
					 3 changed files with 12 additions and 0 deletions
				
			
		|  | @ -9,6 +9,7 @@ actix-web-httpauth = "0.5.0" | ||||||
| anyhow = "1.0.34" | anyhow = "1.0.34" | ||||||
| derive_more = "0.99.11" | derive_more = "0.99.11" | ||||||
| diesel = { version = "1.4.4", features = ["postgres", "r2d2"] } | diesel = { version = "1.4.4", features = ["postgres", "r2d2"] } | ||||||
|  | diesel_migrations = "1.4.0" | ||||||
| dotenv = "0.15.0" | dotenv = "0.15.0" | ||||||
| env_logger = "0.8.1" | env_logger = "0.8.1" | ||||||
| jsonwebtoken = "7.2.0" | jsonwebtoken = "7.2.0" | ||||||
|  |  | ||||||
|  | @ -22,6 +22,9 @@ pub use works::*; | ||||||
| 
 | 
 | ||||||
| mod schema; | mod schema; | ||||||
| 
 | 
 | ||||||
|  | // This makes the SQL migration scripts accessible from the code.
 | ||||||
|  | embed_migrations!(); | ||||||
|  | 
 | ||||||
| /// A pool of connections to the database.
 | /// A pool of connections to the database.
 | ||||||
| pub type DbPool = r2d2::Pool<r2d2::ConnectionManager<PgConnection>>; | pub type DbPool = r2d2::Pool<r2d2::ConnectionManager<PgConnection>>; | ||||||
| 
 | 
 | ||||||
|  | @ -35,5 +38,9 @@ pub fn connect() -> Result<DbPool> { | ||||||
|     let manager = r2d2::ConnectionManager::<PgConnection>::new(url); |     let manager = r2d2::ConnectionManager::<PgConnection>::new(url); | ||||||
|     let pool = r2d2::Pool::new(manager)?; |     let pool = r2d2::Pool::new(manager)?; | ||||||
| 
 | 
 | ||||||
|  |     // Run embedded migrations.
 | ||||||
|  |     let conn = pool.get()?; | ||||||
|  |     embedded_migrations::run(&conn)?; | ||||||
|  | 
 | ||||||
|     Ok(pool) |     Ok(pool) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -2,6 +2,10 @@ | ||||||
| #[macro_use] | #[macro_use] | ||||||
| extern crate diesel; | extern crate diesel; | ||||||
| 
 | 
 | ||||||
|  | // Required for embed_migrations macro in database/mod.rs
 | ||||||
|  | #[macro_use] | ||||||
|  | extern crate diesel_migrations; | ||||||
|  | 
 | ||||||
| use actix_web::{App, HttpServer}; | use actix_web::{App, HttpServer}; | ||||||
| 
 | 
 | ||||||
| mod database; | mod database; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Elias Projahn
						Elias Projahn