diff --git a/db/post_migrate/20230701043315_ensure_backfill_for_ci_pipeline_variables_pipeline_id_is_finished.rb b/db/post_migrate/20230701043315_ensure_backfill_for_ci_pipeline_variables_pipeline_id_is_finished.rb
new file mode 100644
index 0000000000000000000000000000000000000000..723b074a89884dcb4bbdcaf6897e2c1624da174b
--- /dev/null
+++ b/db/post_migrate/20230701043315_ensure_backfill_for_ci_pipeline_variables_pipeline_id_is_finished.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class EnsureBackfillForCiPipelineVariablesPipelineIdIsFinished < Gitlab::Database::Migration[2.1]
+  include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+  restrict_gitlab_migration gitlab_schema: :gitlab_ci
+  disable_ddl_transaction!
+
+  TABLE_NAME = :ci_pipeline_variables
+
+  def up
+    ensure_batched_background_migration_is_finished(
+      job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+      table_name: TABLE_NAME,
+      column_name: 'pipeline_id',
+      job_arguments: [['pipeline_id'], ['id_convert_to_bigint']]
+    )
+  end
+
+  def down
+    # no-op
+  end
+end
diff --git a/db/post_migrate/20230702053002_create_async_index_for_ci_pipline_variables_pipeline_id.rb b/db/post_migrate/20230702053002_create_async_index_for_ci_pipline_variables_pipeline_id.rb
new file mode 100644
index 0000000000000000000000000000000000000000..0919dceed7e481b6fce07ed45cb174d3597440f9
--- /dev/null
+++ b/db/post_migrate/20230702053002_create_async_index_for_ci_pipline_variables_pipeline_id.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class CreateAsyncIndexForCiPiplineVariablesPipelineId < Gitlab::Database::Migration[2.1]
+  TABLE_NAME = :ci_pipeline_variables
+  INDEX_NAME = "index_ci_pipeline_variables_on_pipeline_id_bigint_and_key"
+
+  def up
+    prepare_async_index TABLE_NAME, [:pipeline_id_convert_to_bigint, :key], unique: true, name: INDEX_NAME
+  end
+
+  def down
+    unprepare_async_index TABLE_NAME, [:pipeline_id_convert_to_bigint, :key], unique: true, name: INDEX_NAME
+  end
+end
diff --git a/db/schema_migrations/20230701043315 b/db/schema_migrations/20230701043315
new file mode 100644
index 0000000000000000000000000000000000000000..15a1fd9cbfed0159b49ad5f7a6e6ebe7178aeb6e
--- /dev/null
+++ b/db/schema_migrations/20230701043315
@@ -0,0 +1 @@
+e2a7487d4da68819a1bdde6626b32ef8399a917a75d4cbc8ecf2fa140ba1ff16
\ No newline at end of file
diff --git a/db/schema_migrations/20230702053002 b/db/schema_migrations/20230702053002
new file mode 100644
index 0000000000000000000000000000000000000000..a2eb709cd56ecef73e846ee37f7138d5c89507a0
--- /dev/null
+++ b/db/schema_migrations/20230702053002
@@ -0,0 +1 @@
+54ac5a22e121379b1ffcefc7b4c1f26cadd15a9b0cabfd0d9e3cba3886777d46
\ No newline at end of file