diff --git a/Cargo.toml b/Cargo.toml index 0a18c39..e482acb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,16 +15,16 @@ members = ["sqlxmq_macros", "sqlxmq_stress"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -sqlx = { version = "0.7.1", features = ["postgres", "chrono", "uuid"] } -tokio = { version = "1.8.3", features = ["full"] } -dotenv = "0.15.0" -chrono = "0.4.19" -uuid = { version = "1.1.2", features = ["v4"] } -log = "0.4.14" -serde_json = "1.0.64" -serde = "1.0.124" +sqlx = { version = "~0.8.1", features = ["postgres", "chrono", "uuid"] } +tokio = { version = "~1.38", features = ["full"] } +dotenvy = "~0.15.7" +chrono = "~0.4.19" +uuid = { version = "~1.1", features = ["v4"] } +log = "~0.4" +serde_json = "~1.0" +serde = "~1.0" sqlxmq_macros = { version = "0.5.0", path = "sqlxmq_macros" } -anymap2 = "0.13.0" +anymap2 = "~0.13" [features] default = ["runtime-tokio-native-tls"] @@ -32,7 +32,7 @@ runtime-tokio-native-tls = ["sqlx/runtime-tokio-native-tls"] runtime-tokio-rustls = ["sqlx/runtime-tokio-rustls"] [dev-dependencies] -dotenv = "0.15.0" +dotenvy = "0.15.0" pretty_env_logger = "0.4.0" futures = "0.3.13" tokio = { version = "1", features = ["full"] } diff --git a/devsupport/.gitignore b/devsupport/.gitignore new file mode 100644 index 0000000..d44a8fa --- /dev/null +++ b/devsupport/.gitignore @@ -0,0 +1,3 @@ +db/ +db_sockets/ +!db_sockets/.gitkeep diff --git a/devsupport/db_sockets/.gitkeep b/devsupport/db_sockets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/devsupport/run_postgres.sh b/devsupport/run_postgres.sh new file mode 100755 index 0000000..75a0ebb --- /dev/null +++ b/devsupport/run_postgres.sh @@ -0,0 +1,8 @@ +#! /usr/bin/env bash + +set -e +devsupport=$(realpath $(dirname $0)) +if [ ! -d "$PGDATA" ]; then + initdb --no-instructions +fi +exec postgres -c listen_addresses= -c unix_socket_directories="${devsupport}/db_sockets" diff --git a/devsupport/setup_postgres.sh b/devsupport/setup_postgres.sh new file mode 100755 index 0000000..a9a5ef3 --- /dev/null +++ b/devsupport/setup_postgres.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +sqlx database create +sqlx migrate run diff --git a/envrc.example b/envrc.example new file mode 100644 index 0000000..5ab056f --- /dev/null +++ b/envrc.example @@ -0,0 +1,7 @@ +export db_socket_path=$(echo $(pwd)/devsupport/db_sockets) +export PGDATA="$(pwd)/devsupport/db" +export DATABASE_URL="postgres:///sqlxmq?host=$db_socket_path&sslmode=disable" +# export SQLX_OFFLINE=yes + +session_name sqlxmq +use lorri diff --git a/examples/graceful-shutdown.rs b/examples/graceful-shutdown.rs index 1af237e..df7a402 100644 --- a/examples/graceful-shutdown.rs +++ b/examples/graceful-shutdown.rs @@ -4,7 +4,7 @@ use tokio::time; #[tokio::main] async fn main() -> Result<(), Box> { - dotenv::dotenv().ok(); + dotenvy::dotenv().ok(); let db = sqlx::PgPool::connect(&std::env::var("DATABASE_URL").unwrap()).await?; sleep.builder().set_json(&5u64)?.spawn(&db).await?; diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..d3d0f8a --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1717179513, + "narHash": "sha256-vboIEwIQojofItm2xGCdZCzW96U85l9nDW3ifMuAIdM=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "63dacb46bf939521bdc93981b4cbb7ecb58427a0", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..69dc398 --- /dev/null +++ b/flake.nix @@ -0,0 +1,36 @@ +{ + description = "sqlxmq is a message queue built by Diggsey on rust sqlx"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/24.05"; + flake-utils.url = "github:numtide/flake-utils"; + }; + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = (import "${nixpkgs}" { + inherit system; + }); + + runDeps = with pkgs; [ + openssl + ]; + + buildDeps = with pkgs; [ + pkg-config + ] ++ runDeps; + in rec { + devShells.devShell.${system} = pkgs.mkShell { + buildInputs = with pkgs; [ + cargo + cargo-expand + rustc + rust-analyzer + clippy + + postgresql + sqlx-cli + ] ++ buildDeps; + }; + devShells.default = devShells.devShell.${system}; + }); +} diff --git a/sqlxmq_stress/src/main.rs b/sqlxmq_stress/src/main.rs index 1721b7b..8daad76 100644 --- a/sqlxmq_stress/src/main.rs +++ b/sqlxmq_stress/src/main.rs @@ -80,7 +80,7 @@ async fn schedule_tasks(num_jobs: usize, interval: Duration, pool: Pool Result<(), Box> { - let _ = dotenv::dotenv(); + let _ = dotenvy::dotenv(); let pool = Pool::connect(&env::var("DATABASE_URL")?).await?; diff --git a/src/lib.rs b/src/lib.rs index 3423821..fc279e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -278,6 +278,8 @@ mod tests { use tokio::sync::{Mutex, MutexGuard}; use tokio::task; + // field 0 is never read, but its drop is important + #[allow(dead_code)] struct TestGuard(MutexGuard<'static, ()>, T); impl Deref for TestGuard { @@ -294,7 +296,7 @@ mod tests { let guard = TEST_MUTEX.lock().await; - let _ = dotenv::dotenv(); + let _ = dotenvy::dotenv(); INIT_LOGGER.call_once(pretty_env_logger::init);