diff --git a/.github/workflows/sqlx.yml b/.github/workflows/sqlx.yml index 4b080b42d2..0af338b02d 100644 --- a/.github/workflows/sqlx.yml +++ b/.github/workflows/sqlx.yml @@ -215,9 +215,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 --cfg postgres="${{ matrix.postgres }}" run: > cargo build --no-default-features @@ -237,9 +235,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 --cfg postgres="${{ matrix.postgres }}" # Run the `test-attr` test again to cover cleanup. - run: > @@ -250,9 +246,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 --cfg postgres="${{ matrix.postgres }}" - if: matrix.tls != 'none' run: > @@ -262,9 +256,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 --cfg postgres="${{ matrix.postgres }}" # Remove test artifacts - run: cargo clean -p sqlx @@ -278,9 +270,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 --cfg postgres="${{ matrix.postgres }}" # Test macros in offline mode (still needs DATABASE_URL to run) - run: > @@ -292,9 +282,7 @@ 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 --cfg postgres="${{ matrix.postgres }}" # client SSL authentication @@ -310,9 +298,7 @@ jobs: --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 --cfg postgres="${{ matrix.postgres }}" mysql: name: MySQL diff --git a/Cargo.toml b/Cargo.toml index 6d08df23d3..fa5409cedd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -245,6 +245,8 @@ level = 'warn' check-cfg = [ 'cfg(mariadb, values(any()))', 'cfg(sqlite_ipaddr)', + 'cfg(postgres)', + 'cfg(postgres, values(any()))', 'cfg(sqlite_test_sqlcipher)', ] 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/postgres/postgres.rs b/tests/postgres/postgres.rs index c580bb4eed..ee7330c621 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(()) } + +#[allow(unused)] 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..5d99f14c01 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(all(postgres, 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,51 @@ 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(all(postgres, 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))] +#[cfg(postgres)] 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))] +#[cfg(postgres)] 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))] +#[cfg(postgres)] 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))] +#[cfg(postgres)] 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))] +#[cfg(postgres)] 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))] +#[cfg(postgres)] 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))] +#[cfg(postgres)] 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))] +#[cfg(postgres)] 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 +583,7 @@ test_type!(polygon(Postgres, ]}, )); -#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))] +#[cfg(postgres)] 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 +678,13 @@ 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))] +#[cfg(postgres)] 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))] +#[cfg(postgres)] test_type!(ltree_vec>(Postgres, "array['Foo.Bar.Baz.Quux', 'Alpha.Beta.Delta.Gamma']::ltree[]" == vec![