Skip to content

Instantly share code, notes, and snippets.

@ivan
Last active February 22, 2022 23:27
Show Gist options
  • Select an option

  • Save ivan/7532c95c323d985dbbaa786a3a08c80f to your computer and use it in GitHub Desktop.

Select an option

Save ivan/7532c95c323d985dbbaa786a3a08c80f to your computer and use it in GitHub Desktop.
An alternative to `cargo sqlx prepare --merged` that doesn't rebuild all the crates in the workspace
#!/bin/sh
set -eu -o pipefail
export DATABASE_URL=$(pg_tmp)
psql "$DATABASE_URL" -f schema/schema.sql
# We don't use `cargo sqlx prepare --merged` because it rebuilds everything
for i in crates/{a,b,c}; do
(cd "$i" && cargo sqlx prepare -- --lib)
done
# We need to make a merged file at the workspace root for sqlx `offline`
# to work properly with rust-analyzer. Otherwise many red squigglies.
cat crates/*/sqlx-data.json | jq --sort-keys -s add > sqlx-data.json
rm -f crates/*/sqlx-data.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment