Skip to content

Commit

Permalink
add: api to get migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
geofmureithi committed Oct 5, 2023
1 parent 1e0fb25 commit 8a7ba8f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
10 changes: 8 additions & 2 deletions packages/apalis-sql/src/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ impl<T> MysqlStorage<T> {
Ok(Self::new(pool))
}

/// Setup
/// Get mysql migrations without running them
#[cfg(feature = "migrate")]
pub fn migrations() -> sqlx::migrate::Migrator {
sqlx::migrate!("migrations/mysql")
}

/// Do migrations for mysql
#[cfg(feature = "migrate")]
pub async fn setup(&self) -> Result<(), sqlx::Error> {
let pool = self.pool.clone();
sqlx::migrate!("migrations/mysql").run(&pool).await?;
Self::migrations().run(&pool).await?;
Ok(())
}

Expand Down
9 changes: 8 additions & 1 deletion packages/apalis-sql/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@ impl<T> PostgresStorage<T> {
Ok(Self::new(pool))
}

/// Get postgres migrations without running them
#[cfg(feature = "migrate")]
pub fn migrations() -> sqlx::migrate::Migrator {
sqlx::migrate!("migrations/postgres")
}


/// Do migrations for Postgres
#[cfg(feature = "migrate")]
pub async fn setup(&self) -> Result<(), sqlx::Error> {
let pool = self.pool.clone();
sqlx::migrate!("migrations/postgres").run(&pool).await?;
Self::migrations().run(&pool).await?;
Ok(())
}

Expand Down
9 changes: 8 additions & 1 deletion packages/apalis-sql/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ impl<T: Job> SqliteStorage<T> {
sqlx::query("PRAGMA cache_size = 64000;")
.execute(&pool)
.await?;
sqlx::migrate!("migrations/sqlite").run(&pool).await?;
Self::migrations().run(&pool).await?;
Ok(())
}

/// Get sqlite migrations without running them
#[cfg(feature = "migrate")]
pub fn migrations() -> sqlx::migrate::Migrator {
sqlx::migrate!("migrations/sqlite")
}


/// Keeps a storage notified that the worker is still alive manually
pub async fn keep_alive_at<Service>(
&mut self,
Expand Down

0 comments on commit 8a7ba8f

Please sign in to comment.