Per-tenant schema migration fan-out.
The platform migrate runs the migration set against the public schema. Each
tenant lives in its own tenant_<slug> schema, so the same migrations must
also run inside every tenant schema — otherwise a schema change lands in
public but not in existing tenants, and queries executed under the tenant
search_path fail with missing relation/column errors (the drift this fixes).
Each tenant run pins the JDBC connection's search_path to the tenant schema
via the PostgreSQL currentSchema connection property, so migratus creates
its own schema_migrations ledger inside that schema and applies DDL there.
Because migrations run once per tenant schema, tenant-run migrations must be idempotent / tenant-scoped.
Per-tenant schema migration fan-out. The platform `migrate` runs the migration set against the public schema. Each tenant lives in its own `tenant_<slug>` schema, so the same migrations must also run inside every tenant schema — otherwise a schema change lands in public but not in existing tenants, and queries executed under the tenant search_path fail with missing relation/column errors (the drift this fixes). Each tenant run pins the JDBC connection's search_path to the tenant schema via the PostgreSQL `currentSchema` connection property, so migratus creates its own `schema_migrations` ledger inside that schema and applies DDL there. Because migrations run once per tenant schema, tenant-run migrations must be idempotent / tenant-scoped.
Classpath-relative directory holding tenant-scoped migrations — the set that
runs inside every tenant schema (must only touch tenant-scoped tables). Kept
separate from the public migrations/ set, which runs once against public.
Classpath-relative directory holding tenant-scoped migrations — the set that runs inside every tenant schema (must only touch tenant-scoped tables). Kept separate from the public `migrations/` set, which runs once against public.
(migrate-all-tenants! schemas)(migrate-all-tenants! db-cfg schemas)(migrate-all-tenants! db-cfg schemas migration-dir)Fan out pending tenant-scoped migrations across the given tenant schemas.
Continues past a failing schema so one bad tenant does not block the rest;
returns {:schemas-migrated [...] :errors {schema-name message}}. Callers get
the schema list from provisioning/list-tenant-schemas (kept out of this ns
to avoid a dependency cycle with provisioning).
Fan out pending tenant-scoped migrations across the given tenant schemas.
Continues past a failing schema so one bad tenant does not block the rest;
returns {:schemas-migrated [...] :errors {schema-name message}}. Callers get
the schema list from `provisioning/list-tenant-schemas` (kept out of this ns
to avoid a dependency cycle with provisioning).(migrate-tenant! db-cfg schema-name)(migrate-tenant! db-cfg schema-name migration-dir)Run all pending tenant-scoped migrations inside one tenant schema.
db-cfg is a database config map (as from get-active-db-config) carrying
:host/:port/:name/:username/:password. migration-dir is a classpath-relative
tenant migration directory. Throws on a malformed schema name.
Run all pending tenant-scoped migrations inside one tenant schema. `db-cfg` is a database config map (as from `get-active-db-config`) carrying :host/:port/:name/:username/:password. `migration-dir` is a classpath-relative tenant migration directory. Throws on a malformed schema name.
(tenant-migratus-config db-cfg schema-name migration-dir)Migratus config that applies migrations inside a single tenant schema.
Pins currentSchema to the tenant schema ONLY (no ,public fallback). This
is deliberate: with a <schema>,public search_path migratus's
CREATE TABLE IF NOT EXISTS schema_migrations resolves to the existing
public.schema_migrations, so every tenant would share the public ledger and
the second tenant would skip migrations it never actually ran. Tenant-only
search_path gives each schema its own ledger and full isolation.
The consequence: migrations run here must be tenant-scoped — they may only
reference tables that exist in the tenant schema. Point :migration-dir at a
tenant-scoped migration set, not the full public migration set.
Migratus config that applies migrations inside a single tenant schema. Pins `currentSchema` to the tenant schema ONLY (no `,public` fallback). This is deliberate: with a `<schema>,public` search_path migratus's `CREATE TABLE IF NOT EXISTS schema_migrations` resolves to the existing `public.schema_migrations`, so every tenant would share the public ledger and the second tenant would skip migrations it never actually ran. Tenant-only search_path gives each schema its own ledger and full isolation. The consequence: migrations run here must be tenant-scoped — they may only reference tables that exist in the tenant schema. Point `:migration-dir` at a tenant-scoped migration set, not the full public migration set.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |