Skip to content

Upgrading a self-hosted instance

When you run PotaLab Base with the Community Docker Compose files, a one-shot service called init-upgrade brings every database to the version shipped in the new image. You no longer run any SQL by hand.

  1. Read the changelog, especially the Breaking section.
  2. Back up: pg_dump the platform and project databases, and keep a copy of .env (it holds BASE_MASTER_KEY).
  3. Set the new BASE_IMAGE_TAG in .env, then:
Terminal window
docker compose pull
docker compose up -d
docker compose logs init-upgrade

init-upgrade runs the new Postgres image against your existing volume and applies, in order: the cluster (roles and permissions), the platform and regional databases, every project database, and finally the template used for new projects. Each SQL file runs in its own transaction and is recorded in base_internal.schema_version, so a file that is already applied is skipped and running it again changes nothing.

Migrations API: plan version 2, lost run lock is 409

Section titled “Migrations API: plan version 2, lost run lock is 409”
  • POST .../database/migrations/plan answers plan_version: 2 with items[] (one result per script) and complete. The top-level fields are unchanged. A script with CREATE INDEX CONCURRENTLY or COMMIT no longer fails the whole request with 400 plan_unavailable: its item is non_transactional, the scripts after it are not_planned, and would_apply is false. A script that fails is reported in its item instead of failing the request.
  • migration_lock_lost is now 409 (was 400).
  • A migration that is a single CREATE / DROP INDEX CONCURRENTLY is now applied instead of refused (see Management API).

The Data Router accepts only these names in db_schemas (API config or the static projects file):

  • public, api and core;
  • app_<slug> (lower-case letters, digits and _, at most 40 characters after app_).

The list holds at most 50 entries, with no spaces and no duplicates. Any other schema name, which earlier versions accepted, now makes the router refuse the project at start with invalid db_schemas ....

To upgrade, rename the schema before the upgrade, then put the new name in db_schemas:

alter schema reports rename to app_reports;

You can also move its objects into public, api or an app_ schema.

The upgrade can print WARNING: foreign_app_role: objects of database <db> depend on app roles of other projects: .... It means objects in that database were granted to an app role of another project ("<other db>.app_x"), usually by hand. Nothing is removed, and the project keeps working. New grants of that kind are refused from now on.

To clean up, connect to that database as a superuser and revoke the listed role there:

  • REVOKE ALL ON ALL TABLES IN SCHEMA <schema> FROM "<other db>.app_x" (do the same for schemas, sequences and functions);
  • DROP POLICY for any policy written for it;
  • ALTER ... OWNER TO for any object it owns.

The security advisor of the project lists the role as foreign_app_role until no dependency is left.

Management API: PATCH merges nested sections key by key

Section titled “Management API: PATCH merges nested sections key by key”

A PATCH that sends a nested section now changes only the keys it names. Earlier versions replaced the whole section, so a key you did not send was reset to its default. This applies to:

  • PATCH /v1/projects/{ref}/config/auth: mfa, passkeys, email_branding, rate_limits;
  • PATCH /v1/projects/{ref}/config/rate-limits: each bucket, for example burst;
  • PATCH /v1/projects/{ref}/config/realtime: limits;
  • PATCH /v1/projects/{ref}/log-drains/{id}: s3;
  • PATCH of an SSO provider (attribute_mapping) and of an OIDC provider (claim_mapping).

What a client has to change:

  • To remove one key, send it as null, for example { "email_branding": { "footer_text": null } }. Leaving the key out keeps its stored value.
  • Lists and maps are still replaced as a whole. Send [] to clear a list, and {} to empty a map: email_templates: {} resets every template, and attribute_mapping.extra is replaced.
  • To clear a whole section, send the section as null where the route allows it, for example limits: null.

A client that always sends the full section, like the dashboard, sees no difference.

Permission checks apply to the result, not to the keys you send. Returning a key to its default with null counts as a change:

  • changing auth rate_limits needs the admin role, null included;
  • lowering MFA (turning it off, or no longer requiring it for every user) now needs the admin role and is audited at high severity;
  • a patch that leaves the config invalid, such as null on a required key like mfa.enabled, is refused with 400.

The whole run holds a Postgres advisory lock (BASE_LOCK_INIT). If two stacks or two runners start at the same moment, the second waits, then finds everything already applied. Nothing is applied twice.

The failing file is rolled back, init-upgrade exits with an error and core-api, data-router, realtime and functions do not start. The stack never runs on a half-upgraded schema. Read docker compose logs init-upgrade, fix the cause, and run docker compose up -d again. If you cannot fix it, restore from your backup and set the old tag back. Upgrades only move forward, there is no automatic downgrade.

Set BASE_AUTO_UPGRADE=false in .env. init-upgrade then logs that it is skipped and exits successfully. You apply the SQL yourself with base-apply-cluster-init, base-apply-init <database> <platform|regional|project> and base-create-template inside the postgres container (see UPGRADE.md in the self-host repository).