mirror of
https://github.com/warmbly/warmbly.git
synced 2026-08-19 16:01:16 +00:00
1317ea67d6
PR #10 added 000035_api_key_suffix and PR #11 separately added 000035_api_key_smart_limits, both targeting the api_keys table. golang-migrate refuses to load when two source files share a version number, so the backend container failed health checks in fresh stacks. Bumping api_key_smart_limits to 000037 keeps PR #10 in its original slot (it landed first) and matches the next free version after 000036_contact_categories. The two migrations touch different columns so apply order does not matter.
27 lines
1.2 KiB
SQL
27 lines
1.2 KiB
SQL
-- Smart per-key rate limits + analytics-friendly indexes.
|
|
--
|
|
-- rate_limit_per_minute: soft cap enforced in middleware via Redis sliding
|
|
-- window. Defaults to 60 r/m (matches the marketing copy on the dashboard);
|
|
-- workspace owners can raise/lower it per key. NULL would mean "no limit"
|
|
-- but we store an explicit value so the column reads simpler.
|
|
--
|
|
-- description: human note shown next to the key in the dashboard. Helps
|
|
-- when a workspace has many keys for many integrations.
|
|
--
|
|
-- last_request_ip: most recent caller IP. Useful for "where's this key
|
|
-- being used from" without scanning the usage log table.
|
|
|
|
ALTER TABLE api_keys
|
|
ADD COLUMN rate_limit_per_minute INT NOT NULL DEFAULT 60,
|
|
ADD COLUMN description TEXT,
|
|
ADD COLUMN last_request_ip INET;
|
|
|
|
-- Analytics: bucketed timeseries grouped by status family. Compound index
|
|
-- so the (api_key_id, created_at) → response_status scan is index-only.
|
|
CREATE INDEX IF NOT EXISTS idx_api_key_usage_key_time_status
|
|
ON api_key_usage_logs (api_key_id, created_at DESC, response_status);
|
|
|
|
-- Endpoint breakdown: top endpoints by call count per key.
|
|
CREATE INDEX IF NOT EXISTS idx_api_key_usage_endpoint
|
|
ON api_key_usage_logs (api_key_id, endpoint);
|