mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
Merge upstream main into feat/500-api-key-ip-whitelist
This commit is contained in:
@@ -2704,6 +2704,14 @@ CREATE INDEX IF NOT EXISTS idx_provider_api_keys_provider_active ON public.provi
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_provider_api_keys_provider_default_sort; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_provider_api_keys_provider_default_sort ON public.provider_api_keys USING btree (provider_id, internal_priority, name, id);
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_provider_api_keys_provider_created_at_desc; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
ALTER TABLE api_keys
|
||||
ADD COLUMN IF NOT EXISTS allowed_ips json NULL;
|
||||
@@ -0,0 +1,67 @@
|
||||
CREATE TABLE IF NOT EXISTS public.usage_counter_deltas (
|
||||
id character varying(36) NOT NULL,
|
||||
request_id character varying(128) NOT NULL,
|
||||
kind character varying(64) NOT NULL,
|
||||
target_id text NOT NULL,
|
||||
request_count_delta bigint DEFAULT 0 NOT NULL,
|
||||
total_requests_delta bigint DEFAULT 0 NOT NULL,
|
||||
success_count_delta bigint DEFAULT 0 NOT NULL,
|
||||
error_count_delta bigint DEFAULT 0 NOT NULL,
|
||||
dns_failures_delta bigint DEFAULT 0 NOT NULL,
|
||||
stream_errors_delta bigint DEFAULT 0 NOT NULL,
|
||||
total_tokens_delta bigint DEFAULT 0 NOT NULL,
|
||||
total_cost_usd_delta double precision DEFAULT 0 NOT NULL,
|
||||
total_response_time_ms_delta bigint DEFAULT 0 NOT NULL,
|
||||
last_used_at_unix_secs bigint,
|
||||
last_used_ip text,
|
||||
candidate_last_used_at_unix_secs bigint,
|
||||
removed_last_used_at_unix_secs bigint,
|
||||
usage_created_at_unix_secs bigint,
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
processed_at timestamp with time zone,
|
||||
CONSTRAINT usage_counter_deltas_pkey PRIMARY KEY (id),
|
||||
CONSTRAINT usage_counter_deltas_kind_check CHECK (
|
||||
kind IN (
|
||||
'api_key',
|
||||
'provider_api_key',
|
||||
'model',
|
||||
'provider_monthly',
|
||||
'proxy_node',
|
||||
'management_token',
|
||||
'api_key_last_used'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_usage_counter_deltas_unprocessed
|
||||
ON public.usage_counter_deltas USING btree (created_at, id)
|
||||
WHERE processed_at IS NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_usage_counter_deltas_processed
|
||||
ON public.usage_counter_deltas USING btree (processed_at, created_at, id)
|
||||
WHERE processed_at IS NOT NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_usage_counter_deltas_request_kind
|
||||
ON public.usage_counter_deltas USING btree (request_id, kind, target_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_entitlement_usage_entitlement_date
|
||||
ON public.entitlement_usage_ledgers USING btree (user_entitlement_id, usage_date);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_video_tasks_due_poll
|
||||
ON public.video_tasks USING btree (status, next_poll_at, updated_at)
|
||||
WHERE next_poll_at IS NOT NULL;
|
||||
|
||||
ALTER TABLE IF EXISTS public.api_keys
|
||||
ALTER COLUMN total_requests TYPE bigint USING COALESCE(total_requests, 0)::bigint;
|
||||
|
||||
ALTER TABLE IF EXISTS public.global_models
|
||||
ALTER COLUMN usage_count TYPE bigint USING COALESCE(usage_count, 0)::bigint;
|
||||
|
||||
ALTER TABLE IF EXISTS public.management_tokens
|
||||
ALTER COLUMN usage_count TYPE bigint USING COALESCE(usage_count, 0)::bigint;
|
||||
|
||||
ALTER TABLE IF EXISTS public.provider_api_keys
|
||||
ALTER COLUMN request_count TYPE bigint USING COALESCE(request_count, 0)::bigint,
|
||||
ALTER COLUMN success_count TYPE bigint USING COALESCE(success_count, 0)::bigint,
|
||||
ALTER COLUMN error_count TYPE bigint USING COALESCE(error_count, 0)::bigint,
|
||||
ALTER COLUMN total_response_time_ms TYPE bigint USING COALESCE(total_response_time_ms, 0)::bigint;
|
||||
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE api_keys
|
||||
ADD COLUMN IF NOT EXISTS allowed_ips jsonb NULL;
|
||||
|
||||
ALTER TABLE api_keys
|
||||
ALTER COLUMN allowed_ips TYPE jsonb USING allowed_ips::jsonb;
|
||||
@@ -0,0 +1,63 @@
|
||||
ALTER TABLE public.users
|
||||
ADD COLUMN privacy_policy_accepted_version character varying(64),
|
||||
ADD COLUMN privacy_policy_accepted_at timestamp with time zone;
|
||||
|
||||
ALTER TABLE public.announcements
|
||||
ADD COLUMN requires_ack boolean NOT NULL DEFAULT false;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.user_invite_codes (
|
||||
user_id character varying(64) PRIMARY KEY REFERENCES public.users(id) ON DELETE CASCADE,
|
||||
invite_code character varying(64) NOT NULL UNIQUE,
|
||||
active boolean NOT NULL DEFAULT true,
|
||||
created_at timestamp with time zone NOT NULL DEFAULT NOW(),
|
||||
updated_at timestamp with time zone NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.user_referrals (
|
||||
id character varying(64) PRIMARY KEY,
|
||||
inviter_user_id character varying(64) NOT NULL REFERENCES public.users(id) ON DELETE CASCADE,
|
||||
invitee_user_id character varying(64) NOT NULL UNIQUE REFERENCES public.users(id) ON DELETE CASCADE,
|
||||
invite_code_snapshot character varying(64) NOT NULL,
|
||||
source_json jsonb,
|
||||
first_paid_order_id character varying(64) REFERENCES public.payment_orders(id) ON DELETE SET NULL,
|
||||
first_paid_at timestamp with time zone,
|
||||
created_at timestamp with time zone NOT NULL DEFAULT NOW(),
|
||||
updated_at timestamp with time zone NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_user_referrals_inviter
|
||||
ON public.user_referrals USING btree (inviter_user_id, created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_user_referrals_created
|
||||
ON public.user_referrals USING btree (created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_user_referrals_invite_code
|
||||
ON public.user_referrals USING btree (invite_code_snapshot);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.referral_rewards (
|
||||
id character varying(64) PRIMARY KEY,
|
||||
referral_id character varying(64) NOT NULL REFERENCES public.user_referrals(id) ON DELETE CASCADE,
|
||||
inviter_user_id character varying(64) NOT NULL REFERENCES public.users(id) ON DELETE CASCADE,
|
||||
invitee_user_id character varying(64) NOT NULL REFERENCES public.users(id) ON DELETE CASCADE,
|
||||
reward_type character varying(32) NOT NULL,
|
||||
trigger_point character varying(64) NOT NULL,
|
||||
source_order_id character varying(64) REFERENCES public.payment_orders(id) ON DELETE SET NULL,
|
||||
idempotency_key character varying(128) NOT NULL UNIQUE,
|
||||
amount_usd numeric(20,8) NOT NULL,
|
||||
status character varying(32) NOT NULL DEFAULT 'pending',
|
||||
wallet_transaction_id character varying(64),
|
||||
reversed_amount_usd numeric(20,8) NOT NULL DEFAULT 0,
|
||||
pending_reversal_amount_usd numeric(20,8) NOT NULL DEFAULT 0,
|
||||
failure_reason text,
|
||||
admin_operator_id character varying(64),
|
||||
admin_note text,
|
||||
created_at timestamp with time zone NOT NULL DEFAULT NOW(),
|
||||
updated_at timestamp with time zone NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_referral_rewards_inviter_status
|
||||
ON public.referral_rewards USING btree (inviter_user_id, status, created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_referral_rewards_inviter_created
|
||||
ON public.referral_rewards USING btree (inviter_user_id, created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_referral_rewards_created
|
||||
ON public.referral_rewards USING btree (created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_referral_rewards_source_order
|
||||
ON public.referral_rewards USING btree (source_order_id);
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE public.oauth_providers ADD COLUMN IF NOT EXISTS icon_url VARCHAR(500);
|
||||
@@ -0,0 +1,2 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_provider_api_keys_provider_default_sort
|
||||
ON public.provider_api_keys USING btree (provider_id, internal_priority, name, id);
|
||||
Reference in New Issue
Block a user