From be18d15507fd510f9411bebb3dddbfb468e2a051 Mon Sep 17 00:00:00 2001 From: Aidan Jensen Date: Fri, 20 Dec 2024 14:29:59 -0800 Subject: [PATCH] only create schema if doesn't exist Signed-off-by: Aidan Jensen --- db/schema.sql | 6 +++--- internal/db.go | 2 +- internal/models.go | 4 +--- internal/queries.sql.go | 2 +- internal/schema.go | 6 +++--- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/db/schema.sql b/db/schema.sql index b2bfa93..216f995 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -1,6 +1,6 @@ PRAGMA journal_mode = WAL; -CREATE TABLE jobs ( +CREATE TABLE IF NOT EXISTS jobs ( id INTEGER NOT NULL, queue TEXT NOT NULL, job TEXT NOT NULL, @@ -16,12 +16,12 @@ CREATE TABLE jobs ( PRIMARY KEY (id) ); -CREATE INDEX todo ON jobs (queue, job_status, execute_after) +CREATE INDEX IF NOT EXISTS todo ON jobs (queue, job_status, execute_after) WHERE job_status = 'queued' OR job_status = 'fetched'; -CREATE UNIQUE INDEX dedupe ON jobs (deduping_key, job_status) +CREATE UNIQUE INDEX IF NOT EXISTS dedupe ON jobs (deduping_key, job_status) WHERE deduping_key != '' AND job_status = 'queued'; diff --git a/internal/db.go b/internal/db.go index 9e50c0c..45a0533 100644 --- a/internal/db.go +++ b/internal/db.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.25.0 +// sqlc v1.27.0 package internal diff --git a/internal/models.go b/internal/models.go index b57c523..aaad1a5 100644 --- a/internal/models.go +++ b/internal/models.go @@ -1,11 +1,9 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.25.0 +// sqlc v1.27.0 package internal -import () - type Job struct { ID int64 Queue string diff --git a/internal/queries.sql.go b/internal/queries.sql.go index 89848e5..c330f45 100644 --- a/internal/queries.sql.go +++ b/internal/queries.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.25.0 +// sqlc v1.27.0 // source: queries.sql package internal diff --git a/internal/schema.go b/internal/schema.go index a863793..d3c4732 100644 --- a/internal/schema.go +++ b/internal/schema.go @@ -4,7 +4,7 @@ package internal const Schema = ` PRAGMA journal_mode = WAL; -CREATE TABLE jobs ( +CREATE TABLE IF NOT EXISTS jobs ( id INTEGER NOT NULL, queue TEXT NOT NULL, job TEXT NOT NULL, @@ -20,12 +20,12 @@ CREATE TABLE jobs ( PRIMARY KEY (id) ); -CREATE INDEX todo ON jobs (queue, job_status, execute_after) +CREATE INDEX IF NOT EXISTS todo ON jobs (queue, job_status, execute_after) WHERE job_status = 'queued' OR job_status = 'fetched'; -CREATE UNIQUE INDEX dedupe ON jobs (deduping_key, job_status) +CREATE UNIQUE INDEX IF NOT EXISTS dedupe ON jobs (deduping_key, job_status) WHERE deduping_key != '' AND job_status = 'queued';