Create Ai::ActiveContext::Code tables
What does this MR do and why?
Adds two tables for ActiveContext: Ai::ActiveContext::Code::EnabledNamspace and Ai::ActiveContext::Code::Repository.
enabled_namespaces is a reference to namespace and exists only for namespaces that have Duo licenses. An enabled_namespace has many repositories. A repository represents (and references) a project that has to be indexed.
These records belong to a connection. If a new connection is created, the old enabled_namespaces and repositories records will be cleaned up.
Both tables are partitioned:
-
enabled_namespacesis partitioned bynamespace_idwhich will be a root namespace id -
repositoriesis partitioned byproject_idwhich is non-nullable
The following references exist:
-
enabled_namespacesis ongitlab_main_celland sharded bynamespaces -
repositoriesis ongitlab_main_cell_local -
connection(existing table) is ongitlab_main_cell_local
Schema
EnabledNamespace
Partitioned table "public.p_ai_active_context_code_enabled_namespaces"
Column | Type | Collation | Nullable | Default
---------------+--------------------------+-----------+----------+-------------------------------------------------------------------------
id | bigint | | not null | nextval('p_ai_active_context_code_enabled_namespaces_id_seq'::regclass)
namespace_id | bigint | | not null |
connection_id | bigint | | not null |
metadata | jsonb | | not null | '{}'::jsonb
state | smallint | | not null | 0
created_at | timestamp with time zone | | not null |
updated_at | timestamp with time zone | | not null |
Partition key: RANGE (namespace_id)
Indexes:
"p_ai_active_context_code_enabled_namespaces_pkey" PRIMARY KEY, btree (id, namespace_id)
"idx_ai_active_context_code_enabled_namespaces_namespace_id" btree (namespace_id)
"idx_unique_ai_code_repository_connection_namespace_id" UNIQUE, btree (connection_id, namespace_id)
Foreign-key constraints:
"fk_rails_42b1b86224" FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE
Triggers:
p_ai_active_context_code_enabled_namespaces_loose_fk_trigger AFTER DELETE ON p_ai_active_context_code_enabled_namespaces REFERENCING OLD TABLE AS old_table FOR EACH STATEMENT EXECUTE FUNCTION insert_into_loose_foreign_keys_deleted_records()
Number of partitions: 7 (Use \d+ to list them.)
Repository
Partitioned table "public.p_ai_active_context_code_repositories"
Column | Type | Collation | Nullable | Default
----------------------+--------------------------+-----------+----------+-------------------------------------------------------------------
id | bigint | | not null | nextval('p_ai_active_context_code_repositories_id_seq'::regclass)
project_id | bigint | | not null |
connection_id | bigint | | |
enabled_namespace_id | bigint | | |
metadata | jsonb | | not null | '{}'::jsonb
last_commit | text | | |
state | smallint | | not null | 0
indexed_at | timestamp with time zone | | |
created_at | timestamp with time zone | | not null |
updated_at | timestamp with time zone | | not null |
Partition key: RANGE (project_id)
Indexes:
"p_ai_active_context_code_repositories_pkey" PRIMARY KEY, btree (id, project_id)
"idx_ai_code_repository_project_id_state" btree (project_id, state)
"idx_p_ai_active_context_code_repositories_enabled_namespace_id" btree (enabled_namespace_id)
"idx_unique_ai_code_repository_connection_project_id" UNIQUE, btree (connection_id, project_id)
Check constraints:
"check_b253d453c7" CHECK (char_length(last_commit) <= 64)
Foreign-key constraints:
"fk_rails_b3d72d06cf" FOREIGN KEY (connection_id) REFERENCES ai_active_context_connections(id) ON DELETE SET NULL
Number of partitions: 7 (Use \d+ to list them.)
References
- [Index state tracking] Create tables for tracki... (#536221 - closed)
- Similar MR: Add knowledge graph tables (!191162 - merged)
- https://docs.gitlab.com/development/database/partitioning/int_range/
- https://docs.gitlab.com/development/database/loose_foreign_keys
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #536221 (closed)
Edited by Madelein van Niekerk
