ON-PREM CHOREO CLOUD BOTH

What it is

In the SaaS setup, agent-manager-service does not create or update its own database tables when it starts. When an environment is new, its database is rebuilt, or the service crash-loops saying a relation does not exist, an SRE runs the service's own image once as a Job with the arguments -migrate -server=false. The Job applies every pending migration and exits. Then the service is restarted.

Like a building manager who has to turn the water on at the valve once after a new flat is fitted. The taps work fine, but nothing flows until someone does it.

Why it exists

The workload starts the service without the -migrate flag, which defaults to false. Schema changes therefore happen as a deliberate step, and only a person decides when.

How it works

  • Get a kubectl context for the environment's control plane cluster (dev through the dev setup, stage and prod through a bastion).
  • Find the namespace and the agent-manager-service deployment.
  • Create the Job am-db-migrate by cloning the deployment's pod template. It has the same image, environment, database secret and labels, but its arguments are -migrate -server=false and a probe that always fails keeps it out of the Services.
  • Wait for it to complete and read its log. A good run ends with 'dbmigrations:migration completed' and a successCount (0 on an up-to-date database). Then delete the Job.
  • Restart the deployment, wait for the rollout and check the log has no 'failed to initialize' or 'does not exist' lines.

Key facts

Job name
am-db-migrate
Arguments
-migrate -server=false
Safe to re-run
Yes: applied migrations are skipped
All or nothing
Pending migrations run in one transaction
History table
migration_history in the service's own database
Typical symptom
relation ... does not exist at startup
Rollback caution
A database migrated by a newer release than the image gives an 'unknown migration' error. Roll forward instead
Namespace
cloud-cp

Talks to (2)

Inside and around

Part of: CR runbooks index