-
Notifications
You must be signed in to change notification settings - Fork 0
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
fix: raise notice to delete dependent fields after workspace reset #230
Changes from 1 commit
8a961b5
ba48fed
def3e25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,6 +200,20 @@ BEGIN | |
WHERE w.id = _workspace_id; | ||
GET DIAGNOSTICS rcount = ROW_COUNT; | ||
RAISE NOTICE 'Deleted % workspaces', rcount; | ||
|
||
_org_id := (SELECT fyle_org_id FROM workspaces WHERE id = _workspace_id); | ||
|
||
RAISE NOTICE E'\n\n\n\n\n\n\n\n\nSwitch to prod db and run the below queries to delete dependent fields | ||
|
||
|
||
rollback; | ||
begin; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Remove incorrect transaction control statements The - rollback;
- begin; |
||
|
||
delete from platform_schema.dependent_expense_field_mappings where expense_field_id in (select id from platform_schema.expense_fields where org_id =''%'' and type=''DEPENDENT_SELECT''); | ||
|
||
delete from platform_schema.expense_fields where org_id = ''%'' and type = ''DEPENDENT_SELECT'';\n\n\n\n\n\n\n\n\n\n\n', _org_id, _org_id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security: Fix SQL injection vulnerability and improve architecture The current implementation has several issues:
Consider creating a separate function in the production database to handle this cleanup: CREATE OR REPLACE FUNCTION cleanup_dependent_fields(IN _org_id varchar) RETURNS void AS $$
BEGIN
IF _org_id IS NULL THEN
RAISE EXCEPTION 'Organization ID cannot be null';
END IF;
DELETE FROM platform_schema.dependent_expense_field_mappings
WHERE expense_field_id IN (
SELECT id
FROM platform_schema.expense_fields
WHERE org_id = _org_id
AND type = 'DEPENDENT_SELECT'
);
DELETE FROM platform_schema.expense_fields
WHERE org_id = _org_id
AND type = 'DEPENDENT_SELECT';
END;
$$ LANGUAGE plpgsql; Then modify the notice to reference this function: - delete from platform_schema.dependent_expense_field_mappings where expense_field_id in (select id from platform_schema.expense_fields where org_id =''%'' and type=''DEPENDENT_SELECT'');
- delete from platform_schema.expense_fields where org_id = ''%'' and type = ''DEPENDENT_SELECT'';\n\n\n\n\n\n\n\n\n\n\n'
+ SELECT cleanup_dependent_fields(''%'');\n\n'
JustARatherRidiculouslyLongUsername marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
RETURN; | ||
END | ||
$$ LANGUAGE plpgsql; |
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.
Critical: Variable assignment will always return NULL
The
_org_id
assignment happens after the workspaces table has been deleted (see line 202), making this SELECT statement always return NULL. Move this assignment to the beginning of the function, right after the variable declarations.DECLARE rcount integer; _org_id varchar(255); BEGIN + _org_id := (SELECT fyle_org_id FROM workspaces WHERE id = _workspace_id); RAISE NOTICE 'Deleting data from workspace % ', _workspace_id;