zed/crates/collab/migrations_llm/20240806213401_create_usages.sql
Marshall Bowers a54e16b7ea
collab: Add usages table to LLM database (#15884)
This PR adds a `usages` table to the LLM database.

We'll use this to track usage for rate-limiting purposes.

Release Notes:

- N/A
2024-08-06 18:40:10 -04:00

15 lines
663 B
SQL

create table if not exists usages (
id serial primary key,
user_id integer not null,
model_id integer not null references models (id) on delete cascade,
requests_this_minute integer not null default 0,
tokens_this_minute bigint not null default 0,
requests_this_day integer not null default 0,
tokens_this_day bigint not null default 0,
requests_this_month integer not null default 0,
tokens_this_month bigint not null default 0
);
create index ix_usages_on_user_id on usages (user_id);
create index ix_usages_on_model_id on usages (model_id);
create unique index uix_usages_on_user_id_model_id on usages (user_id, model_id);