Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20240104191802_migrate_zoekt_indexed_namespaces_to_zoekt_indices.rb')
-rw-r--r--db/migrate/20240104191802_migrate_zoekt_indexed_namespaces_to_zoekt_indices.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/db/migrate/20240104191802_migrate_zoekt_indexed_namespaces_to_zoekt_indices.rb b/db/migrate/20240104191802_migrate_zoekt_indexed_namespaces_to_zoekt_indices.rb
new file mode 100644
index 00000000000..5461ad5094b
--- /dev/null
+++ b/db/migrate/20240104191802_migrate_zoekt_indexed_namespaces_to_zoekt_indices.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+class MigrateZoektIndexedNamespacesToZoektIndices < Gitlab::Database::Migration[2.2]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ milestone '16.8'
+
+ INSERTED_COLUMNS = %w[
+ zoekt_enabled_namespace_id
+ namespace_id
+ zoekt_node_id
+ state
+ created_at
+ updated_at
+ ].join(',')
+
+ STATE_READY = 10
+
+ def up
+ connection.execute(<<~SQL)
+ WITH indexed_namespaces AS (
+ (SELECT DISTINCT ON (namespace_id) namespace_id, search, zoekt_node_id
+ FROM zoekt_indexed_namespaces ORDER BY namespace_id, search)
+ )
+
+ INSERT INTO zoekt_indices (#{INSERTED_COLUMNS})
+ SELECT
+ zoekt_enabled_namespaces.id,
+ indexed_namespaces.namespace_id,
+ indexed_namespaces.zoekt_node_id,
+ #{STATE_READY},
+ NOW(),
+ NOW()
+ FROM zoekt_enabled_namespaces
+ JOIN indexed_namespaces ON indexed_namespaces.namespace_id = zoekt_enabled_namespaces.root_namespace_id
+ SQL
+ end
+
+ def down
+ connection.execute(<<~SQL)
+ DELETE FROM zoekt_indices
+ SQL
+ end
+end