diff --git a/docs/schema/README.md b/docs/schema/README.md index 286f5a5..a5af1d4 100644 --- a/docs/schema/README.md +++ b/docs/schema/README.md @@ -12,7 +12,7 @@ | [public.users](public.users.md) | 8 | | BASE TABLE | | [public.oauth_accounts](public.oauth_accounts.md) | 9 | | BASE TABLE | | [public.user_bookmarks](public.user_bookmarks.md) | 4 | | BASE TABLE | -| [public.user_analysis_history](public.user_analysis_history.md) | 5 | | BASE TABLE | +| [public.user_analysis_history](public.user_analysis_history.md) | 6 | | BASE TABLE | | [public.github_organizations](public.github_organizations.md) | 8 | | BASE TABLE | | [public.user_github_org_memberships](public.user_github_org_memberships.md) | 6 | | BASE TABLE | | [public.user_github_repositories](public.user_github_repositories.md) | 20 | | BASE TABLE | @@ -20,7 +20,7 @@ | [public.refresh_tokens](public.refresh_tokens.md) | 8 | | BASE TABLE | | [public.test_files](public.test_files.md) | 5 | | BASE TABLE | | [public.system_config](public.system_config.md) | 3 | | BASE TABLE | -| [public.spec_documents](public.spec_documents.md) | 10 | | BASE TABLE | +| [public.spec_documents](public.spec_documents.md) | 11 | | BASE TABLE | | [public.spec_domains](public.spec_domains.md) | 8 | | BASE TABLE | | [public.spec_features](public.spec_features.md) | 7 | | BASE TABLE | | [public.spec_behaviors](public.spec_behaviors.md) | 7 | | BASE TABLE | @@ -174,6 +174,7 @@ erDiagram timestamp_with_time_zone created_at timestamp_with_time_zone updated_at uuid id + integer retention_days_at_creation } "public.github_organizations" { uuid id @@ -260,6 +261,7 @@ erDiagram timestamp_with_time_zone updated_at integer version uuid user_id FK + integer retention_days_at_creation } "public.spec_domains" { uuid id diff --git a/docs/schema/public.analyses.md b/docs/schema/public.analyses.md index 331cbcf..554c2e8 100644 --- a/docs/schema/public.analyses.md +++ b/docs/schema/public.analyses.md @@ -68,6 +68,7 @@ erDiagram timestamp_with_time_zone created_at timestamp_with_time_zone updated_at uuid id + integer retention_days_at_creation } "public.test_files" { uuid id @@ -87,6 +88,7 @@ erDiagram timestamp_with_time_zone updated_at integer version uuid user_id FK + integer retention_days_at_creation } "public.usage_events" { uuid id diff --git a/docs/schema/public.spec_documents.md b/docs/schema/public.spec_documents.md index c1d706d..b78a7a3 100644 --- a/docs/schema/public.spec_documents.md +++ b/docs/schema/public.spec_documents.md @@ -4,28 +4,30 @@ ## Columns -| Name | Type | Default | Nullable | Children | Parents | Comment | -| ----------------- | ------------------------ | ----------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | ------- | -| id | uuid | gen_random_uuid() | false | [public.spec_domains](public.spec_domains.md) [public.user_specview_history](public.user_specview_history.md) [public.usage_events](public.usage_events.md) | | | -| analysis_id | uuid | | false | | [public.analyses](public.analyses.md) | | -| content_hash | bytea | | false | | | | -| language | varchar(10) | 'en'::character varying | false | | | | -| executive_summary | text | | true | | | | -| model_id | varchar(100) | | false | | | | -| created_at | timestamp with time zone | now() | false | | | | -| updated_at | timestamp with time zone | now() | false | | | | -| version | integer | 1 | false | | | | -| user_id | uuid | | false | | [public.users](public.users.md) | | +| Name | Type | Default | Nullable | Children | Parents | Comment | +| -------------------------- | ------------------------ | ----------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | ------- | +| id | uuid | gen_random_uuid() | false | [public.spec_domains](public.spec_domains.md) [public.user_specview_history](public.user_specview_history.md) [public.usage_events](public.usage_events.md) | | | +| analysis_id | uuid | | false | | [public.analyses](public.analyses.md) | | +| content_hash | bytea | | false | | | | +| language | varchar(10) | 'en'::character varying | false | | | | +| executive_summary | text | | true | | | | +| model_id | varchar(100) | | false | | | | +| created_at | timestamp with time zone | now() | false | | | | +| updated_at | timestamp with time zone | now() | false | | | | +| version | integer | 1 | false | | | | +| user_id | uuid | | false | | [public.users](public.users.md) | | +| retention_days_at_creation | integer | | true | | | | ## Constraints -| Name | Type | Definition | -| ---------------------------------------------- | ----------- | ------------------------------------------------------------------- | -| fk_spec_documents_analysis | FOREIGN KEY | FOREIGN KEY (analysis_id) REFERENCES analyses(id) ON DELETE CASCADE | -| fk_spec_documents_user | FOREIGN KEY | FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE | -| spec_documents_pkey | PRIMARY KEY | PRIMARY KEY (id) | -| uq_spec_documents_user_analysis_lang_version | UNIQUE | UNIQUE (user_id, analysis_id, language, version) | -| uq_spec_documents_user_hash_lang_model_version | UNIQUE | UNIQUE (user_id, content_hash, language, model_id, version) | +| Name | Type | Definition | +| ---------------------------------------------- | ----------- | ---------------------------------------------------------------------------------- | +| chk_retention_days_positive | CHECK | CHECK (((retention_days_at_creation IS NULL) OR (retention_days_at_creation > 0))) | +| fk_spec_documents_analysis | FOREIGN KEY | FOREIGN KEY (analysis_id) REFERENCES analyses(id) ON DELETE CASCADE | +| fk_spec_documents_user | FOREIGN KEY | FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE | +| spec_documents_pkey | PRIMARY KEY | PRIMARY KEY (id) | +| uq_spec_documents_user_analysis_lang_version | UNIQUE | UNIQUE (user_id, analysis_id, language, version) | +| uq_spec_documents_user_hash_lang_model_version | UNIQUE | UNIQUE (user_id, content_hash, language, model_id, version) | ## Indexes @@ -37,6 +39,7 @@ | uq_spec_documents_user_hash_lang_model_version | CREATE UNIQUE INDEX uq_spec_documents_user_hash_lang_model_version ON public.spec_documents USING btree (user_id, content_hash, language, model_id, version) | | idx_spec_documents_user_created | CREATE INDEX idx_spec_documents_user_created ON public.spec_documents USING btree (user_id, created_at) | | idx_spec_documents_content_hash_lang_model | CREATE INDEX idx_spec_documents_content_hash_lang_model ON public.spec_documents USING btree (content_hash, language, model_id) | +| idx_spec_documents_retention_cleanup | CREATE INDEX idx_spec_documents_retention_cleanup ON public.spec_documents USING btree (created_at) WHERE (retention_days_at_creation IS NOT NULL) | ## Relations @@ -60,6 +63,7 @@ erDiagram timestamp_with_time_zone updated_at integer version uuid user_id FK + integer retention_days_at_creation } "public.spec_domains" { uuid id diff --git a/docs/schema/public.spec_domains.md b/docs/schema/public.spec_domains.md index c3d94b3..27a928f 100644 --- a/docs/schema/public.spec_domains.md +++ b/docs/schema/public.spec_domains.md @@ -67,6 +67,7 @@ erDiagram timestamp_with_time_zone updated_at integer version uuid user_id FK + integer retention_days_at_creation } ``` diff --git a/docs/schema/public.usage_events.md b/docs/schema/public.usage_events.md index 904d476..c55c289 100644 --- a/docs/schema/public.usage_events.md +++ b/docs/schema/public.usage_events.md @@ -87,6 +87,7 @@ erDiagram timestamp_with_time_zone updated_at integer version uuid user_id FK + integer retention_days_at_creation } ``` diff --git a/docs/schema/public.user_analysis_history.md b/docs/schema/public.user_analysis_history.md index a81f821..776a775 100644 --- a/docs/schema/public.user_analysis_history.md +++ b/docs/schema/public.user_analysis_history.md @@ -4,31 +4,34 @@ ## Columns -| Name | Type | Default | Nullable | Children | Parents | Comment | -| ----------- | ------------------------ | ----------------- | -------- | -------- | ------------------------------------- | ------- | -| user_id | uuid | | false | | [public.users](public.users.md) | | -| analysis_id | uuid | | false | | [public.analyses](public.analyses.md) | | -| created_at | timestamp with time zone | now() | false | | | | -| updated_at | timestamp with time zone | now() | false | | | | -| id | uuid | gen_random_uuid() | false | | | | +| Name | Type | Default | Nullable | Children | Parents | Comment | +| -------------------------- | ------------------------ | ----------------- | -------- | -------- | ------------------------------------- | ------- | +| user_id | uuid | | false | | [public.users](public.users.md) | | +| analysis_id | uuid | | false | | [public.analyses](public.analyses.md) | | +| created_at | timestamp with time zone | now() | false | | | | +| updated_at | timestamp with time zone | now() | false | | | | +| id | uuid | gen_random_uuid() | false | | | | +| retention_days_at_creation | integer | | true | | | | ## Constraints -| Name | Type | Definition | -| -------------------------------------- | ----------- | ------------------------------------------------------------------- | -| fk_user_analysis_history_analysis | FOREIGN KEY | FOREIGN KEY (analysis_id) REFERENCES analyses(id) ON DELETE CASCADE | -| fk_user_analysis_history_user | FOREIGN KEY | FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE | -| user_analysis_history_pkey | PRIMARY KEY | PRIMARY KEY (id) | -| uq_user_analysis_history_user_analysis | UNIQUE | UNIQUE (user_id, analysis_id) | +| Name | Type | Definition | +| -------------------------------------- | ----------- | ---------------------------------------------------------------------------------- | +| chk_retention_days_positive | CHECK | CHECK (((retention_days_at_creation IS NULL) OR (retention_days_at_creation > 0))) | +| fk_user_analysis_history_analysis | FOREIGN KEY | FOREIGN KEY (analysis_id) REFERENCES analyses(id) ON DELETE CASCADE | +| fk_user_analysis_history_user | FOREIGN KEY | FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE | +| user_analysis_history_pkey | PRIMARY KEY | PRIMARY KEY (id) | +| uq_user_analysis_history_user_analysis | UNIQUE | UNIQUE (user_id, analysis_id) | ## Indexes -| Name | Definition | -| -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -| idx_user_analysis_history_analysis | CREATE INDEX idx_user_analysis_history_analysis ON public.user_analysis_history USING btree (analysis_id) | -| user_analysis_history_pkey | CREATE UNIQUE INDEX user_analysis_history_pkey ON public.user_analysis_history USING btree (id) | -| uq_user_analysis_history_user_analysis | CREATE UNIQUE INDEX uq_user_analysis_history_user_analysis ON public.user_analysis_history USING btree (user_id, analysis_id) | -| idx_user_analysis_history_cursor | CREATE INDEX idx_user_analysis_history_cursor ON public.user_analysis_history USING btree (user_id, updated_at, id) | +| Name | Definition | +| ------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| idx_user_analysis_history_analysis | CREATE INDEX idx_user_analysis_history_analysis ON public.user_analysis_history USING btree (analysis_id) | +| user_analysis_history_pkey | CREATE UNIQUE INDEX user_analysis_history_pkey ON public.user_analysis_history USING btree (id) | +| uq_user_analysis_history_user_analysis | CREATE UNIQUE INDEX uq_user_analysis_history_user_analysis ON public.user_analysis_history USING btree (user_id, analysis_id) | +| idx_user_analysis_history_cursor | CREATE INDEX idx_user_analysis_history_cursor ON public.user_analysis_history USING btree (user_id, updated_at, id) | +| idx_user_analysis_history_retention_cleanup | CREATE INDEX idx_user_analysis_history_retention_cleanup ON public.user_analysis_history USING btree (created_at) WHERE (retention_days_at_creation IS NOT NULL) | ## Relations @@ -44,6 +47,7 @@ erDiagram timestamp_with_time_zone created_at timestamp_with_time_zone updated_at uuid id + integer retention_days_at_creation } "public.users" { uuid id diff --git a/docs/schema/public.user_specview_history.md b/docs/schema/public.user_specview_history.md index 7cf6876..601ad02 100644 --- a/docs/schema/public.user_specview_history.md +++ b/docs/schema/public.user_specview_history.md @@ -66,6 +66,7 @@ erDiagram timestamp_with_time_zone updated_at integer version uuid user_id FK + integer retention_days_at_creation } ``` diff --git a/docs/schema/public.users.md b/docs/schema/public.users.md index 4ddc550..02f2688 100644 --- a/docs/schema/public.users.md +++ b/docs/schema/public.users.md @@ -80,6 +80,7 @@ erDiagram timestamp_with_time_zone created_at timestamp_with_time_zone updated_at uuid id + integer retention_days_at_creation } "public.user_github_org_memberships" { uuid id @@ -144,6 +145,7 @@ erDiagram timestamp_with_time_zone updated_at integer version uuid user_id FK + integer retention_days_at_creation } "public.user_specview_history" { uuid id diff --git a/docs/schema/schema.json b/docs/schema/schema.json index beac2eb..9e834a3 100644 --- a/docs/schema/schema.json +++ b/docs/schema/schema.json @@ -804,6 +804,11 @@ "type": "uuid", "nullable": false, "default": "gen_random_uuid()" + }, + { + "name": "retention_days_at_creation", + "type": "integer", + "nullable": true } ], "indexes": [ @@ -830,9 +835,23 @@ "def": "CREATE INDEX idx_user_analysis_history_cursor ON public.user_analysis_history USING btree (user_id, updated_at, id)", "table": "public.user_analysis_history", "columns": ["user_id", "updated_at", "id"] + }, + { + "name": "idx_user_analysis_history_retention_cleanup", + "def": "CREATE INDEX idx_user_analysis_history_retention_cleanup ON public.user_analysis_history USING btree (created_at) WHERE (retention_days_at_creation IS NOT NULL)", + "table": "public.user_analysis_history", + "columns": ["created_at"] } ], "constraints": [ + { + "name": "chk_retention_days_positive", + "type": "CHECK", + "def": "CHECK (((retention_days_at_creation IS NULL) OR (retention_days_at_creation \u003e 0)))", + "table": "public.user_analysis_history", + "referenced_table": "", + "columns": ["retention_days_at_creation"] + }, { "name": "fk_user_analysis_history_analysis", "type": "FOREIGN KEY", @@ -1660,6 +1679,11 @@ "name": "user_id", "type": "uuid", "nullable": false + }, + { + "name": "retention_days_at_creation", + "type": "integer", + "nullable": true } ], "indexes": [ @@ -1698,9 +1722,23 @@ "def": "CREATE INDEX idx_spec_documents_content_hash_lang_model ON public.spec_documents USING btree (content_hash, language, model_id)", "table": "public.spec_documents", "columns": ["content_hash", "language", "model_id"] + }, + { + "name": "idx_spec_documents_retention_cleanup", + "def": "CREATE INDEX idx_spec_documents_retention_cleanup ON public.spec_documents USING btree (created_at) WHERE (retention_days_at_creation IS NOT NULL)", + "table": "public.spec_documents", + "columns": ["created_at"] } ], "constraints": [ + { + "name": "chk_retention_days_positive", + "type": "CHECK", + "def": "CHECK (((retention_days_at_creation IS NULL) OR (retention_days_at_creation \u003e 0)))", + "table": "public.spec_documents", + "referenced_table": "", + "columns": ["retention_days_at_creation"] + }, { "name": "fk_spec_documents_analysis", "type": "FOREIGN KEY",