Skip to content

chore: Fix warnings for custom postgres_## cfg flags #3950

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
54 changes: 29 additions & 25 deletions .github/workflows/sqlx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,16 @@ 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
--features postgres,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }},macros,migrate

- 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
Expand All @@ -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: >
Expand All @@ -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: >
Expand All @@ -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
Expand All @@ -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: >
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
]
Expand Down Expand Up @@ -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"
Expand Down
9 changes: 3 additions & 6 deletions sqlx-core/src/acquire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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<Output = Result<(), BoxDynError>> + Send + 'a
/// where
/// A: Acquire<'c, Database = Postgres> + Send + 'a,
Expand All @@ -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?;
Expand Down
2 changes: 1 addition & 1 deletion sqlx-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
4 changes: 2 additions & 2 deletions sqlx-postgres/src/types/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

services:
#
# MySQL 8.x, 5.7.x
Expand Down
2 changes: 2 additions & 0 deletions tests/postgres/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Postgres>().await?;

Expand Down
19 changes: 2 additions & 17 deletions tests/postgres/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ test_type!(numrange_bigdecimal<PgRange<sqlx::types::BigDecimal>>(Postgres,
Bound::Excluded("2.4".parse::<sqlx::types::BigDecimal>().unwrap())))
));

#[cfg(any(postgres_14, postgres_15))]
#[cfg(not(postgres = "13"))]
test_type!(cube<sqlx::postgres::types::PgCube>(Postgres,
"cube(2)" == sqlx::postgres::types::PgCube::Point(2.),
"cube(2.1)" == sqlx::postgres::types::PgCube::Point(2.1),
Expand All @@ -530,51 +530,43 @@ test_type!(cube<sqlx::postgres::types::PgCube>(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<Vec<sqlx::postgres::types::PgCube>>(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<sqlx::postgres::types::PgPoint>(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<Vec<sqlx::postgres::types::PgPoint>>(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<sqlx::postgres::types::PgLine>(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<sqlx::postgres::types::PgLSeg>(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<sqlx::postgres::types::PgBox>(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<Vec<sqlx::postgres::types::PgBox>>(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<sqlx::postgres::types::PgPath>(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<sqlx::postgres::types::PgPolygon>(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. },
Expand All @@ -583,7 +575,6 @@ test_type!(polygon<sqlx::postgres::types::PgPolygon>(Postgres,
]},
));

#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))]
test_type!(circle<sqlx::postgres::types::PgCircle>(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 },
Expand Down Expand Up @@ -678,17 +669,11 @@ test_prepared_type!(citext_array<Vec<PgCiText>>(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<sqlx::postgres::types::PgLTree>(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<Vec<sqlx::postgres::types::PgLTree>>(Postgres,
"array['Foo.Bar.Baz.Quux', 'Alpha.Beta.Delta.Gamma']::ltree[]" ==
vec![
Expand Down
Loading