161 Commits

Author SHA1 Message Date
Austin Bonander
a2a219f175
fix CI: replace removed macOS runner, deprecated use of Command::cargo_bin() (#4134)
* fix(ci): update macOS intel runner version

* fix(cli/tests): replace use of deprecated `Command::cargo_bin()`
2025-12-24 21:40:53 -08:00
Joey de Waal
e8384f2a00
fix spelling (#4069) 2025-10-28 05:18:47 -07:00
Austin Bonander
388c424f48
fix(macros): smarter .env loading, caching, and invalidation (#4053)
* fix(macros): smarter `.env` loading, caching, and invalidation

* feat(mysql): test `.env` loading in CI

* feat(postgres): test `.env` loading in CI

* feat(macros): allow `DATABASE_URL` to be empty

* fix(examples/postgres): make `cargo-sqlx` executable

* fix(examples/postgres): `cargo sqlx` invocation

* feat(examples/postgres): check offline prepare on more examples

* fix(examples/postgres): the name of this step

* fix(cli): don't suppress error from `dotenv()`

* fix(ci/examples/postgres): don't use heredoc in this step

* fix(ci/examples/postgres): multi-tenant

* fix(ci/examples/sqlite): test `.env` loading

* chore: add CHANGELOG entry
2025-10-14 17:31:12 -07:00
Austin Bonander
66526d9c56
refactor: tweaks after #3791 (#4022)
* restore fallback to `async-io` for `connect_tcp()` when `runtime-tokio` feature is enabled
* `smol` and `async-global-executor` both use `async-task`, so `JoinHandle` impls can be consolidated
* no need for duplicate `yield_now()` impls
* delete `impl Socket for ()`
2025-09-08 14:28:58 -07:00
martin-kolarik
6b828e698f
Smol+async global executor 1.80 dev (#3791)
* Sqlx-core: rename async_io dependency for async-std

* Sqlx-core: simplify TimeoutError

* Sqlx-core: code for async-global-executor

* Sqlx: integrate async-global-executor feature

* Note to unsafe

* Step up MSRV as async-global-executor needs it

* Sqlx-core: fix of unix socket build

* Unsafe fixes, smol executor added

* Workflow fix

* Changes outside sqlx_rt

* Cleanup conditional rt compilation

* Warning

* Add executors to test matrix

* Fix of skipping code sqlite due to mismatch in cargo feature names

* Smol executor isolated

* Fix, reduce number of tests, remove async_std

* Fix of test_block_on, regression

* Format fixes

* async-global-executor added

* async-std changed to 1.13

* litemap, zerofrom requires rustc 1.81

* Fix of missing _sqlite in cargo.toml

* Clippy lints

* Clean up

* Remove features combinations

* Fixes after merge

* Fix of compiling connect_tcp_address with both tokio + other executor selected

* Try to fix CI -Z minimal-versions check

Try to fix CI -Z minimal-versions check
2025-09-08 11:17:55 -07:00
Predko Silvestr
ed002f89e5
CLi: made cli-lib modules publicly available for other crates (#3881)
* change module visibility to public to easily integrate into other crates

* update module documentation for SQLx CLI
2025-08-15 15:06:13 -07:00
Austin Bonander
21598cfec6
breaking(sqlite): libsqlite3-sys versioning, feature flags, safety changes (#3928) 2025-07-17 01:13:32 -07:00
djarb
f7ef1ed1e9
feat(sqlx.toml): support SQLite extensions in macros and sqlx-cli (#3917)
* feat: create `sqlx.toml` format

* feat: add support for ignored_chars config to sqlx_core::migrate

* chore: test ignored_chars with `U+FEFF` (ZWNBSP/BOM)

https://en.wikipedia.org/wiki/Byte_order_mark

* refactor: make `Config` always compiled

simplifies usage while still making parsing optional for less generated code

* refactor: add origin information to `Column`

* feat(macros): implement `type_override` and `column_override` from `sqlx.toml`

* refactor(sqlx.toml): make all keys kebab-case, create `macros.preferred-crates`

* feat: make macros aware of `macros.preferred-crates`

* feat: make `sqlx-cli` aware of `database-url-var`

* feat: teach macros about `migrate.table-name`, `migrations-dir`

* feat: teach macros about `migrate.ignored-chars`

* feat: teach `sqlx-cli` about `migrate.defaults`

* feat: teach `sqlx-cli` about `migrate.migrations-dir`

* feat: teach `sqlx-cli` about `migrate.table-name`

* feat: introduce `migrate.create-schemas`

* WIP feat: create multi-tenant database example

* SQLite extension loading via sqlx.toml for CLI and query macros

* fix: allow start_database to function when the SQLite database file does not already exist

* Added example demonstrating migration and compile-time checking with SQLite extensions

* remove accidentally included db file

* Update sqlx-core/src/config/common.rs

Doc formatting tweak

Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>

* feat: create `sqlx.toml` format

* feat: add support for ignored_chars config to sqlx_core::migrate

* chore: test ignored_chars with `U+FEFF` (ZWNBSP/BOM)

https://en.wikipedia.org/wiki/Byte_order_mark

* refactor: make `Config` always compiled

simplifies usage while still making parsing optional for less generated code

* refactor: add origin information to `Column`

* feat(macros): implement `type_override` and `column_override` from `sqlx.toml`

* refactor(sqlx.toml): make all keys kebab-case, create `macros.preferred-crates`

* feat: make macros aware of `macros.preferred-crates`

* feat: make `sqlx-cli` aware of `database-url-var`

* feat: teach macros about `migrate.table-name`, `migrations-dir`

* feat: teach macros about `migrate.ignored-chars`

* feat: teach `sqlx-cli` about `migrate.defaults`

* feat: teach `sqlx-cli` about `migrate.migrations-dir`

* feat: teach `sqlx-cli` about `migrate.table-name`

* feat: introduce `migrate.create-schemas`

* fix(postgres): don't fetch `ColumnOrigin` for transparently-prepared statements

* feat: progress on axum-multi-tenant example

* feat(config): better errors for mislabeled fields

* WIP feat: filling out axum-multi-tenant example

* feat: multi-tenant example

No longer Axum-based because filling out the request routes would have distracted from the purpose of the example.

* chore(ci): test multi-tenant example

* fixup after merge

* fix: CI, README for `multi-tenant`

* fix: clippy warnings

* fix: multi-tenant README

* fix: sequential versioning inference for migrations

* fix: migration versioning with explicit overrides

* fix: only warn on ambiguous crates if the invocation relies on it

* fix: remove unused imports

* fix: `sqlx mig add` behavior and tests

* fix: restore original type-checking order

* fix: deprecation warning in `tests/postgres/macros.rs`

* feat: create postgres/multi-database example

* fix: examples/postgres/multi-database

* fix: cargo fmt

* chore: add tests for config `migrate.defaults`

* fix: sqlx-cli/tests/add.rs

* feat(cli): add `--config` override to all relevant commands

* chore: run `sqlx mig add` test with `RUST_BACKTRACE=1`

* fix: properly canonicalize config path for `sqlx mig add` test

* fix: get `sqlx mig add` test passing

* fix(cli): test `migrate.ignored-chars`, fix bugs

* feat: create `macros.preferred-crates` example

* fix(examples): use workspace `sqlx`

* fix: examples

* fix: run `cargo fmt`

* fix: more example fixes

* fix(ci): preferred-crates setup

* fix: axum-multi-tenant example locked to specific sqlx version

* import anyhow::Context trait in sqlx-cli/src/lib.rs since it was being used and causing a compile error

* rebased on upstream/main

* make cargo fmt happy

* make clippy happy

* make clippy happier still

* fix: improved error reporting, added parsing test, removed sqlx-toml flag use

* switched to kebab-case for the config key

* switched to kebab-case for the config key

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
2025-07-08 01:20:46 -07:00
Bogdan Mircea
ba23fdeb76
Compile-time support for external drivers (#3889)
* Make sqlx-macros-core::database public

* Move driver installation to bins

* Fix lint
2025-07-02 03:48:08 -07:00
Austin Bonander
25cbeedab4
feat: create sqlx.toml format (#3383)
* feat: create `sqlx.toml` format

* feat: add support for ignored_chars config to sqlx_core::migrate

* chore: test ignored_chars with `U+FEFF` (ZWNBSP/BOM)

https://en.wikipedia.org/wiki/Byte_order_mark

* refactor: make `Config` always compiled

simplifies usage while still making parsing optional for less generated code

* refactor: add origin information to `Column`

* feat(macros): implement `type_override` and `column_override` from `sqlx.toml`

* refactor(sqlx.toml): make all keys kebab-case, create `macros.preferred-crates`

* feat: make macros aware of `macros.preferred-crates`

* feat: make `sqlx-cli` aware of `database-url-var`

* feat: teach macros about `migrate.table-name`, `migrations-dir`

* feat: teach macros about `migrate.ignored-chars`

* chore: delete unused source file `sqlx-cli/src/migration.rs`

* feat: teach `sqlx-cli` about `migrate.defaults`

* feat: teach `sqlx-cli` about `migrate.migrations-dir`

* feat: teach `sqlx-cli` about `migrate.table-name`

* feat: introduce `migrate.create-schemas`

* WIP feat: create multi-tenant database example

* fix(postgres): don't fetch `ColumnOrigin` for transparently-prepared statements

* feat: progress on axum-multi-tenant example

* feat(config): better errors for mislabeled fields

* WIP feat: filling out axum-multi-tenant example

* feat: multi-tenant example

No longer Axum-based because filling out the request routes would have distracted from the purpose of the example.

* chore(ci): test multi-tenant example

* fixup after merge

* fix(ci): enable `sqlx-toml` in CLI build for examples

* fix: CI, README for `multi-tenant`

* fix: clippy warnings

* fix: multi-tenant README

* fix: sequential versioning inference for migrations

* fix: migration versioning with explicit overrides

* fix: only warn on ambiguous crates if the invocation relies on it

* fix: remove unused imports

* fix: doctest

* fix: `sqlx mig add` behavior and tests

* fix: restore original type-checking order

* fix: deprecation warning in `tests/postgres/macros.rs`

* feat: create postgres/multi-database example

* fix: examples/postgres/multi-database

* fix: cargo fmt

* chore: add tests for config `migrate.defaults`

* fix: sqlx-cli/tests/add.rs

* feat(cli): add `--config` override to all relevant commands

* chore: run `sqlx mig add` test with `RUST_BACKTRACE=1`

* fix: properly canonicalize config path for `sqlx mig add` test

* fix: get `sqlx mig add` test passing

* fix(cli): test `migrate.ignored-chars`, fix bugs

* feat: create `macros.preferred-crates` example

* fix(examples): use workspace `sqlx`

* fix: examples

* fix(sqlite): unexpected feature flags in `type_checking.rs`

* fix: run `cargo fmt`

* fix: more example fixes

* fix(ci): preferred-crates setup

* fix(examples): enable default-features for workspace `sqlx`

* fix(examples): issues in `preferred-crates`

* chore: adjust error message for missing param type in `query!()`

* doc: mention new `sqlx.toml` configuration

* chore: add `CHANGELOG` entry

Normally I generate these when cutting the release, but I wanted to take time to editorialize this one.

* doc: fix new example titles

* refactor: make `sqlx-toml` feature non-default, improve errors

* refactor: eliminate panics in `Config` read path

* chore: remove unused `axum` dependency from new examples

* fix(config): restore fallback to default config for macros

* chore(config): remove use of `once_cell` (to match `main`)
2025-06-30 16:34:46 -07:00
Paolo Barbolini
df47ffedd2
Replace some more futures_util APIs with std variants (#3874) 2025-06-15 15:18:39 -07:00
Austin Bonander
90797200ee
groundwork for 0.9.0-alpha.1 (#3821)
* chore: bump version to `0.9.0-alpha.1`

* chore: delete unused `sqlx-bench` package

* chore: set `rust-version` to 1.85 for all crates

* fix: lots of new Clippy warnings

* fix: lots more Clippy warnings

* fix(cli): add `_sqlite` feature

* fix: lots, *lots* more Clippy warnings

* fix(core): warning in `tls_rustls`

* breaking: delete runtime+TLS combination features

* chore: don't re-export unstable `TransactionManager` trait

* chore: 0.9.0-alplha.1 CHANGELOG

* chore: increase MSRV further to 1.86

* fix: more clippy warnings
2025-06-01 21:09:55 -07:00
Josh McKinney
6b2e0247d4
Add color and wrapping to cli help text (#3849) 2025-05-02 18:48:46 -07:00
Austin Bonander
e7236881a1
Hotfix 0.8.5 (#3824)
* fix(cli): correctly handle `.env` files again

* feat(ci): add functionality tests for sqlx-cli (MySQL)

* feat(ci): add functionality tests for sqlx-cli (Postgres)

* feat(ci): add functionality tests for sqlx-cli (SQLite)

* chore: prepare 0.8.5 release

* feat(ci): run `test-attr` tests twice to catch #3825

* fix: correct bugs in MySQL implementation of `#[sqlx::test]`
2025-04-15 15:11:07 -07:00
Paolo Barbolini
277dd36c78
refactor(cli): replace promptly with dialoguer (#3669) 2025-02-27 12:17:09 -08:00
tottoto
520d25c453
chore(cli): remove unused async-trait crate from dependencies (#3754) 2025-02-20 11:35:44 -08:00
Ben Wilber
91291beb23
feat(sqlx-cli): Add flag to disable automatic loading of .env files (#3724)
* Add flag to disable automatic loading of .env files

* Update sqlx-cli/src/opt.rs

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2025-02-04 10:52:43 -08:00
Paolo Barbolini
6b337668de
fix(cli): running tests on 32bit platforms (#3666) 2025-01-06 16:00:18 -08:00
依云
5b8bb3b28b
Add a "sqlite-unbundled" feature that dynamically links to system libsqlite3.so library (#3507)
* Add a "sqlite-unbundled" feature that dynamically links to system libsqlite3.so library

* update README abouot the newly-added `sqlite-unbundled` feature

* Update README.md to make it clear with bulleted list

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>

* more cfg feature updates

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>

* update documentation in sqlx-sqlx/src/lib.rs too

and also mention possible build time increasement.

* cargo fmt

* Add "sqlite-unbundled" feature to sqlx-cli

* Add sqlite-unbundled to gituhb actions tests

* cfg(feature = "sqlite") => cfg(any(feature = "sqlite", feature = "sqlite-unbundled"))

* fix

* CI: make sqlite-unbundled tests workaround required-features

by duplicating the relevant test section

* use an internal "_sqlite" feature to do the conditional compilation

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2024-10-02 11:55:21 -07:00
vsuryamurthy
293c55ce89 Remove unused dependencies from sqlx-core, sqlx-cli and sqlx-postgres 2024-09-24 18:46:31 -07:00
Austin Bonander
2ab7565bd8 chore: configure clippy cast lints at workspace level 2024-08-23 23:39:32 -07:00
cycraig
4acecfc636
fix(sqlx-cli): do not clean sqlx during prepare (#2786)
* fix(cli): do not clean sqlx during prepare

* feat(cli): only clean dependencies with new --all flag for prepare
2024-08-01 15:36:42 -07:00
Denis Otkidach
572e2a4ed5
fix(cli): typo in error for required DB URL (#3389) 2024-07-29 17:28:41 -07:00
Frank Elsinga
e089d2fb55
bumped cargo_metadata to v0.18.1 (#3386) 2024-07-27 16:19:26 -07:00
Frank Elsinga
b37b34bd04
chore:added a testcase for sqlx migrate add ... (#3352) 2024-07-19 18:50:18 -07:00
Jos Ahrens
543395d80a
fix: build script new line at eof (#3353)
When generating the build script, it will
fail `cargo fmt -- --check` because it is
missing a new line at the end of the file.
2024-07-19 14:53:45 -07:00
Cristian Le
92de9d42a6 Add LICENSE-* files to crates 2024-06-20 10:56:08 -07:00
Austin Bonander
bae083cf79 fix: clippy warnings 2024-06-13 13:11:36 -07:00
Vraj Shah
02f196b4ac
fix: link to correct version in first-migration message (#2900)
Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2024-02-18 20:20:29 -08:00
Dawson
2cc3e0f90b
Minor fixes (#2955)
* doc link fix
variable declaration moved for better readability

* migration version abstraction
2024-01-16 13:49:25 -08:00
Vraj Shah
fda415927a
Sqlx Cli: Added force flag to drop database for postgres (#2873)
* Updated ahash so it can compile on mac

* Updated MigrateDatabase Trait + related functions

* Postgres force drop database flag impl

* Update migrate.rs

* Reverted MigrateDatabase Trait

* Update migrate.rs

* Update migrate.rs

* Added force drop database fn impl

* Add Migrate Error

* Fixed changed function name
2023-11-21 11:11:08 -08:00
Ferenc Tamás
d3a28d461f
Do not require db url for prepare (#2882)
* feat(cli): do not require db url

* chore: remove unused import

* fix(cli): do not always pass DATABASE_URL

* fix(cli): check db when DATABASE_URL is provided
2023-11-20 20:11:23 -08:00
Rico
220bf93dc2
Fix comment in sqlx migrate add help (#2847)
The old description for the `sequential` flag read "If set, use *timestamp* versioning".
I guess this was a simple copy-paste error.
2023-11-03 17:23:36 -07:00
Matt Fellenz
b16fbebf2f
Don't use separate temp dir for query jsons (2) (#2803)
* Don't use temp dir for query jsons

Fixes #2663

* Return early when exclusive create fails

* Use atomic-file-write for writing query data
2023-10-17 11:41:30 -07:00
Adriano Di Luzio
6bec8574d4
Remove unused remove_dir_all crate (#2757) 2023-09-25 18:01:56 -07:00
Max Vorobev
d0fbe7feff
Automatically infer migration type (#2664) 2023-08-01 11:16:43 -07:00
Yuri Astrakhan
a824e8468c
Cleanup format arguments (#2650)
Inlined format args make code more readable, and code more compact.

I ran this clippy command to fix most cases, and then cleaned up a few trailing commas and uncaught edge cases.

```
cargo clippy --bins --examples  --benches --tests --lib --workspace --fix -- -A clippy::all -W clippy::uninlined_format_args
```
2023-07-31 13:27:04 -07:00
Ameer Ghani
84f21e99ef
cli: add --target-version CLI flags for migrate run/revert (#2538)
* cli: add --target-version CLI flags for migrate run/revert

* cli: fix broken test

* cli: test harness for `sqlx migrate` along with --target-version tests

* cli: Fail if version supplied to run/revert is too old/new

After some discussion with my coworkers, we thought about the behavior a bit more:

The behavior is now that for a run, if the provided version is too old, the CLI
will return with failure rather than being a no-op. This gives feedback to the
operator instead of being quiet.

It is still valid to up/downgrade to the latest version, this will still be a no-op
to allow for idempotency.
2023-07-31 12:49:53 -07:00
Max Vorobev
f2bb464bcd
Support naming migrations sequentially (#2602)
* Support naming migrations sequentially and inferring naming scheme

* Document new options and how naming is inferred

* Only account for up migrations when inferring ordering
2023-07-24 16:00:26 -07:00
Jon Heinritz
8b223e24d3
Update clap to v4.3.10 (#2576) 2023-07-09 13:13:43 -07:00
Austin Bonander
dcb58b0e2c
0.7.0 release (#2575)
* WIP preparing 0.7.0 release

* fix: re-enable examples

* fix doctests in `sqlx-core`

* cherry-pick CHANGELOG entry for 0.6.3

* add actions workflow for examples

* fix(cli): close connection after running migrations

* fix examples

* fix(sqlite): fix parsing of URLs via `Any`

* fix(example): don't let Postgres `listen` example run forever

* fix Postgres `transaction` example
2023-07-03 14:37:37 -07:00
Jon Heinritz
1b7631eddc
Add CLI autocompletion using clap_complete (#2559) 2023-06-30 14:59:35 -07:00
Paolo Barbolini
14d70feab1 Enable runtime-tokio of sqlx when building sqlx-cli 2023-03-24 00:28:16 -07:00
Austin Schey
cf3ce13d27 fix(prepare): store temporary query files inside the workspace 2023-03-14 17:25:24 -07:00
Craig Bester
3f2ec6f91a chore: update documentation to replace sqlx-data.json with .sqlx 2023-03-01 19:17:21 -08:00
Craig Bester
96c8b12485 feat(prepare): move to one-file-per-query for offline mode
Co-authored-by: Jonas Platte <jonas@lumeo.com>
2023-03-01 19:17:21 -08:00
Craig Bester
a942f5316e fix: install default drivers before sqlx-cli create/drop 2023-02-22 15:09:41 -08:00
Craig Bester
006da611e1 fix: uncomment sqlx-cli database, default features 2023-02-22 15:09:41 -08:00
Austin Bonander
eade49cfb0
0.7.0-alpha.1 release 2023-02-21 14:56:54 -08:00
laundmo
c4a2e73a6f Add context to metadata parse error 2023-02-21 13:25:25 -08:00