-
Notifications
You must be signed in to change notification settings - Fork 41
ci: support any org/workspace cleanup #855
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
base: main
Are you sure you want to change the base?
Conversation
Changed Files
|
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
WalkthroughThe PR enhances the test cleanup infrastructure by introducing organizational pattern filtering and workspace-specific cleanup modes. The SQL cleanup script now supports two conditional paths: specific workspace cleanup (when workspace_name is provided) and full organization cleanup (default). The shell wrapper was refactored to parse Changes
Sequence Diagram(s)sequenceDiagram
participant Shell as Shell Script<br/>(test-with-cleanup.sh)
participant Env as Environment<br/>Variables
participant SQL as SQL Script<br/>(cleanup.sql)
participant DB as PostgreSQL<br/>Database
Shell->>Env: Load .env file
Shell->>Shell: Parse --org-pattern & --workspace args
Shell->>Shell: Construct DATABASE_URL (if needed)
alt Specific Workspace Mode
Shell->>SQL: Pass org_pattern & workspace_name
SQL->>DB: Filter orgs by org_pattern
SQL->>DB: Find workspaces matching workspace_name
SQL->>DB: Drop specific workspace schemas
SQL->>DB: Delete specific workspace records
else Full Organization Mode
Shell->>SQL: Pass org_pattern (workspace_name empty)
SQL->>DB: Filter orgs by org_pattern
SQL->>DB: Drop all workspace schemas for org
SQL->>DB: Delete all workspace records for org
SQL->>DB: Delete organization records
end
SQL-->>Shell: Return cleanup summary
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@tests/cleanup.sql`:
- Around line 12-14: Change the current_setting calls used to initialize
v_org_pattern and v_workspace_name so they don't raise when the settings are
absent: replace current_setting('cleanup.org_pattern') and
current_setting('cleanup.workspace_name') with
current_setting('cleanup.org_pattern', true) and
current_setting('cleanup.workspace_name', true') (or wrap them in COALESCE(...,
'<default>') if you need a fallback), update the v_org_pattern and
v_workspace_name initializations accordingly, and ensure any later logic that
assumes non-NULL values checks for NULL or uses the chosen defaults.
In `@tests/test-with-cleanup.sh`:
- Around line 14-21: The --org-pattern and --workspace case branches currently
assign ORG_PATTERN="$2" and WORKSPACE_NAME="$2" without validating the next
token; update the case handlers for the --org-pattern and --workspace options to
check that "$2" is non-empty and does not begin with a dash (e.g., [[ -n "$2" &&
"${2:0:1}" != "-" ]]); if the check fails, print a clear usage/error message and
exit nonzero instead of assigning, otherwise assign the value and shift 2 as
before so ORG_PATTERN and WORKSPACE_NAME are safely populated.
🧹 Nitpick comments (1)
tests/cleanup.sql (1)
28-31: SQL injection risk: User-supplied pattern used directly in LIKE clause.The
v_org_patternvalue is used directly in theWHERE id LIKE v_org_patternclause. SinceLIKEis a parameterized comparison in PL/pgSQL (not string concatenation), this is safe from SQL injection. The risk here is more about unintended data deletion if a broad pattern like%is passed.Consider adding validation or a confirmation notice when the pattern could match many organizations (e.g., patterns starting with
%).Also applies to: 64-67
| -- Retrieve variables from session config | ||
| v_org_pattern text := current_setting('cleanup.org_pattern'); | ||
| v_workspace_name text := current_setting('cleanup.workspace_name'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current_setting() will throw an error if the setting doesn't exist.
When the session config isn't set (e.g., if set_config wasn't called), current_setting() raises an exception. Consider using current_setting('cleanup.org_pattern', true) to return NULL on missing settings instead of erroring.
🛡️ Proposed fix to handle missing settings gracefully
-- Retrieve variables from session config
- v_org_pattern text := current_setting('cleanup.org_pattern');
- v_workspace_name text := current_setting('cleanup.workspace_name');
+ v_org_pattern text := current_setting('cleanup.org_pattern', true);
+ v_workspace_name text := current_setting('cleanup.workspace_name', true);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| -- Retrieve variables from session config | |
| v_org_pattern text := current_setting('cleanup.org_pattern'); | |
| v_workspace_name text := current_setting('cleanup.workspace_name'); | |
| -- Retrieve variables from session config | |
| v_org_pattern text := current_setting('cleanup.org_pattern', true); | |
| v_workspace_name text := current_setting('cleanup.workspace_name', true); |
🤖 Prompt for AI Agents
In `@tests/cleanup.sql` around lines 12 - 14, Change the current_setting calls
used to initialize v_org_pattern and v_workspace_name so they don't raise when
the settings are absent: replace current_setting('cleanup.org_pattern') and
current_setting('cleanup.workspace_name') with
current_setting('cleanup.org_pattern', true) and
current_setting('cleanup.workspace_name', true') (or wrap them in COALESCE(...,
'<default>') if you need a fallback), update the v_org_pattern and
v_workspace_name initializations accordingly, and ensure any later logic that
assumes non-NULL values checks for NULL or uses the chosen defaults.
afc7e93 to
a1142b7
Compare
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
a1142b7 to
76585dd
Compare
Problem
The org cleanup script was hard-coded to cleanup only orgs starting with
org%and single workspaces could not be removed cleanly.Solution
This PR parameterizes the sql / shell script to enable any org / workspace deletion completely.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.