Skip to content

database: drop old delete_system function#2229

Open
TenSt wants to merge 1 commit into
RedHatInsights:masterfrom
TenSt:stepan/drop-old-delete-system-function
Open

database: drop old delete_system function#2229
TenSt wants to merge 1 commit into
RedHatInsights:masterfrom
TenSt:stepan/drop-old-delete-system-function

Conversation

@TenSt
Copy link
Copy Markdown
Collaborator

@TenSt TenSt commented Jun 4, 2026

We found out that there is an old delete_system(inventory_id_in varchar) function that was living in our database for a long time.

@TenSt TenSt requested a review from a team as a code owner June 4, 2026 13:52
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jun 4, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the database schema migration version and adds a new migration to drop the legacy delete_system function if it exists.

File-Level Changes

Change Details Files
Advance the schema version and register migration 158 as the latest.
  • Update the schema_migrations seed row to use version 158 instead of 157
database_admin/schema/create_schema.sql
Introduce a migration that removes the deprecated delete_system database function.
  • Create an up migration script numbered 158
  • Drop the delete_system(inventory_id_in varchar) function defensively using IF EXISTS
database_admin/migrations/158_drop_old_delete_system_function.up.sql

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Consider schema-qualifying the function in the migration (e.g., DROP FUNCTION IF EXISTS public.delete_system(...)) to avoid ambiguity if multiple schemas define a delete_system function.
  • If your migration process supports rollbacks, you may want to add a corresponding down migration that re-creates delete_system to keep the migration set reversible.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider schema-qualifying the function in the migration (e.g., `DROP FUNCTION IF EXISTS public.delete_system(...)`) to avoid ambiguity if multiple schemas define a `delete_system` function.
- If your migration process supports rollbacks, you may want to add a corresponding down migration that re-creates `delete_system` to keep the migration set reversible.

## Individual Comments

### Comment 1
<location path="database_admin/migrations/158_drop_old_delete_system_function.up.sql" line_range="1" />
<code_context>
+DROP FUNCTION IF EXISTS delete_system(inventory_id_in varchar);
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Schema-qualify the function name and verify the dropped signature matches all existing overloads.

Relying on the search_path can drop the wrong function when multiple schemas or similarly named functions exist. Also, if other delete_system overloads exist (e.g., text vs varchar), they’ll be left behind. Consider explicitly qualifying the schema in the DROP statement and ensuring all relevant overloads are removed as needed.

Suggested implementation:

```
-- Explicitly drop all known overloads of delete_system, schema-qualified
-- to avoid relying on search_path and accidentally dropping the wrong function.

-- NOTE: adjust the schema name and overloads here if they differ in your environment.
DROP FUNCTION IF EXISTS public.delete_system(inventory_id_in varchar);

-- Example additional overloads; uncomment or adjust as needed:
-- DROP FUNCTION IF EXISTS public.delete_system(inventory_id_in text);
-- DROP FUNCTION IF EXISTS public.delete_system(inventory_id_in uuid);

```

1. Confirm the actual schema that owns `delete_system` (e.g., `public`, `inventory`, or another app schema) and replace `public` with the correct schema.
2. Query the catalog (e.g., `SELECT proname, oid::regprocedure FROM pg_proc WHERE proname = 'delete_system';`) to identify all existing overloads.
3. For each overload you find, add a corresponding `DROP FUNCTION IF EXISTS schema.delete_system(<arg_types>);` line to this migration, removing or adjusting the example overloads I included.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@TenSt TenSt enabled auto-merge (rebase) June 4, 2026 13:54
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.44%. Comparing base (cf25d8a) to head (41289b3).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2229      +/-   ##
==========================================
- Coverage   58.46%   58.44%   -0.03%     
==========================================
  Files         139      139              
  Lines        8925     8925              
==========================================
- Hits         5218     5216       -2     
- Misses       3159     3161       +2     
  Partials      548      548              
Flag Coverage Δ
unittests 58.44% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

auto-merge was automatically disabled June 4, 2026 14:57

Branch protection rule check failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants