Skip to content

Commit

Permalink
backend: fix v2_job.tag length
Browse files Browse the repository at this point in the history
  • Loading branch information
uael committed Feb 7, 2025
1 parent b09eb04 commit 4d34fab
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/migrations/20250205131516_v2_job_tag_size.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- Add down migration script here
31 changes: 31 additions & 0 deletions backend/migrations/20250205131516_v2_job_tag_size.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- Add up migration script here
DO $$
DECLARE
rec RECORD;
view_definitions TEXT[];
view_names TEXT[];
BEGIN
-- Step 1: Store view definitions
FOR rec IN (
SELECT c.relname AS view_name, pg_get_viewdef(c.oid, true) AS view_sql
FROM pg_class c JOIN pg_namespace n ON c.relnamespace = n.oid
WHERE c.relkind = 'v' AND c.relname IN ('job', 'v2_as_queue', 'v2_as_completed_job')
) LOOP
-- Save view names and definitions
view_names := array_append(view_names, rec.view_name);
view_definitions := array_append(view_definitions, rec.view_sql);
END LOOP;

-- Step 2: Drop the views
FOR i IN 1..array_length(view_names, 1) LOOP
EXECUTE format('DROP VIEW IF EXISTS %I', view_names[i]);
END LOOP;

-- Step 3: Alter the table column type
ALTER TABLE v2_job ALTER COLUMN tag TYPE VARCHAR(255);

-- Step 4: Recreate the views using stored definitions
FOR i IN 1..array_length(view_names, 1) LOOP
EXECUTE format('CREATE OR REPLACE VIEW %I AS %s', view_names[i], view_definitions[i]);
END LOOP;
END $$;

0 comments on commit 4d34fab

Please sign in to comment.