From ed79e980d15db506b2ba89a80de73978e888e05f Mon Sep 17 00:00:00 2001
From: Krasimir Angelov <kangelov@gitlab.com>
Date: Wed, 30 Aug 2023 12:29:42 +0300
Subject: [PATCH] Revert "Merge branch
 '421483-update-product-analytics-cluster-settings-fields' into 'master'"

https://gitlab.com/gitlab-com/gl-infra/production/-/issues/16274

Make db/post_migrate/20230822195852_remove_pa_jitsu_related_settings.rb
a no-op.

This reverts commit 380bb17bde22aac88aa61611d57095bb898cd0a2, reversing
changes made to 061f8fe362065e939ab5a9c2d444afaa5d1b14af.

[skip-db-structure-check]
---
 ...195852_remove_pa_jitsu_related_settings.rb | 57 ++-----------------
 db/structure.sql                              | 24 +++++++-
 spec/requests/api/project_attributes.yml      | 10 ++++
 3 files changed, 37 insertions(+), 54 deletions(-)

diff --git a/db/post_migrate/20230822195852_remove_pa_jitsu_related_settings.rb b/db/post_migrate/20230822195852_remove_pa_jitsu_related_settings.rb
index 0f76ba20ad6df..9d36cbac956b8 100644
--- a/db/post_migrate/20230822195852_remove_pa_jitsu_related_settings.rb
+++ b/db/post_migrate/20230822195852_remove_pa_jitsu_related_settings.rb
@@ -1,62 +1,13 @@
 # frozen_string_literal: true
 
 class RemovePaJitsuRelatedSettings < Gitlab::Database::Migration[2.1]
-  disable_ddl_transaction!
-
   def up
-    remove_column :application_settings, :encrypted_product_analytics_clickhouse_connection_string, if_exists: true
-    remove_column :application_settings, :encrypted_product_analytics_clickhouse_connection_string_iv, if_exists: true
-    remove_column :application_settings, :encrypted_jitsu_administrator_password, if_exists: true
-    remove_column :application_settings, :encrypted_jitsu_administrator_password_iv, if_exists: true
-    remove_column :application_settings, :jitsu_host, if_exists: true
-    remove_column :application_settings, :jitsu_project_xid, if_exists: true
-    remove_column :application_settings, :jitsu_administrator_email, if_exists: true
-
-    remove_column :project_settings, :encrypted_product_analytics_clickhouse_connection_string, if_exists: true
-    remove_column :project_settings, :encrypted_product_analytics_clickhouse_connection_string_iv, if_exists: true
-    remove_column :project_settings, :encrypted_jitsu_administrator_password, if_exists: true
-    remove_column :project_settings, :encrypted_jitsu_administrator_password_iv, if_exists: true
-    remove_column :project_settings, :jitsu_key, if_exists: true
-    remove_column :project_settings, :jitsu_host, if_exists: true
-    remove_column :project_settings, :jitsu_project_xid, if_exists: true
-    remove_column :project_settings, :jitsu_administrator_email, if_exists: true
+    # Changed to a no-op, this migration was reverted after
+    # an incident during a deploy to staging.gitlab.com
+    # https://gitlab.com/gitlab-com/gl-infra/production/-/issues/16274
   end
 
   def down
-    add_column :application_settings, :encrypted_product_analytics_clickhouse_connection_string,
-      :binary, if_not_exists: true
-    add_column :application_settings, :encrypted_product_analytics_clickhouse_connection_string_iv,
-      :binary, if_not_exists: true
-    add_column :application_settings, :encrypted_jitsu_administrator_password,
-      :binary, if_not_exists: true
-    add_column :application_settings, :encrypted_jitsu_administrator_password_iv,
-      :binary, if_not_exists: true
-
-    add_column :application_settings, :jitsu_host, :text, if_not_exists: true
-    add_column :application_settings, :jitsu_project_xid, :text, if_not_exists: true
-    add_column :application_settings, :jitsu_administrator_email, :text, if_not_exists: true
-
-    add_column :project_settings, :encrypted_product_analytics_clickhouse_connection_string,
-      :binary, if_not_exists: true
-    add_column :project_settings, :encrypted_product_analytics_clickhouse_connection_string_iv,
-      :binary, if_not_exists: true
-    add_column :project_settings, :encrypted_jitsu_administrator_password,
-      :binary, if_not_exists: true
-    add_column :project_settings, :encrypted_jitsu_administrator_password_iv,
-      :binary, if_not_exists: true
-
-    add_column :project_settings, :jitsu_key, :text
-    add_column :project_settings, :jitsu_host, :text, if_not_exists: true
-    add_column :project_settings, :jitsu_project_xid, :text, if_not_exists: true
-    add_column :project_settings, :jitsu_administrator_email, :text, if_not_exists: true
-
-    add_text_limit :application_settings, :jitsu_host, 255
-    add_text_limit :application_settings, :jitsu_project_xid, 255
-    add_text_limit :application_settings, :jitsu_administrator_email, 255
-
-    add_text_limit :project_settings, :jitsu_key, 100
-    add_text_limit :project_settings, :jitsu_host, 255
-    add_text_limit :project_settings, :jitsu_project_xid, 255
-    add_text_limit :project_settings, :jitsu_administrator_email, 255
+    # no-op
   end
 end
diff --git a/db/structure.sql b/db/structure.sql
index c453e9bb25f59..c873f8b9f1be1 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -11842,6 +11842,11 @@ CREATE TABLE application_settings (
     cube_api_base_url text,
     encrypted_cube_api_key bytea,
     encrypted_cube_api_key_iv bytea,
+    jitsu_host text,
+    jitsu_project_xid text,
+    jitsu_administrator_email text,
+    encrypted_jitsu_administrator_password bytea,
+    encrypted_jitsu_administrator_password_iv bytea,
     dashboard_limit_enabled boolean DEFAULT false NOT NULL,
     dashboard_limit integer DEFAULT 0 NOT NULL,
     can_create_group boolean DEFAULT true NOT NULL,
@@ -11868,6 +11873,8 @@ CREATE TABLE application_settings (
     user_defaults_to_private_profile boolean DEFAULT false NOT NULL,
     allow_possible_spam boolean DEFAULT false NOT NULL,
     default_syntax_highlighting_theme integer DEFAULT 1 NOT NULL,
+    encrypted_product_analytics_clickhouse_connection_string bytea,
+    encrypted_product_analytics_clickhouse_connection_string_iv bytea,
     search_max_shard_size_gb integer DEFAULT 50 NOT NULL,
     search_max_docs_denominator integer DEFAULT 5000000 NOT NULL,
     search_min_docs_before_rollover integer DEFAULT 100000 NOT NULL,
@@ -11973,12 +11980,15 @@ CREATE TABLE application_settings (
     CONSTRAINT check_b8c74ea5b3 CHECK ((char_length(deactivation_email_additional_text) <= 1000)),
     CONSTRAINT check_d03919528d CHECK ((char_length(container_registry_vendor) <= 255)),
     CONSTRAINT check_d820146492 CHECK ((char_length(spam_check_endpoint_url) <= 255)),
+    CONSTRAINT check_dea8792229 CHECK ((char_length(jitsu_host) <= 255)),
     CONSTRAINT check_e2692d7523 CHECK ((char_length(default_preferred_language) <= 32)),
     CONSTRAINT check_e2dd6e290a CHECK ((char_length(jira_connect_application_key) <= 255)),
     CONSTRAINT check_e5024c8801 CHECK ((char_length(elasticsearch_username) <= 255)),
     CONSTRAINT check_e5aba18f02 CHECK ((char_length(container_registry_version) <= 255)),
+    CONSTRAINT check_ec3ca9aa8d CHECK ((char_length(jitsu_administrator_email) <= 255)),
     CONSTRAINT check_ef6176834f CHECK ((char_length(encrypted_cloud_license_auth_token_iv) <= 255)),
-    CONSTRAINT check_f6563bc000 CHECK ((char_length(arkose_labs_verify_api_url) <= 255))
+    CONSTRAINT check_f6563bc000 CHECK ((char_length(arkose_labs_verify_api_url) <= 255)),
+    CONSTRAINT check_fc732c181e CHECK ((char_length(jitsu_project_xid) <= 255))
 );
 
 COMMENT ON COLUMN application_settings.content_validation_endpoint_url IS 'JiHu-specific column';
@@ -21618,6 +21628,7 @@ CREATE TABLE project_settings (
     selective_code_owner_removals boolean DEFAULT false NOT NULL,
     issue_branch_template text,
     show_diff_preview_in_email boolean DEFAULT true NOT NULL,
+    jitsu_key text,
     suggested_reviewers_enabled boolean DEFAULT false NOT NULL,
     only_allow_merge_if_all_status_checks_passed boolean DEFAULT false NOT NULL,
     mirror_branch_regex text,
@@ -21627,7 +21638,14 @@ CREATE TABLE project_settings (
     pages_unique_domain text,
     runner_registration_enabled boolean DEFAULT true,
     product_analytics_instrumentation_key text,
+    jitsu_host text,
+    jitsu_project_xid text,
+    jitsu_administrator_email text,
+    encrypted_jitsu_administrator_password bytea,
+    encrypted_jitsu_administrator_password_iv bytea,
     product_analytics_data_collector_host text,
+    encrypted_product_analytics_clickhouse_connection_string bytea,
+    encrypted_product_analytics_clickhouse_connection_string_iv bytea,
     cube_api_base_url text,
     encrypted_cube_api_key bytea,
     encrypted_cube_api_key_iv bytea,
@@ -21635,6 +21653,7 @@ CREATE TABLE project_settings (
     encrypted_product_analytics_configurator_connection_string_iv bytea,
     pages_multiple_versions_enabled boolean DEFAULT false NOT NULL,
     CONSTRAINT check_1a30456322 CHECK ((char_length(pages_unique_domain) <= 63)),
+    CONSTRAINT check_2981f15877 CHECK ((char_length(jitsu_key) <= 100)),
     CONSTRAINT check_3a03e7557a CHECK ((char_length(previous_default_branch) <= 4096)),
     CONSTRAINT check_3ca5cbffe6 CHECK ((char_length(issue_branch_template) <= 255)),
     CONSTRAINT check_4b142e71f3 CHECK ((char_length(product_analytics_data_collector_host) <= 255)),
@@ -21642,7 +21661,10 @@ CREATE TABLE project_settings (
     CONSTRAINT check_acb7fad2f9 CHECK ((char_length(product_analytics_instrumentation_key) <= 255)),
     CONSTRAINT check_b09644994b CHECK ((char_length(squash_commit_template) <= 500)),
     CONSTRAINT check_bde223416c CHECK ((show_default_award_emojis IS NOT NULL)),
+    CONSTRAINT check_ea15225016 CHECK ((char_length(jitsu_project_xid) <= 255)),
     CONSTRAINT check_eaf7cfb6a7 CHECK ((char_length(merge_commit_template) <= 500)),
+    CONSTRAINT check_f4499c0fa4 CHECK ((char_length(jitsu_host) <= 255)),
+    CONSTRAINT check_f5495015f5 CHECK ((char_length(jitsu_administrator_email) <= 255)),
     CONSTRAINT check_f9df7bcee2 CHECK ((char_length(cube_api_base_url) <= 512))
 );
 
diff --git a/spec/requests/api/project_attributes.yml b/spec/requests/api/project_attributes.yml
index 019862309dd70..1055c1a696862 100644
--- a/spec/requests/api/project_attributes.yml
+++ b/spec/requests/api/project_attributes.yml
@@ -162,6 +162,7 @@ project_setting:
     - selective_code_owner_removals
     - show_diff_preview_in_email
     - suggested_reviewers_enabled
+    - jitsu_key
     - mirror_branch_regex
     - allow_pipeline_trigger_approve_deployment
     - pages_unique_domain_enabled
@@ -169,7 +170,16 @@ project_setting:
     - pages_multiple_versions_enabled
     - runner_registration_enabled
     - product_analytics_instrumentation_key
+    - jitsu_host
+    - jitsu_project_xid
+    - jitsu_administrator_email
+    - jitsu_administrator_password
+    - encrypted_jitsu_administrator_password
+    - encrypted_jitsu_administrator_password_iv
     - product_analytics_data_collector_host
+    - product_analytics_clickhouse_connection_string
+    - encrypted_product_analytics_clickhouse_connection_string
+    - encrypted_product_analytics_clickhouse_connection_string_iv
     - cube_api_base_url
     - cube_api_key
     - encrypted_cube_api_key
-- 
GitLab