Skip to content

Commit e77f32e

Browse files
authored
chore: Fix warnings for custom postgres_## cfg flags (#3950)
* chore: Fix warnings for custom postgres_## cfg flags Signed-off-by: Joshua Potts <[email protected]> * pr feedback - reorder cfg allowance; enable test_pg_copy_chunked test Signed-off-by: Joshua Potts <[email protected]> * refactor(postgres): Remove two more deprecated cfg flag uses (from docstrings) Signed-off-by: Joshua Potts <[email protected]> * refactor(ci): Use separate job for postgres ssl auth tests Signed-off-by: Joshua Potts <[email protected]> --------- Signed-off-by: Joshua Potts <[email protected]>
1 parent 1f7af3a commit e77f32e

File tree

7 files changed

+18
-48
lines changed

7 files changed

+18
-48
lines changed

.github/workflows/sqlx.yml

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,7 @@ jobs:
221221
- uses: Swatinem/rust-cache@v2
222222

223223
- env:
224-
# FIXME: needed to disable `ltree` tests in Postgres 9.6
225-
# but `PgLTree` should just fall back to text format
226-
RUSTFLAGS: -D warnings --cfg postgres_${{ matrix.postgres }}
224+
RUSTFLAGS: -D warnings --cfg postgres="${{ matrix.postgres }}"
227225
run: >
228226
cargo build
229227
--no-default-features
@@ -245,9 +243,7 @@ jobs:
245243
env:
246244
DATABASE_URL: postgres://postgres:password@localhost:5432/sqlx
247245
SQLX_OFFLINE_DIR: .sqlx
248-
# FIXME: needed to disable `ltree` tests in Postgres 9.6
249-
# but `PgLTree` should just fall back to text format
250-
RUSTFLAGS: --cfg postgres_${{ matrix.postgres }}
246+
RUSTFLAGS: --cfg postgres="${{ matrix.postgres }}"
251247
252248
# Run the `test-attr` test again to cover cleanup.
253249
- run: >
@@ -258,9 +254,7 @@ jobs:
258254
env:
259255
DATABASE_URL: postgres://postgres:password@localhost:5432/sqlx
260256
SQLX_OFFLINE_DIR: .sqlx
261-
# FIXME: needed to disable `ltree` tests in Postgres 9.6
262-
# but `PgLTree` should just fall back to text format
263-
RUSTFLAGS: --cfg postgres_${{ matrix.postgres }}
257+
RUSTFLAGS: --cfg postgres="${{ matrix.postgres }}"
264258
265259
- if: matrix.tls != 'none'
266260
run: >
@@ -270,9 +264,7 @@ jobs:
270264
env:
271265
DATABASE_URL: postgres://postgres:password@localhost:5432/sqlx?sslmode=verify-ca&sslrootcert=.%2Ftests%2Fcerts%2Fca.crt
272266
SQLX_OFFLINE_DIR: .sqlx
273-
# FIXME: needed to disable `ltree` tests in Postgres 9.6
274-
# but `PgLTree` should just fall back to text format
275-
RUSTFLAGS: --cfg postgres_${{ matrix.postgres }}
267+
RUSTFLAGS: --cfg postgres="${{ matrix.postgres }}"
276268

277269
# Remove test artifacts
278270
- run: cargo clean -p sqlx
@@ -286,9 +278,7 @@ jobs:
286278
env:
287279
SQLX_OFFLINE: true
288280
SQLX_OFFLINE_DIR: .sqlx
289-
# FIXME: needed to disable `ltree` tests in Postgres 9.6
290-
# but `PgLTree` should just fall back to text format
291-
RUSTFLAGS: -D warnings --cfg postgres_${{ matrix.postgres }}
281+
RUSTFLAGS: -D warnings --cfg postgres="${{ matrix.postgres }}"
292282
293283
# Test macros in offline mode (still needs DATABASE_URL to run)
294284
- run: >
@@ -300,9 +290,7 @@ jobs:
300290
DATABASE_URL: postgres://postgres:password@localhost:5432/sqlx
301291
SQLX_OFFLINE: true
302292
SQLX_OFFLINE_DIR: .sqlx
303-
# FIXME: needed to disable `ltree` tests in Postgres 9.6
304-
# but `PgLTree` should just fall back to text format
305-
RUSTFLAGS: --cfg postgres_${{ matrix.postgres }}
293+
RUSTFLAGS: --cfg postgres="${{ matrix.postgres }}"
306294
307295
postgres-ssl-auth:
308296
name: Postgres SSL Auth
@@ -334,9 +322,7 @@ jobs:
334322
--features any,postgres,macros,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
335323
env:
336324
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
337-
# FIXME: needed to disable `ltree` tests in Postgres 9.6
338-
# but `PgLTree` should just fall back to text format
339-
RUSTFLAGS: --cfg postgres_${{ matrix.postgres }}_client_ssl
325+
RUSTFLAGS: --cfg postgres="${{ matrix.postgres }}"
340326
341327
mysql:
342328
name: MySQL

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ disallowed_methods = 'deny'
244244
level = 'warn'
245245
check-cfg = [
246246
'cfg(mariadb, values(any()))',
247+
'cfg(postgres, values(any()))',
247248
'cfg(sqlite_ipaddr)',
248249
'cfg(sqlite_test_sqlcipher)',
249250
]
@@ -434,7 +435,6 @@ name = "postgres-migrate"
434435
path = "tests/postgres/migrate.rs"
435436
required-features = ["postgres", "macros", "migrate"]
436437

437-
438438
[[test]]
439439
name = "postgres-query-builder"
440440
path = "tests/postgres/query_builder.rs"

sqlx-core/src/acquire.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ use std::ops::{Deref, DerefMut};
1313
/// connection or [`begin`][`Acquire::begin`] a transaction, then you can do it
1414
/// like that:
1515
///
16-
/// ```rust
16+
/// ```rust,ignore
1717
/// # use sqlx::{Acquire, postgres::Postgres, error::BoxDynError};
18-
/// # #[cfg(any(postgres_9_6, postgres_15))]
1918
/// async fn run_query<'a, A>(conn: A) -> Result<(), BoxDynError>
2019
/// where
2120
/// A: Acquire<'a, Database = Postgres>,
@@ -32,10 +31,9 @@ use std::ops::{Deref, DerefMut};
3231
/// If you run into a lifetime error about "implementation of `sqlx::Acquire` is
3332
/// not general enough", the [workaround] looks like this:
3433
///
35-
/// ```rust
34+
/// ```rust,ignore
3635
/// # use std::future::Future;
3736
/// # use sqlx::{Acquire, postgres::Postgres, error::BoxDynError};
38-
/// # #[cfg(any(postgres_9_6, postgres_15))]
3937
/// fn run_query<'a, 'c, A>(conn: A) -> impl Future<Output = Result<(), BoxDynError>> + Send + 'a
4038
/// where
4139
/// A: Acquire<'c, Database = Postgres> + Send + 'a,
@@ -55,9 +53,8 @@ use std::ops::{Deref, DerefMut};
5553
/// connection as an argument to a function, then it's easier to just accept a
5654
/// mutable reference to a database connection like so:
5755
///
58-
/// ```rust
56+
/// ```rust,ignore
5957
/// # use sqlx::{postgres::PgConnection, error::BoxDynError};
60-
/// # #[cfg(any(postgres_9_6, postgres_15))]
6158
/// async fn run_query(conn: &mut PgConnection) -> Result<(), BoxDynError> {
6259
/// sqlx::query!("SELECT 1 as v").fetch_one(&mut *conn).await?;
6360
/// sqlx::query!("SELECT 2 as v").fetch_one(&mut *conn).await?;

sqlx-core/src/database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//! | [MariaDB] | 10.1+ | [`mysql`] |
1313
//! | [Microsoft SQL Server] | 2019 | [`mssql`] (Pending a full rewrite) |
1414
//! | [MySQL] | 5.6, 5.7, 8.0 | [`mysql`] |
15-
//! | [PostgreSQL] | 9.5+ | [`postgres`] |
15+
//! | [PostgreSQL] | 13+ | [`postgres`] |
1616
//! | [SQLite] | 3.20.1+ | [`sqlite`] |
1717
//!
1818
//! [MariaDB]: https://mariadb.com/

sqlx-postgres/src/types/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ where
205205
}
206206

207207
// appears to have been used in the past to communicate potential NULLS
208-
// but reading source code back through our supported postgres versions (9.5+)
209-
// this is never used for anything
208+
// but reading source code back through our historically supported
209+
// postgres versions (9.5+) this is never used for anything
210210
let _flags = buf.get_i32();
211211

212212
// the OID of the element

tests/postgres/postgres.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2142,6 +2142,8 @@ create temporary table person(
21422142
assert_eq!(people, p_query);
21432143
Ok(())
21442144
}
2145+
2146+
#[sqlx_macros::test]
21452147
async fn test_pg_copy_chunked() -> anyhow::Result<()> {
21462148
let mut conn = new::<Postgres>().await?;
21472149

tests/postgres/types.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ test_type!(numrange_bigdecimal<PgRange<sqlx::types::BigDecimal>>(Postgres,
519519
Bound::Excluded("2.4".parse::<sqlx::types::BigDecimal>().unwrap())))
520520
));
521521

522-
#[cfg(any(postgres_14, postgres_15))]
522+
#[cfg(not(postgres = "13"))]
523523
test_type!(cube<sqlx::postgres::types::PgCube>(Postgres,
524524
"cube(2)" == sqlx::postgres::types::PgCube::Point(2.),
525525
"cube(2.1)" == sqlx::postgres::types::PgCube::Point(2.1),
@@ -530,51 +530,43 @@ test_type!(cube<sqlx::postgres::types::PgCube>(Postgres,
530530
"cube(array[2,3,4],array[4,5,6])" == sqlx::postgres::types::PgCube::MultiDimension(vec![vec![2.,3.,4.],vec![4.,5.,6.]]),
531531
));
532532

533-
#[cfg(any(postgres_14, postgres_15))]
533+
#[cfg(not(postgres = "13"))]
534534
test_type!(_cube<Vec<sqlx::postgres::types::PgCube>>(Postgres,
535535
"array[cube(2),cube(2)]" == vec![sqlx::postgres::types::PgCube::Point(2.), sqlx::postgres::types::PgCube::Point(2.)],
536536
"array[cube(2.2,-3.4)]" == vec![sqlx::postgres::types::PgCube::OneDimensionInterval(2.2, -3.4)],
537537
));
538538

539-
#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))]
540539
test_type!(point<sqlx::postgres::types::PgPoint>(Postgres,
541540
"point(2.2,-3.4)" ~= sqlx::postgres::types::PgPoint { x: 2.2, y:-3.4 },
542541
));
543542

544-
#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))]
545543
test_type!(_point<Vec<sqlx::postgres::types::PgPoint>>(Postgres,
546544
"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 }],
547545
"array[point(2.2,-3.4)]" @= vec![sqlx::postgres::types::PgPoint { x: 2.2, y: -3.4 }],
548546
));
549547

550-
#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))]
551548
test_type!(line<sqlx::postgres::types::PgLine>(Postgres,
552549
"line('{1.1, -2.2, 3.3}')" == sqlx::postgres::types::PgLine { a: 1.1, b:-2.2, c: 3.3 },
553550
"line('((0.0, 0.0), (1.0,1.0))')" == sqlx::postgres::types::PgLine { a: 1., b: -1., c: 0. },
554551
));
555552

556-
#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))]
557553
test_type!(lseg<sqlx::postgres::types::PgLSeg>(Postgres,
558554
"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.},
559555
));
560556

561-
#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))]
562557
test_type!(box<sqlx::postgres::types::PgBox>(Postgres,
563558
"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.},
564559
));
565560

566-
#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))]
567561
test_type!(_box<Vec<sqlx::postgres::types::PgBox>>(Postgres,
568562
"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 }],
569563
));
570564

571-
#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))]
572565
test_type!(path<sqlx::postgres::types::PgPath>(Postgres,
573566
"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. } ]},
574567
"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. } ]},
575568
));
576569

577-
#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))]
578570
test_type!(polygon<sqlx::postgres::types::PgPolygon>(Postgres,
579571
"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![
580572
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<sqlx::postgres::types::PgPolygon>(Postgres,
583575
]},
584576
));
585577

586-
#[cfg(any(postgres_12, postgres_13, postgres_14, postgres_15))]
587578
test_type!(circle<sqlx::postgres::types::PgCircle>(Postgres,
588579
"circle('<(1.1, -2.2), 3.3>')" ~= sqlx::postgres::types::PgCircle { x: 1.1, y:-2.2, radius: 3.3 },
589580
"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<Vec<PgCiText>>(Postgres,
678669
],
679670
));
680671

681-
// FIXME: needed to disable `ltree` tests in version that don't have a binary format for it
682-
// but `PgLTree` should just fall back to text format
683-
#[cfg(any(postgres_14, postgres_15))]
684672
test_type!(ltree<sqlx::postgres::types::PgLTree>(Postgres,
685673
"'Foo.Bar.Baz.Quux'::ltree" == sqlx::postgres::types::PgLTree::from_str("Foo.Bar.Baz.Quux").unwrap(),
686674
"'Alpha.Beta.Delta.Gamma'::ltree" == sqlx::postgres::types::PgLTree::try_from_iter(["Alpha", "Beta", "Delta", "Gamma"]).unwrap(),
687675
));
688676

689-
// FIXME: needed to disable `ltree` tests in version that don't have a binary format for it
690-
// but `PgLTree` should just fall back to text format
691-
#[cfg(any(postgres_14, postgres_15))]
692677
test_type!(ltree_vec<Vec<sqlx::postgres::types::PgLTree>>(Postgres,
693678
"array['Foo.Bar.Baz.Quux', 'Alpha.Beta.Delta.Gamma']::ltree[]" ==
694679
vec![

0 commit comments

Comments
 (0)