Skip to content

Commit 62ce779

Browse files
authored
Clean up extraneous SQL annotations (#444)
A small change that goes through and cleans up SQL a bit by removing some unnecessary annotations, mostly typecasting that's already implied by the type of the column where the values are going.
1 parent b44f59a commit 62ce779

9 files changed

Lines changed: 96 additions & 95 deletions

File tree

riverdriver/riverdatabasesql/internal/dbsqlc/river_job.sql.go

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

riverdriver/riverdatabasesql/internal/dbsqlc/river_leader.sql.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

riverdriver/riverdatabasesql/migration/main/002_initial_schema.up.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CREATE TABLE river_job(
1818
-- looking at jobs with `SELECT *` it'll appear first after ID. The other two
1919
-- fields aren't as important but are kept adjacent to `state` for alignment
2020
-- to get an 8-byte block.
21-
state river_job_state NOT NULL DEFAULT 'available' ::river_job_state,
21+
state river_job_state NOT NULL DEFAULT 'available',
2222
attempt smallint NOT NULL DEFAULT 0,
2323
max_attempts smallint NOT NULL,
2424

@@ -36,8 +36,8 @@ CREATE TABLE river_job(
3636
attempted_by text[],
3737
errors jsonb[],
3838
kind text NOT NULL,
39-
metadata jsonb NOT NULL DEFAULT '{}' ::jsonb,
40-
queue text NOT NULL DEFAULT 'default' ::text,
39+
metadata jsonb NOT NULL DEFAULT '{}',
40+
queue text NOT NULL DEFAULT 'default',
4141
tags varchar(255)[],
4242

4343
CONSTRAINT finalized_or_finalized_at_null CHECK ((state IN ('cancelled', 'completed', 'discarded') AND finalized_at IS NOT NULL) OR finalized_at IS NULL),

riverdriver/riverpgxv5/internal/dbsqlc/river_job.sql

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ CREATE TYPE river_job_state AS ENUM(
1111

1212
CREATE TABLE river_job(
1313
id bigserial PRIMARY KEY,
14-
args jsonb NOT NULL DEFAULT '{}'::jsonb,
14+
args jsonb NOT NULL DEFAULT '{}',
1515
attempt smallint NOT NULL DEFAULT 0,
1616
attempted_at timestamptz,
1717
attempted_by text[],
@@ -20,12 +20,12 @@ CREATE TABLE river_job(
2020
finalized_at timestamptz,
2121
kind text NOT NULL,
2222
max_attempts smallint NOT NULL,
23-
metadata jsonb NOT NULL DEFAULT '{}' ::jsonb,
23+
metadata jsonb NOT NULL DEFAULT '{}',
2424
priority smallint NOT NULL DEFAULT 1,
25-
queue text NOT NULL DEFAULT 'default' ::text,
26-
state river_job_state NOT NULL DEFAULT 'available' ::river_job_state,
25+
queue text NOT NULL DEFAULT 'default',
26+
state river_job_state NOT NULL DEFAULT 'available',
2727
scheduled_at timestamptz NOT NULL DEFAULT NOW(),
28-
tags varchar(255)[] NOT NULL DEFAULT '{}' ::varchar(255)[],
28+
tags varchar(255)[] NOT NULL DEFAULT '{}',
2929
CONSTRAINT finalized_or_finalized_at_null CHECK (
3030
(finalized_at IS NULL AND state NOT IN ('cancelled', 'completed', 'discarded')) OR
3131
(finalized_at IS NOT NULL AND state IN ('cancelled', 'completed', 'discarded'))
@@ -61,8 +61,8 @@ updated_job AS (
6161
SET
6262
-- If the job is actively running, we want to let its current client and
6363
-- producer handle the cancellation. Otherwise, immediately cancel it.
64-
state = CASE WHEN state = 'running'::river_job_state THEN state ELSE 'cancelled'::river_job_state END,
65-
finalized_at = CASE WHEN state = 'running'::river_job_state THEN finalized_at ELSE now() END,
64+
state = CASE WHEN state = 'running' THEN state ELSE 'cancelled' END,
65+
finalized_at = CASE WHEN state = 'running' THEN finalized_at ELSE now() END,
6666
-- Mark the job as cancelled by query so that the rescuer knows not to
6767
-- rescue it, even if it gets stuck in the running state:
6868
metadata = jsonb_set(metadata, '{cancel_attempted_at}'::text[], @cancel_attempted_at::jsonb, true)
@@ -96,7 +96,7 @@ deleted_job AS (
9696
USING job_to_delete
9797
WHERE river_job.id = job_to_delete.id
9898
-- Do not touch running jobs:
99-
AND river_job.state != 'running'::river_job_state
99+
AND river_job.state != 'running'
100100
RETURNING river_job.*
101101
)
102102
SELECT *
@@ -132,7 +132,7 @@ WITH locked_jobs AS (
132132
FROM
133133
river_job
134134
WHERE
135-
state = 'available'::river_job_state
135+
state = 'available'
136136
AND queue = @queue::text
137137
AND scheduled_at <= now()
138138
ORDER BY
@@ -146,7 +146,7 @@ WITH locked_jobs AS (
146146
UPDATE
147147
river_job
148148
SET
149-
state = 'running'::river_job_state,
149+
state = 'running',
150150
attempt = river_job.attempt + 1,
151151
attempted_at = now(),
152152
attempted_by = array_append(river_job.attempted_by, @attempted_by::text)
@@ -187,7 +187,7 @@ ORDER BY id;
187187
-- name: JobGetStuck :many
188188
SELECT *
189189
FROM river_job
190-
WHERE state = 'running'::river_job_state
190+
WHERE state = 'running'
191191
AND attempted_at < @stuck_horizon::timestamptz
192192
ORDER BY id
193193
LIMIT @max;
@@ -206,16 +206,16 @@ INSERT INTO river_job(
206206
state,
207207
tags
208208
) VALUES (
209-
@args::jsonb,
209+
@args,
210210
coalesce(sqlc.narg('created_at')::timestamptz, now()),
211211
@finalized_at,
212-
@kind::text,
213-
@max_attempts::smallint,
212+
@kind,
213+
@max_attempts,
214214
coalesce(@metadata::jsonb, '{}'),
215-
@priority::smallint,
216-
@queue::text,
215+
@priority,
216+
@queue,
217217
coalesce(sqlc.narg('scheduled_at')::timestamptz, now()),
218-
@state::river_job_state,
218+
@state,
219219
coalesce(@tags::varchar(255)[], '{}')
220220
) RETURNING *;
221221

@@ -267,15 +267,15 @@ INSERT INTO river_job(
267267
coalesce(@attempt::smallint, 0),
268268
@attempted_at,
269269
coalesce(sqlc.narg('created_at')::timestamptz, now()),
270-
@errors::jsonb[],
270+
@errors,
271271
@finalized_at,
272-
@kind::text,
272+
@kind,
273273
@max_attempts::smallint,
274274
coalesce(@metadata::jsonb, '{}'),
275-
@priority::smallint,
276-
@queue::text,
275+
@priority,
276+
@queue,
277277
coalesce(sqlc.narg('scheduled_at')::timestamptz, now()),
278-
@state::river_job_state,
278+
@state,
279279
coalesce(@tags::varchar(255)[], '{}')
280280
) RETURNING *;
281281

@@ -307,16 +307,16 @@ WITH job_to_update AS (
307307
updated_job AS (
308308
UPDATE river_job
309309
SET
310-
state = 'available'::river_job_state,
310+
state = 'available',
311311
scheduled_at = now(),
312312
max_attempts = CASE WHEN attempt = max_attempts THEN max_attempts + 1 ELSE max_attempts END,
313313
finalized_at = NULL
314314
FROM job_to_update
315315
WHERE river_job.id = job_to_update.id
316316
-- Do not touch running jobs:
317-
AND river_job.state != 'running'::river_job_state
317+
AND river_job.state != 'running'
318318
-- If the job is already available with a prior scheduled_at, leave it alone.
319-
AND NOT (river_job.state = 'available'::river_job_state AND river_job.scheduled_at < now())
319+
AND NOT (river_job.state = 'available' AND river_job.scheduled_at < now())
320320
RETURNING river_job.*
321321
)
322322
SELECT *
@@ -345,7 +345,7 @@ WITH jobs_to_schedule AS (
345345
),
346346
river_job_scheduled AS (
347347
UPDATE river_job
348-
SET state = 'available'::river_job_state
348+
SET state = 'available'
349349
FROM jobs_to_schedule
350350
WHERE river_job.id = jobs_to_schedule.id
351351
RETURNING river_job.id
@@ -364,7 +364,7 @@ job_to_update AS (
364364
SELECT river_job.id, job_to_finalized_at.finalized_at
365365
FROM river_job, job_to_finalized_at
366366
WHERE river_job.id = job_to_finalized_at.id
367-
AND river_job.state = 'running'::river_job_state
367+
AND river_job.state = 'running'
368368
FOR UPDATE
369369
),
370370
updated_job AS (
@@ -387,7 +387,7 @@ FROM updated_job;
387387
WITH job_to_update AS (
388388
SELECT
389389
id,
390-
@state::river_job_state IN ('retryable'::river_job_state, 'scheduled'::river_job_state) AND metadata ? 'cancel_attempted_at' AS should_cancel
390+
@state::river_job_state IN ('retryable', 'scheduled') AND metadata ? 'cancel_attempted_at' AS should_cancel
391391
FROM river_job
392392
WHERE id = @id::bigint
393393
FOR UPDATE
@@ -408,7 +408,7 @@ updated_job AS (
408408
ELSE scheduled_at END
409409
FROM job_to_update
410410
WHERE river_job.id = job_to_update.id
411-
AND river_job.state = 'running'::river_job_state
411+
AND river_job.state = 'running'
412412
RETURNING river_job.*
413413
)
414414
SELECT *

0 commit comments

Comments
 (0)