From c3a1fa23cf73dae52a3bf900a734caf094f9fa65 Mon Sep 17 00:00:00 2001 From: KubrickCode <126654223+KubrickCode@users.noreply.github.com> Date: Sun, 1 Feb 2026 10:13:26 +0000 Subject: [PATCH] docs: update schema documentation --- docs/schema/README.md | 11 +++ docs/schema/public.quota_reservations.md | 65 +++++++++++++ docs/schema/public.users.md | 30 ++++-- docs/schema/schema.json | 114 +++++++++++++++++++++++ 4 files changed, 210 insertions(+), 10 deletions(-) create mode 100644 docs/schema/public.quota_reservations.md diff --git a/docs/schema/README.md b/docs/schema/README.md index 449b60c..286f5a5 100644 --- a/docs/schema/README.md +++ b/docs/schema/README.md @@ -30,6 +30,7 @@ | [public.user_subscriptions](public.user_subscriptions.md) | 9 | | BASE TABLE | | [public.behavior_caches](public.behavior_caches.md) | 4 | | BASE TABLE | | [public.classification_caches](public.classification_caches.md) | 7 | | BASE TABLE | +| [public.quota_reservations](public.quota_reservations.md) | 7 | | BASE TABLE | ## Enums @@ -79,6 +80,7 @@ erDiagram "public.usage_events" }o--o| "public.spec_documents" : "FOREIGN KEY (document_id) REFERENCES spec_documents(id) ON DELETE SET NULL" "public.user_subscriptions" }o--|| "public.users" : "FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE" "public.user_subscriptions" }o--|| "public.subscription_plans" : "FOREIGN KEY (plan_id) REFERENCES subscription_plans(id) ON DELETE RESTRICT" +"public.quota_reservations" }o--|| "public.users" : "FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE" "atlas_schema_revisions.atlas_schema_revisions" { varchar version @@ -338,6 +340,15 @@ erDiagram jsonb test_index_map timestamp_with_time_zone created_at } +"public.quota_reservations" { + uuid id + uuid user_id FK + usage_event_type event_type + integer reserved_amount + bigint job_id + timestamp_with_time_zone expires_at + timestamp_with_time_zone created_at +} ``` --- diff --git a/docs/schema/public.quota_reservations.md b/docs/schema/public.quota_reservations.md new file mode 100644 index 0000000..c0727b4 --- /dev/null +++ b/docs/schema/public.quota_reservations.md @@ -0,0 +1,65 @@ +# public.quota_reservations + +## Description + +## Columns + +| Name | Type | Default | Nullable | Children | Parents | Comment | +| --------------- | ------------------------ | ------------------------------ | -------- | -------- | ------------------------------- | ------- | +| id | uuid | gen_random_uuid() | false | | | | +| user_id | uuid | | false | | [public.users](public.users.md) | | +| event_type | usage_event_type | | false | | | | +| reserved_amount | integer | | false | | | | +| job_id | bigint | | false | | | | +| expires_at | timestamp with time zone | (now() + '01:00:00'::interval) | false | | | | +| created_at | timestamp with time zone | now() | false | | | | + +## Constraints + +| Name | Type | Definition | +| ---------------------------- | ----------- | ------------------------------------------------------------ | +| chk_reserved_amount_positive | CHECK | CHECK ((reserved_amount > 0)) | +| fk_quota_reservations_user | FOREIGN KEY | FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE | +| quota_reservations_pkey | PRIMARY KEY | PRIMARY KEY (id) | +| uq_quota_reservations_job_id | UNIQUE | UNIQUE (job_id) | + +## Indexes + +| Name | Definition | +| --------------------------------- | ------------------------------------------------------------------------------------------------------------- | +| quota_reservations_pkey | CREATE UNIQUE INDEX quota_reservations_pkey ON public.quota_reservations USING btree (id) | +| uq_quota_reservations_job_id | CREATE UNIQUE INDEX uq_quota_reservations_job_id ON public.quota_reservations USING btree (job_id) | +| idx_quota_reservations_expires | CREATE INDEX idx_quota_reservations_expires ON public.quota_reservations USING btree (expires_at) | +| idx_quota_reservations_user_event | CREATE INDEX idx_quota_reservations_user_event ON public.quota_reservations USING btree (user_id, event_type) | + +## Relations + +```mermaid +erDiagram + +"public.quota_reservations" }o--|| "public.users" : "FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE" + +"public.quota_reservations" { + uuid id + uuid user_id FK + usage_event_type event_type + integer reserved_amount + bigint job_id + timestamp_with_time_zone expires_at + timestamp_with_time_zone created_at +} +"public.users" { + uuid id + varchar_255_ email + varchar_255_ username + text avatar_url + timestamp_with_time_zone last_login_at + timestamp_with_time_zone created_at + timestamp_with_time_zone updated_at + integer token_version +} +``` + +--- + +> Generated by [tbls](https://github.com/k1LoW/tbls) diff --git a/docs/schema/public.users.md b/docs/schema/public.users.md index 8442f5f..4ddc550 100644 --- a/docs/schema/public.users.md +++ b/docs/schema/public.users.md @@ -4,16 +4,16 @@ ## Columns -| Name | Type | Default | Nullable | Children | Parents | Comment | -| ------------- | ------------------------ | ----------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ------- | -| id | uuid | gen_random_uuid() | false | [public.oauth_accounts](public.oauth_accounts.md) [public.user_bookmarks](public.user_bookmarks.md) [public.user_analysis_history](public.user_analysis_history.md) [public.user_github_org_memberships](public.user_github_org_memberships.md) [public.user_github_repositories](public.user_github_repositories.md) [public.github_app_installations](public.github_app_installations.md) [public.refresh_tokens](public.refresh_tokens.md) [public.spec_documents](public.spec_documents.md) [public.user_specview_history](public.user_specview_history.md) [public.usage_events](public.usage_events.md) [public.user_subscriptions](public.user_subscriptions.md) | | | -| email | varchar(255) | | true | | | | -| username | varchar(255) | | false | | | | -| avatar_url | text | | true | | | | -| last_login_at | timestamp with time zone | | true | | | | -| created_at | timestamp with time zone | now() | false | | | | -| updated_at | timestamp with time zone | now() | false | | | | -| token_version | integer | 1 | false | | | | +| Name | Type | Default | Nullable | Children | Parents | Comment | +| ------------- | ------------------------ | ----------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ------- | +| id | uuid | gen_random_uuid() | false | [public.oauth_accounts](public.oauth_accounts.md) [public.user_bookmarks](public.user_bookmarks.md) [public.user_analysis_history](public.user_analysis_history.md) [public.user_github_org_memberships](public.user_github_org_memberships.md) [public.user_github_repositories](public.user_github_repositories.md) [public.github_app_installations](public.github_app_installations.md) [public.refresh_tokens](public.refresh_tokens.md) [public.spec_documents](public.spec_documents.md) [public.user_specview_history](public.user_specview_history.md) [public.usage_events](public.usage_events.md) [public.user_subscriptions](public.user_subscriptions.md) [public.quota_reservations](public.quota_reservations.md) | | | +| email | varchar(255) | | true | | | | +| username | varchar(255) | | false | | | | +| avatar_url | text | | true | | | | +| last_login_at | timestamp with time zone | | true | | | | +| created_at | timestamp with time zone | now() | false | | | | +| updated_at | timestamp with time zone | now() | false | | | | +| token_version | integer | 1 | false | | | | ## Constraints @@ -45,6 +45,7 @@ erDiagram "public.user_specview_history" }o--|| "public.users" : "FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE" "public.usage_events" }o--|| "public.users" : "FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE" "public.user_subscriptions" }o--|| "public.users" : "FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE" +"public.quota_reservations" }o--|| "public.users" : "FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE" "public.users" { uuid id @@ -171,6 +172,15 @@ erDiagram timestamp_with_time_zone created_at timestamp_with_time_zone updated_at } +"public.quota_reservations" { + uuid id + uuid user_id FK + usage_event_type event_type + integer reserved_amount + bigint job_id + timestamp_with_time_zone expires_at + timestamp_with_time_zone created_at +} ``` --- diff --git a/docs/schema/schema.json b/docs/schema/schema.json index 760e14b..beac2eb 100644 --- a/docs/schema/schema.json +++ b/docs/schema/schema.json @@ -2546,6 +2546,111 @@ "columns": ["content_hash", "language", "model_id"] } ] + }, + { + "name": "public.quota_reservations", + "type": "BASE TABLE", + "columns": [ + { + "name": "id", + "type": "uuid", + "nullable": false, + "default": "gen_random_uuid()" + }, + { + "name": "user_id", + "type": "uuid", + "nullable": false + }, + { + "name": "event_type", + "type": "usage_event_type", + "nullable": false + }, + { + "name": "reserved_amount", + "type": "integer", + "nullable": false + }, + { + "name": "job_id", + "type": "bigint", + "nullable": false + }, + { + "name": "expires_at", + "type": "timestamp with time zone", + "nullable": false, + "default": "(now() + '01:00:00'::interval)" + }, + { + "name": "created_at", + "type": "timestamp with time zone", + "nullable": false, + "default": "now()" + } + ], + "indexes": [ + { + "name": "quota_reservations_pkey", + "def": "CREATE UNIQUE INDEX quota_reservations_pkey ON public.quota_reservations USING btree (id)", + "table": "public.quota_reservations", + "columns": ["id"] + }, + { + "name": "uq_quota_reservations_job_id", + "def": "CREATE UNIQUE INDEX uq_quota_reservations_job_id ON public.quota_reservations USING btree (job_id)", + "table": "public.quota_reservations", + "columns": ["job_id"] + }, + { + "name": "idx_quota_reservations_expires", + "def": "CREATE INDEX idx_quota_reservations_expires ON public.quota_reservations USING btree (expires_at)", + "table": "public.quota_reservations", + "columns": ["expires_at"] + }, + { + "name": "idx_quota_reservations_user_event", + "def": "CREATE INDEX idx_quota_reservations_user_event ON public.quota_reservations USING btree (user_id, event_type)", + "table": "public.quota_reservations", + "columns": ["user_id", "event_type"] + } + ], + "constraints": [ + { + "name": "chk_reserved_amount_positive", + "type": "CHECK", + "def": "CHECK ((reserved_amount \u003e 0))", + "table": "public.quota_reservations", + "referenced_table": "", + "columns": ["reserved_amount"] + }, + { + "name": "fk_quota_reservations_user", + "type": "FOREIGN KEY", + "def": "FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE", + "table": "public.quota_reservations", + "referenced_table": "users", + "columns": ["user_id"], + "referenced_columns": ["id"] + }, + { + "name": "quota_reservations_pkey", + "type": "PRIMARY KEY", + "def": "PRIMARY KEY (id)", + "table": "public.quota_reservations", + "referenced_table": "", + "columns": ["id"] + }, + { + "name": "uq_quota_reservations_job_id", + "type": "UNIQUE", + "def": "UNIQUE (job_id)", + "table": "public.quota_reservations", + "referenced_table": "", + "columns": ["job_id"] + } + ] } ], "relations": [ @@ -2818,6 +2923,15 @@ "parent_columns": ["id"], "parent_cardinality": "exactly_one", "def": "FOREIGN KEY (plan_id) REFERENCES subscription_plans(id) ON DELETE RESTRICT" + }, + { + "table": "public.quota_reservations", + "columns": ["user_id"], + "cardinality": "zero_or_more", + "parent_table": "public.users", + "parent_columns": ["id"], + "parent_cardinality": "exactly_one", + "def": "FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE" } ], "enums": [