Upgrading
The framework is a package, so an update is a version:
bun update @swirls/spoolsbun run crm:genbun run db:push # a database you push to; for one you migrate, see belowbun run check
Read the changelog first. Breaking changes are listed with what to do
about them. Your own files (crm.config.json, src/, swirls/) never change under you.
When an update changes the tables#
The changelog says when a version changes the tables, and what changes. What you run then depends on how each of your databases is kept up:
| The database | What to run after bun run crm:gen |
|---|---|
A Postgres you push to (db:push) |
bun run db:push |
A Postgres you migrate (db:plan, db:migrate) |
bun run db:plan -- --name <update>, commit the migration, then bun run db:migrate |
PGlite (.data/pglite) |
Nothing. The server brings it up to date when it starts |
If you push to a local database and migrate production, plan the migration before you push.
db:plan starts from the db ref (migrations/app/refs/db.json), and db:push moves that
ref on to the new tables, which leaves the plan nothing to start from. db:plan then stops
with MIGRATION.HASH_NOT_IN_GRAPH. It stops with MIGRATION.PLAN_ORIGIN_UNKNOWN when there
is no ref at all, because you have only ever migrated. Either way, say where to start:
bun run db:plan -- --name <update> --from <the last migration's folder name>
Read the plan before you apply it: it lists each operation and the SQL. A plan that would
delete or rename a column is refused until you say so (Deployment), and the
changelog says when an update needs that. Running db:push or db:migrate a second time
changes nothing.
PGlite adds what is missing and drops an index a table no longer declares (Database). It never drops a table or a column, so there is nothing to back up first and nothing to delete.
Versioning#
- The framework follows semantic versioning. Before 1.0, minor versions can include breaking changes.
"version"incrm.config.jsonis the config format version. It changes only when the format breaks, andbun run crm:gentells you if your config is on an older one.- New pages and endpoints are new route files. The changelog gives them to you to copy; until you do, the feature is off.
Layouts (0.9)#
Nothing changes until crm.config.json has a ui key. To use layouts:
For pages of your own (
ui.pages), add the route filesrc/routes/_crm/pages.$page.tsx:tsximport { createFileRoute } from '@tanstack/react-router'import { customPage } from '@swirls/spools/pages/custom'export const Route = createFileRoute('/_crm/pages/$page')(customPage)bun run crm:gensays when it is missing. A record page's layout (ui.records) needs no new file.An object with the key
pagescan't share a Spool withui.pages: its list would be at their address.
No table changes.
Modules, record rules, role access and your own door (0.7)#
A Spool with no modules and none of the new config keys works as before, apart from what
changes without any new key. Everything else is off until
the config or src/spool.server.ts says otherwise.
The database#
| Table or column | When | Holds |
|---|---|---|
change_signals |
Always | A "last changed" mark for each object and record (Database) |
idempotent_requests |
Always | Writes sent with an Idempotency-Key (Extending) |
activities.field |
Always | For a change line, the key of the field it changed. Empty on lines written before |
rate_limit_slots |
Only with rateLimits: storeRateLimits() |
Rate limits counted in the database (Adapters) |
<module>_<table> |
Only with a module that keeps tables of its own | A module's private tables (Modules) |
| A unique index | Only for each unique rule in the config |
The rule, partial when it has where (Database) |
Nothing is renamed or dropped, so no plan needs to be told it may delete anything.
bun update @swirls/spoolsbun run crm:genbun run db:push # a database you push tobun run db:plan -- --name modules-and-rules # or one you migrate:bun run db:migrate # commit the migration, then apply itbun run check
PGlite adds the tables and the column as the server starts.
What changes without any new key#
modulesincrm.config.jsonis now the modules' settings. Before, a key the config's schema didn't know was ignored. Now settings undermodules.<name>for a module thatsrc/spool.server.tsdoesn't list are refused when the server starts and bybun run crm:gen, and so are settings for a module that takes none. If your config has amoduleskey of its own, rename it.- The tool API wraps every timeline line. The summary, body and author of each line that
gethands a workflow or the assistant are now{ "untrusted": true, "text": "..." }, not a string, whoever wrote the line. A workflow of yours that reads a record's timeline reads.text. Copy the two lines about wrapped values from the starter'sswirls/assistant.swirlsinto your assistant's instructions, thenswirls deploy. See Swirls. - New scripts. A new Spool has
"db:rules": "spools rules"inpackage.json. Add it, or runbunx spools rules. - Fixes. The Prisma adapter names each column of an included record once. Times on a record's page are drawn the same on the server and in the browser. A search still loading no longer replaces a filter chosen after it.
Modules#
Listing a module is three edits (Use a module): modules in
src/spool.server.ts, its settings in crm.config.json, and its browser half. A Spool made
before this version has no place for the browser half yet. Add it once:
// src/spool.ui.tsimport { defineSpoolUi } from '@swirls/spools/ui/slots'export const ui = defineSpoolUi({ modules: [] })
// src/routes/__root.tsximport { SpoolUiProvider } from '@swirls/spools/ui/slots'import { authClients, ui } from '../spool.ui';<AuthClientProvider clients={authClients} id={brand?.auth}> <SpoolUiProvider ui={ui}> <html lang="en">...</html> </SpoolUiProvider></AuthClientProvider>
Without the provider nothing breaks: the slots are empty, so a module's panels and sidebar
links are not shown, while its objects, hooks and tables still work. Then run
bunx spools modules, which lists the route files your modules expect and exits 1 until each
is there.
Record rules#
- Uniqueness rules (
uniqueon an object) are unique indexes. Runbun run db:rules(spools rules) after adding one and beforedb:pushordb:plan: Postgres refuses to make the index over records that already break the rule. See Database. - A clash is a
Conflict, with the rule's name and your message, on every store. Code that relied on a constraint of your own (a migration adding a unique or exclusion constraint, and code that read the database's refusal) can move touniquein the config. Drop your own constraint in the same migration, or keep it: PGlite and Prisma leave a constraint they didn't make alone. - Hooks that guarded fields (refusing a change to a field once written, keeping a field to
the server, writing a correction trail) can become
immutable,lock,readonlyandaudit(Record rules). Areadonlyfield is refused from a person's write before yourbeforehook runs. Your hook, and code writing withactor: null, may still set it. Anaudit.notefield must itself bereadonly. - A locked record is deleted only by the server's own work. A person, the assistant and
code with nobody said are refused the delete of a record its
lockholds, of a record its parent locks (parentLock), and of a parent that locks others. Code that must remove one (an erasure request, a submission made by mistake) does it insideasSystem, behind a check of your own for who may ask. See Security. beforeDeleteis a new hook: throw in it to refuse a delete.
Role access#
access on a role, access.default and assistant.deny narrow what people and the
assistant reach (Roles). Without any of them nobody's reach changes, and
roles still decide only what Home and the sidebar show. Once the config has one:
Your own code runs with the role access of the teammate it runs for. A hook, a handler, a run target, a
crmHandleror anapiRoutereads and writes through@swirls/spools/extensionsas that person: an object their roles deny is not found, and a change to one they only read is refused. A hook that writes an object the person who caused it is kept from (an office-only ledger line when a designer closes a job) now fails until that write is insideasSystem(Hooks and role access):tsimport { asSystem, createRecord } from '@swirls/spools/extensions'await asSystem(() => createRecord('ledger', { jobId: record.id, amount }, actor))A read-only object changes nothing of what hangs off its records. Someone who only reads jobs adds no note, task or logged call to one, completes no task on one, sends it no email, starts no action or sequence for it, and adds, renames, moves or deletes no file in its folder or a folder inside it. A role with
"readOnly": truechanges nothing in the file library, shared views, Marketing or shared connections either. Your own code'saddActivity,createTaskandcreateNotekeep to the same for the teammate it runs for: wrap the server's own bookkeeping inasSystem. A file is opened or changed through the folder it is in (the file browser's links carry it) for anyone role access keeps something from; a link of your own to/api/files/<id>adds?folder=<the folder's id>.asSystemlifts role access as well as record scopes. Code already inside it reaches every object. Keep its uses few, and never hand what it read to someone it is kept from.Code with nobody behind it holds no role. A cron route, a script, a
publicRouteand the config's automations are not narrowed, andaccess.defaultdoes not apply to them.Timeline lines stop naming records of a denied object. A change to a relation that leads to an object any role,
access.defaultorassistant.denykeeps from someone is written "updated Client", for everyone who reads the record. Lines written before are not changed until you runbunx spools timeline redact, once, after adding the firstdeny. It can't fix a line written under a label the field no longer has, nor a title in a note, an email or a line your own code wrote (Roles).The assistant is not narrowed by roles. Name the objects it must never reach in
assistant.deny.
Live updates#
Off until "live": { "seconds": 20 } is in the config
(Live updates). Pages call one new server function
(changedSinceFn), which needs no route file.
Your own door#
Endpoints for people who are not teammates are built from helpers in
@swirls/spools/extensions, behind publicRoute
(Building your own door). Three things to set where
it runs (Deployment): TRUST_PROXY, your front end's origins
for verifyToken, and CLERK_JWT_KEY with clerk(). apiRoute(name, answer, { idempotency: {} }) gives a teammate's endpoint the same once-only writes.
If you built on this version before it was released, four things changed on the way:
callerAddress(headers)answersnullwhen the address can't be known (TRUST_PROXYunset or mistyped). There is no shared stand-in value. Skip the address limit fornull, or refuse: never count a limit under it.idempotenttakes only a caller made withverifiedCaller(namespace, ...verifiedIds).- A rate limiter of your own implements
consumeandwaitbesidehitandrecord. - A person who could delete a record under its own
lockno longer can (above).
Record scopes#
A Spool without scopes in crm.config.json needs the schema change and nothing more
(bun run crm:gen, bun run db:push): seven system tables gain a scope column that stays
empty. Before you add scopes, and each time you change it:
- Run
bun run db:scopesafter every change toscopes.objects, not only the first time. It gives the rows that hang off records (timeline, tasks, notes, favourites, folders, uploads, sequence runs) their record's scope, where they have none or carry one from before the change. Until it has run, rows on a newly scoped object's records are only there for a role withall, and their sequence runs are held. A server that stays up says at start-up when rows are waiting. See Security. - Code with nobody signed in changes no record until it says it is the system. With
scopes on, a script, a webhook or an endpoint of your own that creates or changes records
with nobody behind it is refused, for a shared object's records too. Wrap the work in
asSystemfrom@swirls/spools/extensions. - A workflow's write-back binds your hooks to its record. With scopes on, a hook or an
automation's handler set off by a tool call made under a grant reaches, through
@swirls/spools/extensions, the one record the grant was made for. One that lists or creates other records there needsasSystem. See Extending. - Remove links that cross scopes. A
relationsfield between two scoped objects may hold links made before scopes were on that join records of two scopes. They are left as they are and shown only to someone who holds both, and such a record can't move scope or be deleted by someone who holds one. Unlink them as head office. - Send the grant back. Workflows that write through the tool API send the
grantfrom their input as theX-Spools-Grantheader. See Swirls. - Name the scopes there are. A scope a person holds counts only when it is one of this
Spool's: an option of the scope field where that is a select, and otherwise one the
resolver lists. With Clerk organizations, name the ones that are scopes with
clerk({ scopes: 'organizations', scopesFrom: ['org_...'] }); without it no organization is a scope. A resolver of your own needslistwhere a scope field is text or a relation. The server says at start-up when nothing is listed. See Signing in. - Someone who can change no record changes nothing else. With scopes on, a read-only person and someone who holds no scope read Marketing and Integrations and are refused every change there: posts, the website's check and profile, ad results, and the accounts the team shares. If the people who run your marketing hold no scope, give them one with a role that writes.
- Change a scope field with the server stopped. If you move an object's scope to another
field, run
bun run db:scopesbefore anyone signs in again: until it has run, rows on a record are still read by the scope the old field gave them.
For code of yours that imported the server's modules: what sendEmailFn does is now
sendRecordEmail in @swirls/spools/server/workspace, and a store method can fail with
ScopeRefused beside DatabaseError.
From a copy of the repository#
Before Spools was a package, a CRM was a copy of the whole repository that merged updates from it. Moving
one over changes no data: the tables are the same, column for column, and crm.config.json
and every environment variable keep their names.
Make a Spool in a folder of its own with
bun create @swirls/spools, and copy what is yours over it:crm.config.json,src/app,src/styles.css,swirls,migrations,.env,vercel.jsonif you changed it, and any pages you added tosrc/routes. Keep your repository's history by doing this on a branch of it.Say what it runs on in
src/spool.server.ts. These are the services a copy used, so nothing behaves differently:tsexport default defineSpool({ crm, extensions, auth: clerk(), database: prisma({ contract }), files: flashdrive(), email: resend(), vault: cipherstash(), agents: swirls(),})Change your imports. In
src/app/extensions.ts,'../crm/extensions'and'../server/extension-api'are both'@swirls/spools/extensions'.Change your own server code that used the database: it asks for
Storeinstead ofDatabase(Database).AuthErrorreplacesClerkErrorandAgentsErrorreplacesSwirlsError.Find a home for changes you made to the framework. Most fit an extension point: hooks, handlers, pages, or an adapter. Open an issue for one that doesn't.
Run
bun run crm:genandbun run check.crm:genshould leaveprisma/schema.jsonexactly as it was, which is how you know the database needs no change.
The Resend webhook keeps its address: /api/webhooks/resend is now the same as
/api/webhooks/email. The stubbed-sign-in harness reads DEV_AUTH_EMAIL and
DEV_AUTH_SIGNED_OUT where it read E2E_EMAIL and E2E_SIGNED_OUT.
On a host with no long-lived process other than Vercel, set SERVERLESS=1. Vercel is still
worked out from the host. Its build is now vercel() from @swirls/spools/vite in
vite.config.ts, where a copy carried its own Nitro plugin.