Skip to content
Documentation
On this page

Historical app framework migrations

Historical app framework migrations from the built-in skills in Executor 2.0.0-beta.79.

These historical migrations shipped with Executor 2.0.0-beta.79, which uses apps 0.0.1-beta.148. Use the version named by your host for current apps. Check the framework version on your host before upgrading.

Upgrade to apps@0.0.1-beta.38

October 6, 2026. For apps on 0.0.1-beta.37 or earlier upgrading to 0.0.1-beta.38, which replaced the document database with SQL.

This release replaces the document database (defineDatabase, table, ctx.db) with SQL through ctx.sql. Apps without a database only bump the version. Versions you already deployed keep running unchanged until you deploy again.

1. Bump the version

Set "apps": "0.0.1-beta.38" in package.json.

2. Remove the database declaration

// Before
const requirements = {
  accounts: { github },
  database: defineDatabase({
    notes: table({ text: string(), pinned: boolean() }).index("by_pinned", ["pinned"]),
  }),
};

// After
const requirements = { accounts: { github } };

Remove the defineDatabase, table, id and userId imports. The app has a database because it has migrations; there is nothing to declare.

3. Create the tables, and copy the old rows

Write migrations/0001_init.sql. The document API stored every row as JSON in _executor_legacy_rows (table_name, id, body), with createdAt and updatedAt inside the body. Copy them into the new tables in the same migration:

CREATE TABLE notes (
  id TEXT PRIMARY KEY NOT NULL,
  text TEXT NOT NULL,
  pinned INTEGER NOT NULL DEFAULT 0,
  created_at INTEGER NOT NULL
);
CREATE INDEX notes_pinned ON notes (pinned, created_at);
INSERT INTO notes (id, text, pinned, created_at)
SELECT
  id,
  json_extract(body, '$.text'),
  coalesce(json_extract(body, '$.pinned'), 0),
  json_extract(body, '$.createdAt')
FROM _executor_legacy_rows
WHERE table_name = 'notes';

_executor_legacy_rows exists in every app database and is empty when the app never stored rows, so the same migration works for a fresh deploy or a copy of the app. Booleans are stored as JSON true/false; json_extract returns them as 1/0. Check createdAt’s format in a few rows before relying on it, for example with a query running SELECT body FROM _executor_legacy_rows LIMIT 5.

The old tables stay in the database untouched. Nothing is deleted.

4. Rewrite handlers

ctx.sql is synchronous, so drop the awaits.

// insert(value)
ctx.sql
  .exec(
    "INSERT INTO notes (id, text, created_at) VALUES (?, ?, ?) RETURNING *",
    crypto.randomUUID(),
    text,
    Date.now(),
  )
  .one();
// get(id)
ctx.sql.exec("SELECT * FROM notes WHERE id = ?", id).toArray()[0] ?? null;
// update(id, patch)
ctx.sql.exec("UPDATE notes SET pinned = 1 WHERE id = ?", id);
// delete(id)
ctx.sql.exec("DELETE FROM notes WHERE id = ? RETURNING id", id).toArray().length > 0;
// withIndex("by_pinned", (q) => q.eq("pinned", true)).take(20)
ctx.sql.exec("SELECT * FROM notes WHERE pinned = 1 ORDER BY created_at LIMIT 20").toArray();
// count()
ctx.sql.exec("SELECT count(*) AS n FROM notes").one().n;
// paginate({ cursor, numItems }): pass the last row's created_at as the next cursor
ctx.sql
  .exec("SELECT * FROM notes WHERE created_at < ? ORDER BY created_at DESC LIMIT ?", cursor, size)
  .toArray();

Rows come back with your column names, so rename createdAt to created_at in callers or alias it (created_at AS createdAt). Nothing adds id, createdAt or updatedAt for you; write them yourself.

The document API’s per-call row budgets are gone, so DatabaseLimitExceeded no longer occurs. Keep batching large work, since a long statement holds the database for every other call.

5. Revisit mutations that call other services

A mutation used to be one transaction, so a failed fetch after an insert rolled the insert back. Now each statement commits on its own, and ctx.sql.transaction(() => ...) groups statements but cannot contain an await. Where a mutation writes, calls a service, then writes again, use the reserve, call, publish pattern in storage.md, and handle the row a failure leaves behind. Writes that two calls can race on should be conditional (UPDATE ... WHERE status = 'pending') and check rowsWritten.

6. Workflow step mutations

A mutation run with step.runMutation writes only inside one ctx.sql.transaction(...). That transaction also records the step’s receipt, so a retried step never writes twice. A write outside it fails, and so does a second transaction in the same step.

const save = mutation({ input }, async (ctx, input) =>
  ctx.sql.transaction((tx) =>
    tx
      .exec(
        "INSERT INTO reports (id, repository) VALUES (?, ?) RETURNING id",
        crypto.randomUUID(),
        input.repository,
      )
      .one(),
  ),
);

7. Deploy

Deploy as usual. The host applies migrations/ before activating the new version. If a migration fails, the deploy fails with the migration’s name and the previous version keeps running.

Upgrade to apps@0.0.1-beta.90

October 13, 2026. For apps on 0.0.1-beta.89 or earlier upgrading to 0.0.1-beta.90, which introduced scoped accounts.

This release declares account requirements by scope. user requirements are each caller’s own linked accounts, as every requirement was before. app requirements are new: accounts linked for everyone by people who can edit the app, which every caller and the app’s background work use. { accounts } requirements, ctx.accounts, cron and interval are removed, and source that uses them fails to build. Versions you already deployed keep running unchanged until you deploy again. Existing links stay user links, and members’ schedule copies stay theirs while their declarations stay user schedules.

1. Bump the version

Set "apps": "0.0.1-beta.90" in package.json.

2. Move requirements to user

// Before
const requirements = { accounts: { github } };
// After
const requirements = { user: { accounts: { github } } };

An app without accounts declares nothing: { accounts: {} } becomes {}.

3. Read the caller’s accounts from ctx.user

// Before
ctx.accounts.github.fields.token;
async ({ accounts, fetch }) => accounts.github.id;
// After
ctx.user.accounts.github.fields.token;
async ({ user, fetch }) => user.accounts.github.id;

Workflow steps change the same way: step.accounts becomes step.user.accounts. A factory, defineApp(requirements, async (ctx) => ...), also runs without a caller for app-scope work, so ctx.user may be undefined there: write ctx.user?.accounts.service ?? [] for a .many() requirement, or return no tools without a caller.

4. Name the scope of a webhook’s account

// Before
account: "github",
// After
account: { user: "github" },

5. Choose each schedule’s scope

cron and interval become userCron and userInterval when the app has user requirements: each member enables their own copy, which runs as them, as before.

An app without user requirements uses appCron and appInterval: one schedule, which an app manager enables and which runs without a caller. Its mutation declares no approval, and its handler either declares no parameters or takes MutationContext<typeof requirements, "app">. A context declared without a type is the caller’s, so async (ctx) => … needs that type; the codemod adds it. So does mutation<Input, Output>(…) with explicit type arguments, even without parameters; the codemod adds it as the third type argument. Keep userCron or userInterval for a mutation that asks for approval, or to keep one copy per member.

Nothing stored is converted. The version already running keeps its members’ schedule copies. Deploying a declaration as an app schedule deletes those copies, with their settings, run history and pending approvals, and the app schedule starts paused until an app manager enables it. The codemod warns at each schedule it makes an app schedule.

const tick = mutation(
  { input: object({}) },
  async (ctx: MutationContext<typeof requirements, "app">) => ctx.sql.exec("...").toArray(),
);
export default defineApp(requirements, {
  tools: router({ tick }),
  schedules: { tick: appInterval({ minutes: 5 }, tick, {}) },
});

6. Optionally, give the app its own accounts

A requirement every caller should share, such as a team’s service key, can move to app: { accounts: { ... } } and be read as ctx.app.accounts. Its members’ existing links do not carry over: someone who can edit the app links an account for everyone on the app’s Accounts tab after you deploy. See accounts.md.

7. Deploy

Deploy as usual and check the build output for the removed names.

Was this page helpful?