Skip to content

Conversation

@imsitnikov
Copy link
Collaborator

No description provided.

FROM license_limits
WHERE tenant_id = p_tenant_id
AND started_at <= p_at_time
ORDER BY started_at DESC
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is order by required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeap, we need to get the last limit, but not the future one. This will be the current limit.

END IF;

ELSIF TG_OP = 'UPDATE' THEN
IF OLD.created_at != NEW.created_at THEN
Copy link
Contributor

Choose a reason for hiding this comment

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

can't we just add both, new and old value, for simplicity, as we have DISTINCT in SELECT DISTINCT unnest(v_check_times) AS check_time?

Probably IS NOT NULL can be added to it:

SELECT DISTINCT unnest(v_check_times) AS check_time WHERE unnest IS NOT NULL

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment on lines 103 to 108
ELSIF TG_OP = 'DELETE' THEN
v_check_times := v_check_times || OLD.created_at;
IF OLD.expires_at IS NOT NULL THEN
v_check_times := v_check_times || OLD.expires_at;
END IF;
END IF;
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we actually need to check limits on license delete?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so, fixed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess it could be a block with return to skip check even for NOW()

ELSIF TG_OP = 'DELETE' THEN
    RETURN OLD;
END IF;

Comment on lines 89 to 96
v_check_times := v_check_times || OLD.created_at || NEW.created_at;
ELSE
v_check_times := v_check_times || NEW.created_at;
END IF;

IF OLD.expires_at IS DISTINCT FROM NEW.expires_at THEN
IF OLD.expires_at IS NOT NULL THEN
v_check_times := v_check_times || OLD.expires_at;
Copy link
Collaborator

@stepanenkoxx stepanenkoxx Nov 7, 2025

Choose a reason for hiding this comment

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

It's also possible that there is no need to check OLD.created_at and OLD.expires_at on license update
Because update is actually same as DELETE and then INSERT
But this is only if check upon deletion is really not necessary

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, it makes sense if we're clearing expires_at for a license that expires next month. Without adding OLD.expires_at to v_check_times, we'll get exceeded limit next month.

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.

5 participants