You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Drop the retired core and plugin data migration capsules after the bridge-release cutover. Keep mixed journal support for future entries while preserving the current core SQL ledger and upgrade guard.
description: "Apply Junior schema and data migrations."
3
+
description: "Apply Junior and plugin schema or data migrations."
4
4
type: reference
5
-
summary: Move configured SQL schemas and persisted state forward after upgrades.
5
+
summary: Bring the configured Junior SQL database up to the installed schema.
6
6
prerequisites:
7
7
- /start-here/quickstart/
8
8
related:
@@ -11,100 +11,65 @@ related:
11
11
- /cli/snapshot-create/
12
12
---
13
13
14
-
Use `junior upgrade` after installing a Junior release that includes schema or
15
-
data migrations. The command mutates the configured SQL database and state
16
-
stores, so run it from the same app environment that has the production state
17
-
and SQL environment variables configured for the deployment you are upgrading.
14
+
Use `junior upgrade` after installing a new Junior release. The command applies
15
+
pending SQL schema and TypeScript data entries from the ordered Drizzle journals
16
+
owned by Junior and its enabled plugins.
18
17
19
18
## Usage
20
19
21
-
Run it from a project that already has `@sentry/junior` installed:
20
+
Run the command from your Junior app:
22
21
23
22
```bash
24
23
pnpm exec junior upgrade
25
24
```
26
25
27
-
The command takes no extra arguments.
26
+
The command takes no arguments. It migrates Junior first, then enabled plugins.
27
+
Already-applied entries are recognized as up to date and are not rerun.
28
28
29
-
## What it does
29
+
## Upgrade bridge for older databases
30
30
31
-
`junior upgrade` runs migrations sequentially. Core and plugin migration
32
-
directories use Drizzle Kit's ordered journal and may contain either generated
33
-
SQL schema migrations or TypeScript data migrations targeting a versioned
34
-
host capability API. Current
35
-
upgrade work includes:
31
+
An existing Junior database without core Drizzle migration history must
32
+
complete the `0.107.1` upgrade before upgrading to a later release. Before
33
+
starting this bridge, block new ingress, drain active and resumable work, stop
34
+
all old workers and queue consumers, and keep them stopped until the later
35
+
release is ready. If Junior reports this unsupported database state:
36
36
37
-
- Apply core and enabled-plugin schema and data journal entries.
38
-
- Rewrite retained turn-session records from legacy storage shapes before the
39
-
new runtime reads them.
40
-
- Move legacy `junior:conversation-work:*` Redis state into the newer conversation record and index state used by the durable worker and dashboard feed.
41
-
- Backfill retained conversation records into the shared Junior SQL database. The upgrade requires `DATABASE_URL`.
42
-
- Apply the SQL schema cutover and rewrite legacy Pi-message rows into canonical conversation events.
43
-
- Repair legacy token and estimated-cost rollups from durable SQL conversation events in bounded batches. Conversations that are active during the repair are left unchanged and can be repaired by rerunning the command after they become idle.
37
+
1. Install `@sentry/junior@0.107.1`.
38
+
2. Run `pnpm exec junior upgrade` and confirm it completes successfully.
39
+
3. Restore the intended Junior version.
40
+
4. Run `pnpm exec junior upgrade` again.
41
+
5. Deploy the intended version, then restart workers and reopen ingress.
44
42
45
-
Completed journal entries are tracked individually, and TypeScript migrations
46
-
can checkpoint progress for safe retries. Legacy backfills remain idempotent:
47
-
rerunning them skips records that were already moved, removes stale legacy
48
-
index entries that no longer have a record, and upserts SQL conversation rows.
49
-
The conversation-history import paginates through every conversation in the
50
-
retained activity index; orphaned or expired Redis keys outside that index are
51
-
not treated as retained history. After cutover, SQL owns durable conversation
52
-
metadata and event history.
53
-
54
-
## Hard-cutover upgrade sequence
55
-
56
-
The canonical conversation-event cutover is not rolling-compatible. Do not run it inside a Vercel build while the previous deployment can still accept work. Use this operator sequence:
57
-
58
-
1. Block new ingress and enqueueing while leaving the previous release's workers and continuation consumers running.
59
-
2. Let existing work drain, then verify that no turns remain running or awaiting resume.
60
-
3. Stop every old worker, queue consumer, and heartbeat. Keep the old deployment stopped for the rest of the procedure.
61
-
4. Run the upgrade from an operator environment with the production `REDIS_URL`, `JUNIOR_STATE_KEY_PREFIX`, and `DATABASE_URL`.
62
-
5. Confirm the history import and message-event seal complete with no missing rows.
63
-
6. Run `junior check`, deploy the new release, and only then reopen ingress and start the new workers.
64
-
65
-
Run the upgrade as a separate operator command:
66
-
67
-
```bash
68
-
pnpm exec junior upgrade
69
-
pnpm exec junior check
70
-
```
71
-
72
-
The checkpoint and message-event rewrites fail closed if resumable work remains. After the drain succeeds, each rewrite invalidates stale resume state before changing physical event positions. Checkpoint normalization closes deletion gaps, and the message migration resequences the streams it changes while preserving reporting summaries.
73
-
74
-
If the command exits nonzero, leave the deployment stopped, correct the reported state, and rerun it. Do not restart workers after only part of the sequence completes.
43
+
Fresh databases without Junior tables do not require the bridge release.
75
44
76
45
## Example output
77
46
78
-
Typical logs look like this:
47
+
An already-current database reports its migrations as existing:
If the configured state store is unavailable or a legacy record is malformed, the CLI exits non-zero and prints the underlying error:
92
-
93
-
```text
94
-
junior command failed: Legacy conversation work state is invalid for slack:C123:1712345.0001
95
-
```
96
-
97
-
Treat that as a deploy blocker for the affected environment. Check `REDIS_URL`, `JUNIOR_STATE_KEY_PREFIX`, `DATABASE_URL`, and the reported legacy record before retrying.
60
+
The command exits nonzero when it cannot connect to SQL, encounters an
61
+
unsupported pre-Drizzle database, or a migration fails. Treat that as a deploy
62
+
blocker: correct the reported database or migration error, then rerun the
63
+
command.
98
64
99
65
## Verification
100
66
101
-
After running the command:
102
-
103
-
1. Confirm the final log line includes `Junior upgrade complete`.
104
-
2. Confirm `backfill-conversation-events-sql` scanned the complete retained activity index and did not stop at one page.
105
-
3. Confirm `move-conversation-messages-to-events` reports `missing=0`. The runtime now uses the copied events. The legacy message table remains available so a later upgrade can recover messages written by old workers during deployment.
106
-
4. Run `pnpm exec junior check` before building or deploying the app.
67
+
Confirm that the command exits successfully and lists `junior` plus each
68
+
enabled plugin that owns migrations. The final line reports whether the
69
+
database was already current or how many migrations were applied.
107
70
108
71
## Next step
109
72
110
-
Run [junior check](/cli/check/) after the upgrade, then continue with [junior snapshot create](/cli/snapshot-create/) if your plugins need sandbox dependencies.
73
+
Run [junior check](/cli/check/) before deploying, then continue with
74
+
[junior snapshot create](/cli/snapshot-create/) if your plugins need sandbox
0 commit comments