Skip to content
This repository was archived by the owner on Jul 25, 2022. It is now read-only.
Open
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
15 changes: 15 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# These are supported funding model platforms

github: vporton # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
thanks_dev: # Replace with a single thanks.dev username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
33 changes: 16 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use tokio_postgres::GenericClient;
use tokio_postgres::Client;

pub struct Migration {
tablename: String,
Expand All @@ -9,19 +9,18 @@ impl Migration {
Self { tablename }
}

async fn execute_script<C: GenericClient>(
async fn execute_script(
&self,
client: &C,
client: &Client,
content: &str,
) -> Result<(), tokio_postgres::Error> {
let stmt = client.prepare(content).await?;
client.execute(&stmt, &[]).await?;
client.batch_execute(content).await?;
Ok(())
}

async fn insert_migration<C: GenericClient>(
async fn insert_migration(
&self,
client: &C,
client: &Client,
name: &str,
) -> Result<(), tokio_postgres::Error> {
let query = format!("INSERT INTO {} (name) VALUES ($1)", self.tablename);
Expand All @@ -30,9 +29,9 @@ impl Migration {
Ok(())
}

async fn delete_migration<C: GenericClient>(
async fn delete_migration(
&self,
client: &C,
client: &Client,
name: &str,
) -> Result<(), tokio_postgres::Error> {
let query = format!("DELETE FROM {} WHERE name = $1", self.tablename);
Expand All @@ -41,9 +40,9 @@ impl Migration {
Ok(())
}

async fn create_table<C: GenericClient>(
async fn create_table(
&self,
client: &C,
client: &Client,
) -> Result<(), tokio_postgres::Error> {
log::debug!("creating migration table {}", self.tablename);
let query = format!(
Expand All @@ -54,9 +53,9 @@ impl Migration {
Ok(())
}

async fn exists<C: GenericClient>(
async fn exists(
&self,
client: &C,
client: &Client,
name: &str,
) -> Result<bool, tokio_postgres::Error> {
log::trace!("check if migration {} exists", name);
Expand All @@ -69,9 +68,9 @@ impl Migration {
}

/// Migrate all scripts up
pub async fn up<C: GenericClient>(
pub async fn up(
&self,
client: &mut C,
client: &mut Client,
scripts: &[(&str, &str)],
) -> Result<(), tokio_postgres::Error> {
log::info!("migrating up to {}", self.tablename);
Expand All @@ -87,9 +86,9 @@ impl Migration {
}

/// Migrate all scripts down
pub async fn down<C: GenericClient>(
pub async fn down(
&self,
client: &C,
client: &Client,
scripts: &[(&str, &str)],
) -> Result<(), tokio_postgres::Error> {
log::info!("migrating down to {}", self.tablename);
Expand Down