MCPcopy Create free account
hub / github.com/LukeMathWalker/zero-to-production / configure_database

Function configure_database

tests/api/helpers.rs:231–256  ·  view source on GitHub ↗
(config: &DatabaseSettings)

Source from the content-addressed store, hash-verified

229}
230
231async fn configure_database(config: &DatabaseSettings) -> PgPool {
232 // Create database
233 let maintenance_settings = DatabaseSettings {
234 database_name: "postgres".to_string(),
235 username: "postgres".to_string(),
236 password: Secret::new("password".to_string()),
237 ..config.clone()
238 };
239 let mut connection = PgConnection::connect_with(&maintenance_settings.connect_options())
240 .await
241 .expect("Failed to connect to Postgres");
242 connection
243 .execute(format!(r#"CREATE DATABASE "{}";"#, config.database_name).as_str())
244 .await
245 .expect("Failed to create database.");
246
247 // Migrate database
248 let connection_pool = PgPool::connect_with(config.connect_options())
249 .await
250 .expect("Failed to connect to Postgres.");
251 sqlx::migrate!("./migrations")
252 .run(&connection_pool)
253 .await
254 .expect("Failed to migrate the database");
255 connection_pool
256}
257
258pub struct TestUser {
259 user_id: Uuid,

Callers 1

spawn_appFunction · 0.85

Calls 2

connect_optionsMethod · 0.80
as_strMethod · 0.80

Tested by

no test coverage detected