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
Alright, so this one's been some cleanup that I've been intending for a
while. Previously, sqlc made using JSONB in SQLite completely unusable
because it sent back the binary format which you're explicitly not
supposed to parse yourself. I ended up fixing this like a year ago in
[1], but getting a sqlc release out the door took so long that I ended
up forgetting about it.
Here, modify our SQLite definitions so that JSON becomes JSONB, and add
migration to convert existing installation values to the same. Luckily,
this doesn't require a table rewrite because both JSON and JSONB are
SQLite BLOB types.
I didn't want to add a migration version just for SQLite, so to keep
everything in sync I also added a version 7 for Postgres that's just a
no-op with a comment.
[1] sqlc-dev/sqlc#3968
Copy file name to clipboardExpand all lines: CHANGELOG.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
8
8
## [Unreleased]
9
9
10
+
⚠️ Version 0.36.0 contains a new database migration, version 7, but running it is **only necessary if you're using SQLite**. It converts all uses of `json` to `jsonb`. If using Postgres, version 7 is a no-op. You can run it now or wait for another migration in the future and run the two together.
11
+
12
+
See [documentation on running River migrations](https://riverqueue.com/docs/migrations). If migrating with the CLI, make sure to update it to its latest version:
13
+
14
+
```shell
15
+
go install github.com/riverqueue/river/cmd/river@latest
16
+
river migrate-up --database-url "$DATABASE_URL"
17
+
```
18
+
19
+
If not using River's internal migration system, the raw SQL can alternatively be dumped with:
20
+
21
+
```shell
22
+
go install github.com/riverqueue/river/cmd/river@latest
23
+
river migrate-get --database-url sqlite:// --version 6 --up > river7.up.sql
24
+
river migrate-get --database-url sqlite:// --version 6 --down > river7.down.sql
-- for JobSetStateIfRunning to use when falling back to non-running jobs.
455
455
-- name: JobSetMetadataIfNotRunning :one
456
456
UPDATE/* TEMPLATE: schema */river_job
457
-
SET metadata =json_patch(metadata, json(cast(@metadata_updatesAS blob)))
457
+
SET metadata =jsonb_patch(metadata, jsonb(@metadata_updates))
458
458
WHERE id = @id
459
459
AND state !='running'
460
460
RETURNING *;
@@ -472,15 +472,15 @@ SET
472
472
THEN @attempt
473
473
ELSE attempt END,
474
474
errors = CASE WHEN cast(@errors_do_update ASboolean)
475
-
THEN json_insert(coalesce(errors, json('[]')), '$[#]', json(cast(@errorAS blob)))
475
+
THEN jsonb_insert(coalesce(errors, jsonb('[]')), '$[#]', jsonb(@error))
476
476
ELSE errors END,
477
477
finalized_at = CASE WHEN /* should_cancel */((@state ='retryable'OR @state ='scheduled') AND (metadata ->'cancel_attempted_at') iS NOT NULL)
478
478
THEN coalesce(cast(sqlc.narg('now') AStext), datetime('now', 'subsec'))
479
479
WHEN cast(@finalized_at_do_update ASboolean)
480
480
THEN @finalized_at
481
481
ELSE finalized_at END,
482
482
metadata = CASE WHEN cast(@metadata_do_merge ASboolean)
483
-
THEN json_patch(metadata, json(cast(@metadata_updatesAS blob)))
483
+
THEN jsonb_patch(metadata, jsonb(@metadata_updates))
484
484
ELSE metadata END,
485
485
scheduled_at = CASE WHEN /* NOT should_cancel */(cast(@state AStext) <>'retryable'AND @state <>'scheduled'OR (metadata ->'cancel_attempted_at') IS NULL) AND cast(@scheduled_at_do_update ASboolean)
486
486
THEN @scheduled_at
@@ -495,7 +495,7 @@ RETURNING *;
495
495
-- name: JobUpdate :one
496
496
UPDATE/* TEMPLATE: schema */river_job
497
497
SET
498
-
metadata = CASE WHEN cast(@metadata_do_merge ASboolean) THEN json_patch(metadata, json(cast(@metadataAS blob))) ELSE metadata END
498
+
metadata = CASE WHEN cast(@metadata_do_merge ASboolean) THEN jsonb_patch(metadata, jsonb(@metadata)) ELSE metadata END
499
499
WHERE id = @id
500
500
RETURNING *;
501
501
@@ -510,7 +510,7 @@ SET
510
510
errors = CASE WHEN cast(@errors_do_update ASboolean) THEN @errors ELSE errors END,
511
511
finalized_at = CASE WHEN cast(@finalized_at_do_update ASboolean) THEN @finalized_at ELSE finalized_at END,
512
512
max_attempts = CASE WHEN cast(@max_attempts_do_update ASboolean) THEN @max_attempts ELSE max_attempts END,
513
-
metadata = CASE WHEN cast(@metadata_do_update ASboolean) THEN json(cast(@metadataAS blob)) ELSE metadata END,
513
+
metadata = CASE WHEN cast(@metadata_do_update ASboolean) THEN jsonb(@metadata) ELSE metadata END,
514
514
state = CASE WHEN cast(@state_do_update ASboolean) THEN @state ELSE state END
0 commit comments