Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend: fix v2_job.tag length #5242

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- Add down migration script here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Down migration script is just a placeholder. Provide a proper down migration to reverse the changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Down migration script is empty; please implement reversal logic.

34 changes: 34 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,34 @@
-- 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);
ALTER TABLE flow ALTER COLUMN tag TYPE VARCHAR(255);
ALTER TABLE schedule ALTER COLUMN tag TYPE VARCHAR(255);
ALTER TABLE script 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 $$;