Skip to content

Commit 25cbeed

Browse files
authored
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`)
1 parent 764ae2f commit 25cbeed

File tree

127 files changed

+6425
-1120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+6425
-1120
lines changed

.github/workflows/examples.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
--bin sqlx
2828
--release
2929
--no-default-features
30-
--features mysql,postgres,sqlite
30+
--features mysql,postgres,sqlite,sqlx-toml
3131
3232
- uses: actions/upload-artifact@v4
3333
with:
@@ -175,6 +175,49 @@ jobs:
175175
DATABASE_URL: postgres://postgres:password@localhost:5432/mockable-todos
176176
run: cargo run -p sqlx-example-postgres-mockable-todos
177177

178+
- name: Multi-Database (Setup)
179+
working-directory: examples/postgres/multi-database
180+
env:
181+
DATABASE_URL: postgres://postgres:password@localhost:5432/multi-database
182+
ACCOUNTS_DATABASE_URL: postgres://postgres:password@localhost:5432/multi-database-accounts
183+
PAYMENTS_DATABASE_URL: postgres://postgres:password@localhost:5432/multi-database-payments
184+
run: |
185+
(cd accounts && sqlx db setup)
186+
(cd payments && sqlx db setup)
187+
sqlx db setup
188+
189+
- name: Multi-Database (Run)
190+
env:
191+
DATABASE_URL: postgres://postgres:password@localhost:5432/multi-database
192+
ACCOUNTS_DATABASE_URL: postgres://postgres:password@localhost:5432/multi-database-accounts
193+
PAYMENTS_DATABASE_URL: postgres://postgres:password@localhost:5432/multi-database-payments
194+
run: cargo run -p sqlx-example-postgres-multi-database
195+
196+
- name: Multi-Tenant (Setup)
197+
working-directory: examples/postgres/multi-tenant
198+
env:
199+
DATABASE_URL: postgres://postgres:password@localhost:5432/multi-tenant
200+
run: |
201+
(cd accounts && sqlx db setup)
202+
(cd payments && sqlx migrate run)
203+
sqlx migrate run
204+
205+
- name: Multi-Tenant (Run)
206+
env:
207+
DATABASE_URL: postgres://postgres:password@localhost:5432/multi-tenant
208+
run: cargo run -p sqlx-example-postgres-multi-tenant
209+
210+
- name: Preferred-Crates (Setup)
211+
working-directory: examples/postgres/preferred-crates
212+
env:
213+
DATABASE_URL: postgres://postgres:password@localhost:5432/preferred-crates
214+
run: sqlx db setup
215+
216+
- name: Multi-Tenant (Run)
217+
env:
218+
DATABASE_URL: postgres://postgres:password@localhost:5432/preferred-crates
219+
run: cargo run -p sqlx-example-postgres-preferred-crates
220+
178221
- name: TODOs (Setup)
179222
working-directory: examples/postgres/todos
180223
env:

CHANGELOG.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,42 @@ This section will be replaced in subsequent alpha releases. See the Git history
1313

1414
### Breaking
1515

16-
* [[#3821]] Groundwork for 0.9.0-alpha.1
17-
* Increased MSRV to 1.86 and set rust-version [@abonander]
16+
* [[#3821]]: Groundwork for 0.9.0-alpha.1 [[@abonander]]
17+
* Increased MSRV to 1.86 and set rust-version
1818
* Deleted deprecated combination runtime+TLS features (e.g. `runtime-tokio-native-tls`)
1919
* Deleted re-export of unstable `TransactionManager` trait in `sqlx`.
2020
* Not technically a breaking change because it's `#[doc(hidden)]`,
2121
but [it _will_ break SeaORM][seaorm-2600] if not proactively fixed.
22+
* [[#3383]]: feat: create `sqlx.toml` format [[@abonander]]
23+
* SQLx and `sqlx-cli` now support per-crate configuration files (`sqlx.toml`)
24+
* New functionality includes, but is not limited to:
25+
* Rename `DATABASE_URL` for a crate (for multi-database workspaces)
26+
* Set global type overrides for the macros (supporting custom types)
27+
* Rename or relocate the `_sqlx_migrations` table (for multiple crates using the same database)
28+
* Set characters to ignore when hashing migrations (e.g. ignore whitespace)
29+
* More to be implemented in future releases.
30+
* Enable feature `sqlx-toml` to use.
31+
* `sqlx-cli` has it enabled by default, but `sqlx` does **not**.
32+
* Default features of library crates can be hard to completely turn off because of [feature unification],
33+
so it's better to keep the default feature set as limited as possible.
34+
[This is something we learned the hard way.][preferred-crates]
35+
* Guide: see `sqlx::_config` module in documentation.
36+
* Reference: [[Link](sqlx-core/src/config/reference.toml)]
37+
* Examples (written for Postgres but can be adapted to other databases; PRs welcome!):
38+
* Multiple databases using `DATABASE_URL` renaming and global type overrides: [[Link](examples/postgres/multi-database)]
39+
* Multi-tenant database using `_sqlx_migrations` renaming and multiple schemas: [[Link](examples/postgres/multi-tenant)]
40+
* Force use of `chrono` when `time` is enabled (e.g. when using `tower-sessions-sqlx-store`): [[Link][preferred-crates]]
41+
* Forcing `bigdecimal` when `rust_decimal` is enabled is also shown, but problems with `chrono`/`time` are more common.
42+
* **Breaking changes**:
43+
* Significant changes to the `Migrate` trait
44+
* `sqlx::migrate::resolve_blocking()` is now `#[doc(hidden)]` and thus SemVer-exempt.
2245

2346
[seaorm-2600]: https://github.com/SeaQL/sea-orm/issues/2600
47+
[feature unification]: https://doc.rust-lang.org/cargo/reference/features.html#feature-unification
48+
[preferred-crates]: examples/postgres/preferred-crates
2449

25-
[#3821]: https://github.com/launchbadge/sqlx/pull/3830
50+
[#3821]: https://github.com/launchbadge/sqlx/pull/3821
51+
[#3383]: https://github.com/launchbadge/sqlx/pull/3383
2652

2753
## 0.8.6 - 2025-05-19
2854

0 commit comments

Comments
 (0)