diff --git a/.github/workflows/sqlx.yml b/.github/workflows/sqlx.yml index 452dcff5ab..05d5da0a3b 100644 --- a/.github/workflows/sqlx.yml +++ b/.github/workflows/sqlx.yml @@ -221,9 +221,7 @@ jobs: - uses: Swatinem/rust-cache@v2 - env: - # FIXME: needed to disable `ltree` tests in Postgres 9.6 - # but `PgLTree` should just fall back to text format - RUSTFLAGS: -D warnings --cfg postgres_${{ matrix.postgres }} + RUSTFLAGS: -D warnings --cfg postgres="${{ matrix.postgres }}" run: > cargo build --no-default-features @@ -231,6 +229,8 @@ jobs: - run: | docker compose -f tests/docker-compose.yml run -d -p 5432:5432 --name postgres_${{ matrix.postgres }} postgres_${{ matrix.postgres }} + + - run: | docker exec postgres_${{ matrix.postgres }} bash -c "until pg_isready; do sleep 1; done" # Create data dir for offline mode @@ -243,9 +243,7 @@ jobs: env: DATABASE_URL: postgres://postgres:password@localhost:5432/sqlx SQLX_OFFLINE_DIR: .sqlx - # FIXME: needed to disable `ltree` tests in Postgres 9.6 - # but `PgLTree` should just fall back to text format - RUSTFLAGS: --cfg postgres_${{ matrix.postgres }} + RUSTFLAGS: --cfg postgres="${{ matrix.postgres }}" # Run the `test-attr` test again to cover cleanup. - run: > @@ -256,9 +254,7 @@ jobs: env: DATABASE_URL: postgres://postgres:password@localhost:5432/sqlx SQLX_OFFLINE_DIR: .sqlx - # FIXME: needed to disable `ltree` tests in Postgres 9.6 - # but `PgLTree` should just fall back to text format - RUSTFLAGS: --cfg postgres_${{ matrix.postgres }} + RUSTFLAGS: --cfg postgres="${{ matrix.postgres }}" - if: matrix.tls != 'none' run: > @@ -268,9 +264,7 @@ jobs: env: DATABASE_URL: postgres://postgres:password@localhost:5432/sqlx?sslmode=verify-ca&sslrootcert=.%2Ftests%2Fcerts%2Fca.crt SQLX_OFFLINE_DIR: .sqlx - # FIXME: needed to disable `ltree` tests in Postgres 9.6 - # but `PgLTree` should just fall back to text format - RUSTFLAGS: --cfg postgres_${{ matrix.postgres }} + RUSTFLAGS: --cfg postgres="${{ matrix.postgres }}" # Remove test artifacts - run: cargo clean -p sqlx @@ -284,9 +278,7 @@ jobs: env: SQLX_OFFLINE: true SQLX_OFFLINE_DIR: .sqlx - # FIXME: needed to disable `ltree` tests in Postgres 9.6 - # but `PgLTree` should just fall back to text format - RUSTFLAGS: -D warnings --cfg postgres_${{ matrix.postgres }} + RUSTFLAGS: -D warnings --cfg postgres="${{ matrix.postgres }}" # Test macros in offline mode (still needs DATABASE_URL to run) - run: > @@ -298,27 +290,39 @@ jobs: DATABASE_URL: postgres://postgres:password@localhost:5432/sqlx SQLX_OFFLINE: true SQLX_OFFLINE_DIR: .sqlx - # FIXME: needed to disable `ltree` tests in Postgres 9.6 - # but `PgLTree` should just fall back to text format - RUSTFLAGS: --cfg postgres_${{ matrix.postgres }} + RUSTFLAGS: --cfg postgres="${{ matrix.postgres }}" - # client SSL authentication + postgres-ssl-auth: + name: Postgres SSL Auth + runs-on: ubuntu-24.04 + strategy: + matrix: + postgres: [ 13, 17 ] + runtime: [ async-std, tokio ] + tls: [ native-tls, rustls-aws-lc-rs, rustls-ring ] + needs: check + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + + - name: Setup Rust + run: rustup show active-toolchain || rustup toolchain install + + - uses: Swatinem/rust-cache@v2 - run: | - docker stop postgres_${{ matrix.postgres }} docker compose -f tests/docker-compose.yml run -d -p 5432:5432 --name postgres_${{ matrix.postgres }}_client_ssl postgres_${{ matrix.postgres }}_client_ssl + + - run: | docker exec postgres_${{ matrix.postgres }}_client_ssl bash -c "until pg_isready; do sleep 1; done" - - if: matrix.tls != 'none' - run: > + - run: > cargo test --no-default-features --features any,postgres,macros,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }} env: DATABASE_URL: postgres://postgres@localhost:5432/sqlx?sslmode=verify-ca&sslrootcert=.%2Ftests%2Fcerts%2Fca.crt&sslkey=.%2Ftests%2Fcerts%2Fkeys%2Fclient.key&sslcert=.%2Ftests%2Fcerts%2Fclient.crt - # FIXME: needed to disable `ltree` tests in Postgres 9.6 - # but `PgLTree` should just fall back to text format - RUSTFLAGS: --cfg postgres_${{ matrix.postgres }}_client_ssl + RUSTFLAGS: --cfg postgres="${{ matrix.postgres }}" mysql: name: MySQL diff --git a/Cargo.toml b/Cargo.toml index 997107fc3c..9c37eb4a5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -244,6 +244,7 @@ disallowed_methods = 'deny' level = 'warn' check-cfg = [ 'cfg(mariadb, values(any()))', + 'cfg(postgres, values(any()))', 'cfg(sqlite_ipaddr)', 'cfg(sqlite_test_sqlcipher)', ] @@ -434,7 +435,6 @@ name = "postgres-migrate" path = "tests/postgres/migrate.rs" required-features = ["postgres", "macros", "migrate"] - [[test]] name = "postgres-query-builder" path = "tests/postgres/query_builder.rs" diff --git a/sqlx-core/src/acquire.rs b/sqlx-core/src/acquire.rs index e84c3802b8..d7105f0463 100644 --- a/sqlx-core/src/acquire.rs +++ b/sqlx-core/src/acquire.rs @@ -13,9 +13,8 @@ use std::ops::{Deref, DerefMut}; /// connection or [`begin`][`Acquire::begin`] a transaction, then you can do it /// like that: /// -/// ```rust +/// ```rust,ignore /// # use sqlx::{Acquire, postgres::Postgres, error::BoxDynError}; -/// # #[cfg(any(postgres_9_6, postgres_15))] /// async fn run_query<'a, A>(conn: A) -> Result<(), BoxDynError> /// where /// A: Acquire<'a, Database = Postgres>, @@ -32,10 +31,9 @@ use std::ops::{Deref, DerefMut}; /// If you run into a lifetime error about "implementation of `sqlx::Acquire` is /// not general enough", the [workaround] looks like this: /// -/// ```rust +/// ```rust,ignore /// # use std::future::Future; /// # use sqlx::{Acquire, postgres::Postgres, error::BoxDynError}; -/// # #[cfg(any(postgres_9_6, postgres_15))] /// fn run_query<'a, 'c, A>(conn: A) -> impl Future> + Send + 'a /// where /// A: Acquire<'c, Database = Postgres> + Send + 'a, @@ -55,9 +53,8 @@ use std::ops::{Deref, DerefMut}; /// connection as an argument to a function, then it's easier to just accept a /// mutable reference to a database connection like so: /// -/// ```rust +/// ```rust,ignore /// # use sqlx::{postgres::PgConnection, error::BoxDynError}; -/// # #[cfg(any(postgres_9_6, postgres_15))] /// async fn run_query(conn: &mut PgConnection) -> Result<(), BoxDynError> { /// sqlx::query!("SELECT 1 as v").fetch_one(&mut *conn).await?; /// sqlx::query!("SELECT 2 as v").fetch_one(&mut *conn).await?; diff --git a/sqlx-core/src/database.rs b/sqlx-core/src/database.rs index 02d7a1214e..f89e5e7156 100644 --- a/sqlx-core/src/database.rs +++ b/sqlx-core/src/database.rs @@ -12,7 +12,7 @@ //! | [MariaDB] | 10.1+ | [`mysql`] | //! | [Microsoft SQL Server] | 2019 | [`mssql`] (Pending a full rewrite) | //! | [MySQL] | 5.6, 5.7, 8.0 | [`mysql`] | -//! | [PostgreSQL] | 9.5+ | [`postgres`] | +//! | [PostgreSQL] | 13+ | [`postgres`] | //! | [SQLite] | 3.20.1+ | [`sqlite`] | //! //! [MariaDB]: https://mariadb.com/ diff --git a/sqlx-postgres/src/types/array.rs b/sqlx-postgres/src/types/array.rs index 372c2891a8..692771ce4b 100644 --- a/sqlx-postgres/src/types/array.rs +++ b/sqlx-postgres/src/types/array.rs @@ -205,8 +205,8 @@ where } // appears to have been used in the past to communicate potential NULLS - // but reading source code back through our supported postgres versions (9.5+) - // this is never used for anything + // but reading source code back through our historically supported + // postgres versions (9.5+) this is never used for anything let _flags = buf.get_i32(); // the OID of the element diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 89ca096169..7e2599d997 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3" - services: # # MySQL 8.x, 5.7.x diff --git a/tests/postgres/postgres.rs b/tests/postgres/postgres.rs index c580bb4eed..8324982b67 100644 --- a/tests/postgres/postgres.rs +++ b/tests/postgres/postgres.rs @@ -2142,6 +2142,8 @@ create temporary table person( assert_eq!(people, p_query); Ok(()) } + +#[sqlx_macros::test] async fn test_pg_copy_chunked() -> anyhow::Result<()> { let mut conn = new::().await?; diff --git a/tests/postgres/types.rs b/tests/postgres/types.rs index 16a165278b..420e9732f3 100644 --- a/tests/postgres/types.rs +++ b/tests/postgres/types.rs @@ -519,7 +519,7 @@ test_type!(numrange_bigdecimal>(Postgres, Bound::Excluded("2.4".parse::().unwrap()))) )); -#[cfg(any(postgres_14, postgres_15))] +#[cfg(not(postgres = "13"))] test_type!(cube(Postgres, "cube(2)" == sqlx::postgres::types::PgCube::Point(2.), "cube(2.1)" == sqlx::postgres::types::PgCube::Point(2.1), @@ -530,51 +530,43 @@ test_type!(cube(Postgres, "cube(array[2,3,4],array[4,5,6])" == sqlx::postgres::types::PgCube::MultiDimension(vec![vec![2.,3.,4.],vec![4.,5.,6.]]), )); -#[cfg(any(postgres_14, postgres_15))] +#[cfg(not(postgres = "13"))] test_type!(_cube>(Postgres, "array[cube(2),cube(2)]" == vec![sqlx::postgres::types::PgCube::Point(2.), sqlx::postgres::types::PgCube::Point(2.)], "array[cube(2.2,-3.4)]" == vec![sqlx::postgres::types::PgCube::OneDimensionInterval(2.2, -3.4)], )); -#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))] test_type!(point(Postgres, "point(2.2,-3.4)" ~= sqlx::postgres::types::PgPoint { x: 2.2, y:-3.4 }, )); -#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))] test_type!(_point>(Postgres, "array[point(2,3),point(2.1,3.4)]" @= vec![sqlx::postgres::types::PgPoint { x:2., y: 3. }, sqlx::postgres::types::PgPoint { x:2.1, y: 3.4 }], "array[point(2.2,-3.4)]" @= vec![sqlx::postgres::types::PgPoint { x: 2.2, y: -3.4 }], )); -#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))] test_type!(line(Postgres, "line('{1.1, -2.2, 3.3}')" == sqlx::postgres::types::PgLine { a: 1.1, b:-2.2, c: 3.3 }, "line('((0.0, 0.0), (1.0,1.0))')" == sqlx::postgres::types::PgLine { a: 1., b: -1., c: 0. }, )); -#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))] test_type!(lseg(Postgres, "lseg('((1.0, 2.0), (3.0,4.0))')" == sqlx::postgres::types::PgLSeg { start_x: 1., start_y: 2., end_x: 3. , end_y: 4.}, )); -#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))] test_type!(box(Postgres, "box('((1.0, 2.0), (3.0,4.0))')" == sqlx::postgres::types::PgBox { upper_right_x: 3., upper_right_y: 4., lower_left_x: 1. , lower_left_y: 2.}, )); -#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))] test_type!(_box>(Postgres, "array[box('1,2,3,4'),box('((1.1, 2.2), (3.3, 4.4))')]" @= vec![sqlx::postgres::types::PgBox { upper_right_x: 3., upper_right_y: 4., lower_left_x: 1., lower_left_y: 2. }, sqlx::postgres::types::PgBox { upper_right_x: 3.3, upper_right_y: 4.4, lower_left_x: 1.1, lower_left_y: 2.2 }], )); -#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))] test_type!(path(Postgres, "path('((1.0, 2.0), (3.0,4.0))')" == sqlx::postgres::types::PgPath { closed: true, points: vec![ sqlx::postgres::types::PgPoint { x: 1., y: 2. }, sqlx::postgres::types::PgPoint { x: 3. , y: 4. } ]}, "path('[(1.0, 2.0), (3.0,4.0)]')" == sqlx::postgres::types::PgPath { closed: false, points: vec![ sqlx::postgres::types::PgPoint { x: 1., y: 2. }, sqlx::postgres::types::PgPoint { x: 3. , y: 4. } ]}, )); -#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))] test_type!(polygon(Postgres, "polygon('((-2,-3),(-1,-3),(-1,-1),(1,1),(1,3),(2,3),(2,-3),(1,-3),(1,0),(-1,0),(-1,-2),(-2,-2))')" ~= sqlx::postgres::types::PgPolygon { points: vec![ sqlx::postgres::types::PgPoint { x: -2., y: -3. }, sqlx::postgres::types::PgPoint { x: -1., y: -3. }, sqlx::postgres::types::PgPoint { x: -1., y: -1. }, sqlx::postgres::types::PgPoint { x: 1., y: 1. }, @@ -583,7 +575,6 @@ test_type!(polygon(Postgres, ]}, )); -#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))] test_type!(circle(Postgres, "circle('<(1.1, -2.2), 3.3>')" ~= sqlx::postgres::types::PgCircle { x: 1.1, y:-2.2, radius: 3.3 }, "circle('((1.1, -2.2), 3.3)')" ~= sqlx::postgres::types::PgCircle { x: 1.1, y:-2.2, radius: 3.3 }, @@ -678,17 +669,11 @@ test_prepared_type!(citext_array>(Postgres, ], )); -// FIXME: needed to disable `ltree` tests in version that don't have a binary format for it -// but `PgLTree` should just fall back to text format -#[cfg(any(postgres_14, postgres_15))] test_type!(ltree(Postgres, "'Foo.Bar.Baz.Quux'::ltree" == sqlx::postgres::types::PgLTree::from_str("Foo.Bar.Baz.Quux").unwrap(), "'Alpha.Beta.Delta.Gamma'::ltree" == sqlx::postgres::types::PgLTree::try_from_iter(["Alpha", "Beta", "Delta", "Gamma"]).unwrap(), )); -// FIXME: needed to disable `ltree` tests in version that don't have a binary format for it -// but `PgLTree` should just fall back to text format -#[cfg(any(postgres_14, postgres_15))] test_type!(ltree_vec>(Postgres, "array['Foo.Bar.Baz.Quux', 'Alpha.Beta.Delta.Gamma']::ltree[]" == vec![