Hello,
Consider this usecase:
- Deployed Migration 001 along with Feature F01 as a major version (v2.0.0)
- A month later i added a small enhancement F02 that required Migration 002, the upgrade was decided to be a minor version update by forge (v2.1.0)
- When I release the forge application to my atlassian site, the migration was not run.
I searched the atlassian documentation and asked the Forge AI Help assistant, but its answers (scheduled hourly trigger, lazy migrations, and adding a web trigger) did not convince me as the way to go.
My goal is for forge to execute my migrations queue everytime I deploy my application, regardless of version.
What is the recommended way to achieve my goal?
Thank you,
Ray
Hi @RayHaddad,
No run-on-deploy hook exists. A minor like 2.1.0 is rolled onto every install automatically, and avi:forge:upgraded:app only fires for majors, so the hourly trigger is still the one I’d take, pushing to a queue whose consumer calls migrationRunner.run().
Nothing calls it for you. Forge SQL is one database per installation and run() applies whatever names are missing from __migrations only when your code invokes it.
modules:
scheduledTrigger:
- key: migrate-hourly
function: enqueueMigration
interval: hour
trigger:
- key: migrate-on-install
function: enqueueMigration
events:
- avi:forge:installed:app
consumer:
- key: migration-consumer
queue: schema-migration-queue
function: runMigration
function:
- key: enqueueMigration
handler: index.enqueueMigration
- key: runMigration
handler: index.runMigration
timeoutSeconds: 900
import { Queue } from '@forge/events';
import { migrationRunner } from '@forge/sql';
const queue = new Queue({ key: 'schema-migration-queue' });
export const enqueueMigration = async () => queue.push({ body: {} });
export const runMigration = async () =>
migrationRunner
.enqueue('v001_create_items', 'CREATE TABLE IF NOT EXISTS items (id VARCHAR(36) PRIMARY KEY)')
.enqueue('v002_add_status', 'ALTER TABLE items ADD COLUMN IF NOT EXISTS status VARCHAR(20)')
.run();
Each install then picks up the new migration within the hour after the deploy. Until then the F02 code runs against the old schema, so keep that path tolerant of the missing column. The schema docs note the same minor gap and wrap run() in a 60s retry.
Tested on a scratch app. 2.1.0 went out silently, 3.0.0 fired the event. The runner itself under a trigger after a minor deploy is still untested.