1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! Test utilities for setting up databases with migrations
use hammerwork::{JobQueue, migrations::MigrationManager};
use std::sync::Arc;
#[cfg(feature = "postgres")]
pub async fn setup_postgres_queue() -> Arc<JobQueue<sqlx::Postgres>> {
use hammerwork::migrations::postgres::PostgresMigrationRunner;
use sqlx::{Pool, Postgres};
let database_url = std::env::var("DATABASE_URL")
.unwrap_or_else(|_| "postgres://postgres:hammerwork@localhost:5433/hammerwork".to_string());
let pool = Pool::<Postgres>::connect(&database_url)
.await
.expect("Failed to connect to Postgres");
let queue = Arc::new(JobQueue::new(pool.clone()));
// Run migrations to set up tables - the migration system handles duplicates gracefully
let runner = Box::new(PostgresMigrationRunner::new(pool));
let manager = MigrationManager::new(runner);
manager
.run_migrations()
.await
.expect("Failed to run migrations");
queue
}
#[cfg(feature = "mysql")]
#[allow(dead_code)]
pub async fn setup_mysql_queue() -> Arc<JobQueue<sqlx::MySql>> {
use hammerwork::migrations::mysql::MySqlMigrationRunner;
use sqlx::{MySql, Pool};
let database_url = std::env::var("MYSQL_DATABASE_URL")
.unwrap_or_else(|_| "mysql://root:hammerwork@localhost:3307/hammerwork".to_string());
let pool = Pool::<MySql>::connect(&database_url)
.await
.expect("Failed to connect to MySQL");
let queue = Arc::new(JobQueue::new(pool.clone()));
// Run migrations to set up tables - the migration system handles duplicates gracefully
let runner = Box::new(MySqlMigrationRunner::new(pool));
let manager = MigrationManager::new(runner);
manager
.run_migrations()
.await
.expect("Failed to run migrations");
queue
}