breaking(sqlite): libsqlite3-sys versioning, feature flags, safety changes (#3928)

This commit is contained in:
Austin Bonander
2025-07-17 01:13:32 -07:00
committed by GitHub
parent f7ef1ed1e9
commit 21598cfec6
52 changed files with 1152 additions and 623 deletions

View File

@@ -177,7 +177,7 @@ async fn do_run(opt: Opt) -> anyhow::Result<()> {
} => {
let config = config.load_config().await?;
connect_opts.populate_db_url(&config)?;
prepare::run(check, all, workspace, connect_opts, args).await?
prepare::run(&config, check, all, workspace, connect_opts, args).await?
}
#[cfg(feature = "completions")]
@@ -188,27 +188,9 @@ async fn do_run(opt: Opt) -> anyhow::Result<()> {
}
/// Attempt to connect to the database server, retrying up to `ops.connect_timeout`.
async fn connect(opts: &ConnectOpts) -> anyhow::Result<AnyConnection> {
async fn connect(config: &Config, opts: &ConnectOpts) -> anyhow::Result<AnyConnection> {
retry_connect_errors(opts, move |url| {
// This only handles the default case. For good support of
// the new command line options, we need to work out some
// way to make the appropriate ConfigOpt available here. I
// suspect that that infrastructure would be useful for
// other things in the future, as well, but it also seems
// like an extensive and intrusive change.
//
// On the other hand, the compile-time checking macros
// can't be configured to use a different config file at
// all, so I believe this is okay for the time being.
let config = Some(std::path::PathBuf::from("sqlx.toml")).and_then(|p| {
if p.exists() {
Some(p)
} else {
None
}
});
async move { AnyConnection::connect_with_config(url, config.clone()).await }
AnyConnection::connect_with_driver_config(url, &config.drivers)
})
.await
}

View File

@@ -130,7 +130,7 @@ pub async fn info(
) -> anyhow::Result<()> {
let migrator = migration_source.resolve(config).await?;
let mut conn = crate::connect(connect_opts).await?;
let mut conn = crate::connect(config, connect_opts).await?;
// FIXME: we shouldn't actually be creating anything here
for schema_name in &config.migrate.create_schemas {
@@ -229,7 +229,7 @@ pub async fn run(
}
}
let mut conn = crate::connect(connect_opts).await?;
let mut conn = crate::connect(config, connect_opts).await?;
for schema_name in &config.migrate.create_schemas {
conn.create_schema_if_not_exists(schema_name).await?;
@@ -331,7 +331,7 @@ pub async fn revert(
}
}
let mut conn = crate::connect(connect_opts).await?;
let mut conn = crate::connect(config, connect_opts).await?;
// FIXME: we should not be creating anything here if it doesn't exist
for schema_name in &config.migrate.create_schemas {

View File

@@ -5,14 +5,15 @@ use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
use crate::metadata::{manifest_dir, Metadata};
use crate::opt::ConnectOpts;
use crate::Config;
use anyhow::{bail, Context};
use console::style;
use sqlx::Connection;
use crate::metadata::{manifest_dir, Metadata};
use crate::opt::ConnectOpts;
pub struct PrepareCtx {
pub struct PrepareCtx<'a> {
pub config: &'a Config,
pub workspace: bool,
pub all: bool,
pub cargo: OsString,
@@ -21,7 +22,7 @@ pub struct PrepareCtx {
pub connect_opts: ConnectOpts,
}
impl PrepareCtx {
impl PrepareCtx<'_> {
/// Path to the directory where cached queries should be placed.
fn prepare_dir(&self) -> anyhow::Result<PathBuf> {
if self.workspace {
@@ -33,6 +34,7 @@ impl PrepareCtx {
}
pub async fn run(
config: &Config,
check: bool,
all: bool,
workspace: bool,
@@ -50,6 +52,7 @@ hint: This command only works in the manifest directory of a Cargo package or wo
let metadata: Metadata = Metadata::from_current_directory(&cargo)?;
let ctx = PrepareCtx {
config,
workspace,
all,
cargo,
@@ -65,9 +68,9 @@ hint: This command only works in the manifest directory of a Cargo package or wo
}
}
async fn prepare(ctx: &PrepareCtx) -> anyhow::Result<()> {
async fn prepare(ctx: &PrepareCtx<'_>) -> anyhow::Result<()> {
if ctx.connect_opts.database_url.is_some() {
check_backend(&ctx.connect_opts).await?;
check_backend(ctx.config, &ctx.connect_opts).await?;
}
let prepare_dir = ctx.prepare_dir()?;
@@ -93,9 +96,9 @@ async fn prepare(ctx: &PrepareCtx) -> anyhow::Result<()> {
Ok(())
}
async fn prepare_check(ctx: &PrepareCtx) -> anyhow::Result<()> {
async fn prepare_check(ctx: &PrepareCtx<'_>) -> anyhow::Result<()> {
if ctx.connect_opts.database_url.is_some() {
check_backend(&ctx.connect_opts).await?;
check_backend(ctx.config, &ctx.connect_opts).await?;
}
// Re-generate and store the queries in a separate directory from both the prepared
@@ -359,8 +362,8 @@ fn load_json_file(path: impl AsRef<Path>) -> anyhow::Result<serde_json::Value> {
Ok(serde_json::from_slice(&file_bytes)?)
}
async fn check_backend(opts: &ConnectOpts) -> anyhow::Result<()> {
crate::connect(opts).await?.close().await?;
async fn check_backend(config: &Config, opts: &ConnectOpts) -> anyhow::Result<()> {
crate::connect(config, opts).await?.close().await?;
Ok(())
}