Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: api to get migrations #179

Merged
merged 3 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 7 additions & 1 deletion packages/apalis-sql/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ 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
8 changes: 7 additions & 1 deletion packages/apalis-sql/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ 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
Loading