From 4fb7102cb2cddc66d2ad39eaac238e86a25d0345 Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Thu, 27 Feb 2025 17:27:57 -0800 Subject: [PATCH] fix: CI, README for `multi-tenant` --- .github/workflows/examples.yml | 8 ++++---- examples/postgres/multi-tenant/README.md | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 6fbb4b31..8d25e96f 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -178,16 +178,16 @@ jobs: - name: Multi-Tenant (Setup) working-directory: examples/postgres/multi-tenant env: - DATABASE_URL: postgres://postgres:password@localhost:5432/mockable-todos + DATABASE_URL: postgres://postgres:password@localhost:5432/multi-tenant run: | (cd accounts && sqlx db setup) (cd payments && sqlx migrate run) sqlx migrate run - - name: Mockable TODOs (Run) + - name: Multi-Tenant (Run) env: - DATABASE_URL: postgres://postgres:password@localhost:5432/mockable-todos - run: cargo run -p sqlx-example-postgres-mockable-todos + DATABASE_URL: postgres://postgres:password@localhost:5432/multi-tenant + run: cargo run -p sqlx-example-postgres-multi-tenant - name: TODOs (Setup) working-directory: examples/postgres/todos diff --git a/examples/postgres/multi-tenant/README.md b/examples/postgres/multi-tenant/README.md index 9f96ff72..8122d852 100644 --- a/examples/postgres/multi-tenant/README.md +++ b/examples/postgres/multi-tenant/README.md @@ -19,7 +19,7 @@ This example uses schema-qualified names everywhere for clarity. It can be tempting to change the `search_path` of the connection (MySQL, Postgres) to eliminate the need for schema prefixes, but this can cause some really confusing issues when names conflict. -This example will generate a `_sqlx_migrations` table in three different schemas, and if `search_path` is set +This example will generate a `_sqlx_migrations` table in three different schemas; if `search_path` is set to `public,accounts,payments` and the migrator for the main application attempts to reference the table unqualified, it would throw an error. @@ -27,11 +27,23 @@ it would throw an error. This example requires running three different sets of migrations. -Ensure `sqlx-cli` is installed with Postgres support. +Ensure `sqlx-cli` is installed with Postgres and `sqlx.toml` support: -Start a Postgres server. +``` +cargo install sqlx-cli --features postgres,sqlx-toml +``` -Create `.env` with `DATABASE_URL` or set it in your shell environment. +Start a Postgres server (shown here using Docker, `run` command also works with `podman`): + +``` +docker run -d -e POSTGRES_PASSWORD=password -p 5432:5432 --name postgres postgres:latest +``` + +Create `.env` with `DATABASE_URL` or set the variable in your shell environment; + +``` +DATABASE_URL=postgres://postgres:password@localhost/example-multi-tenant +``` Run the following commands: