Skip to content

Commit 925b67e

Browse files
CodingAnarchyclaude
andcommitted
fix: Fix migration 012 for empty table and update postgres.rs for UUID arrays
- Remove WHERE clause from migration UPDATE statements to handle empty tables - Fix jsonb_array_elements_text usage in migration for proper UUID extraction - Update postgres.rs dependency resolution to use UUID array operations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent e0358cc commit 925b67e

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/migrations/012_optimize_dependencies.postgres.sql

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ SET depends_on_array = CASE
1919
WHEN jsonb_typeof(depends_on) = 'array' THEN
2020
ARRAY(
2121
SELECT elem::UUID
22-
FROM jsonb_array_elements_text(depends_on) AS elem(value)
23-
WHERE elem.value ~ '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'
22+
FROM jsonb_array_elements_text(depends_on) AS elem
23+
WHERE elem::text ~ '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'
2424
)
2525
ELSE '{}'::UUID[]
26-
END
27-
WHERE depends_on_array = '{}';
26+
END;
2827

2928
-- Handle dependents column with UUID validation
3029
UPDATE hammerwork_jobs
@@ -33,12 +32,11 @@ SET dependents_array = CASE
3332
WHEN jsonb_typeof(dependents) = 'array' THEN
3433
ARRAY(
3534
SELECT elem::UUID
36-
FROM jsonb_array_elements_text(dependents) AS elem(value)
37-
WHERE elem.value ~ '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'
35+
FROM jsonb_array_elements_text(dependents) AS elem
36+
WHERE elem::text ~ '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'
3837
)
3938
ELSE '{}'::UUID[]
40-
END
41-
WHERE dependents_array = '{}';
39+
END;
4240

4341
-- Step 3: Verify data migration integrity
4442
DO $$

src/queue/postgres.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,19 +1779,19 @@ impl DatabaseQueue for crate::queue::JobQueue<Postgres> {
17791779
r#"
17801780
SELECT id, depends_on
17811781
FROM hammerwork_jobs
1782-
WHERE depends_on @> $1::jsonb
1782+
WHERE $1 = ANY(depends_on)
17831783
AND dependency_status = 'waiting'
17841784
"#,
17851785
)
1786-
.bind(serde_json::json!([completed_job_id]))
1786+
.bind(completed_job_id)
17871787
.fetch_all(&self.pool)
17881788
.await?;
17891789

17901790
let mut resolved_jobs = Vec::new();
17911791

17921792
for job_row in dependent_jobs {
17931793
let job_id: uuid::Uuid = job_row.get("id");
1794-
let depends_on: Vec<uuid::Uuid> = serde_json::from_value(job_row.get("depends_on"))?;
1794+
let depends_on: Vec<uuid::Uuid> = job_row.get("depends_on");
17951795

17961796
// Check if all dependencies are now satisfied
17971797
let satisfied_count = sqlx::query_scalar::<_, i64>(
@@ -1860,12 +1860,12 @@ impl DatabaseQueue for crate::queue::JobQueue<Postgres> {
18601860
r#"
18611861
SELECT id
18621862
FROM hammerwork_jobs
1863-
WHERE depends_on @> $1::jsonb
1863+
WHERE $1 = ANY(depends_on)
18641864
AND dependency_status IN ('waiting', 'satisfied')
18651865
AND status = 'Pending'
18661866
"#,
18671867
)
1868-
.bind(serde_json::json!([current_job_id]))
1868+
.bind(current_job_id)
18691869
.fetch_all(&self.pool)
18701870
.await?;
18711871

0 commit comments

Comments
 (0)