From 838c777f1cb49ec2d8dcb48ccf8f479d6568c859 Mon Sep 17 00:00:00 2001
From: Paul Slaughter <pslaughter@gitlab.com>
Date: Sat, 1 Mar 2025 13:52:00 -0600
Subject: [PATCH] Migrate web_ide_extensions_marketplace ff to data

- If the feature flag is enabled globally then we'll
  assume that the instance wants to seemlessly
  transition to the feature being enabled within
  the application settings.

Changelog: changed
---
 ...ension_marketplace_feature_flag_to_data.rb | 49 +++++++++++++++++++
 db/schema_migrations/20250228183319           |  1 +
 2 files changed, 50 insertions(+)
 create mode 100644 db/migrate/20250228183319_migrate_vscode_extension_marketplace_feature_flag_to_data.rb
 create mode 100644 db/schema_migrations/20250228183319

diff --git a/db/migrate/20250228183319_migrate_vscode_extension_marketplace_feature_flag_to_data.rb b/db/migrate/20250228183319_migrate_vscode_extension_marketplace_feature_flag_to_data.rb
new file mode 100644
index 0000000000000..1f81de3853b08
--- /dev/null
+++ b/db/migrate/20250228183319_migrate_vscode_extension_marketplace_feature_flag_to_data.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+# See https://docs.gitlab.com/ee/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class MigrateVSCodeExtensionMarketplaceFeatureFlagToData < Gitlab::Database::Migration[2.2]
+  restrict_gitlab_migration gitlab_schema: :gitlab_main
+  milestone '17.10'
+
+  # NOTE: This approach is lovingly borrowed from this migration:
+  # https://gitlab.com/gitlab-org/gitlab/-/blob/eae8739ac9d5e4c8316fefb03507cdaeac452a0a/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb#L12
+  class ApplicationSetting < MigrationRecord
+    self.table_name = 'application_settings'
+  end
+
+  def up
+    # TODO: This migration should be noop'd when the feature flag is default enabled or removed
+    # why: This is not the desired default behavior, only the behavior we want to carry over for
+    # customers that have chosen to opt-in early by explicitly enabling the flag.
+    return unless extension_marketplace_flag_enabled?
+
+    ApplicationSetting.reset_column_information
+
+    application_setting = ApplicationSetting.last
+    return unless application_setting
+
+    application_setting.update_columns(
+      vscode_extension_marketplace: { enabled: true, preset: "open_vsx" },
+      updated_at: Time.current
+    )
+  end
+
+  def down
+    return unless extension_marketplace_flag_enabled?
+
+    application_setting = ApplicationSetting.last
+    return unless application_setting
+
+    application_setting.update_column(:vscode_extension_marketplace, {})
+  end
+
+  private
+
+  def extension_marketplace_flag_enabled?
+    # NOTE: It's possible the flag is only enabled for a specific user, but in that case we'll assume
+    # the instance admin didn't want the feature globally available and we won't initialize the data.
+    Feature.enabled?(:web_ide_extensions_marketplace, nil) && Feature.enabled?(:vscode_web_ide, nil)
+  end
+end
diff --git a/db/schema_migrations/20250228183319 b/db/schema_migrations/20250228183319
new file mode 100644
index 0000000000000..80fa4de40ac9e
--- /dev/null
+++ b/db/schema_migrations/20250228183319
@@ -0,0 +1 @@
+29a25fcc2d11173ff1b1b056c962f5ecff287383abe27c5760910d34d2d91d72
\ No newline at end of file
-- 
GitLab