Skip to content

Commit

Permalink
db: Fix bug in batch api removal
Browse files Browse the repository at this point in the history
  • Loading branch information
jhf committed Jan 23, 2025
1 parent 389aed4 commit b12e532
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,21 @@ BEGIN

EXECUTE 'DROP FUNCTION ' || prepare_function_name_custom || '()';

-- Drop the unique index created by generate_active_code_custom_unique_constraint
EXECUTE format('DROP INDEX IF EXISTS ix_%I_active_code', table_name_str);
-- Get unique columns and construct index name using same logic as in generate_active_code_custom_unique_constraint
DECLARE
table_properties admin.batch_api_table_properties;
unique_columns text[];
index_name text;
BEGIN
table_properties := admin.detect_batch_api_table_properties(table_name);
unique_columns := admin.get_unique_columns(table_properties);

-- Only attempt to drop if we have unique columns
IF array_length(unique_columns, 1) IS NOT NULL THEN
index_name := 'ix_' || table_name_str || '_' || array_to_string(unique_columns, '_');
EXECUTE format('DROP INDEX IF EXISTS %I', index_name);
END IF;
END;
END;
$$ LANGUAGE plpgsql;

Expand Down

0 comments on commit b12e532

Please sign in to comment.