diff --git a/db/post_migrate/20250312042203_add_unique_index_for_lfs_objects_projects_with_repo_type.rb b/db/post_migrate/20250312042203_add_unique_index_for_lfs_objects_projects_with_repo_type.rb
new file mode 100644
index 0000000000000000000000000000000000000000..1b6d7c34918cffa85c49363886cbfb86d7f1b014
--- /dev/null
+++ b/db/post_migrate/20250312042203_add_unique_index_for_lfs_objects_projects_with_repo_type.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddUniqueIndexForLfsObjectsProjectsWithRepoType < Gitlab::Database::Migration[2.2]
+  milestone '17.10'
+  disable_ddl_transaction!
+
+  TABLE_NAME = :lfs_objects_projects
+  INDEX_NAME = 'lfs_objects_projects_on_project_id_lfs_object_id_with_repo_type'
+
+  def up
+    add_concurrent_index TABLE_NAME, [:project_id, :lfs_object_id, :repository_type],
+      unique: true,
+      where: "repository_type IS NOT NULL",
+      name: INDEX_NAME
+  end
+
+  def down
+    remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME
+  end
+end
diff --git a/db/schema_migrations/20250312042203 b/db/schema_migrations/20250312042203
new file mode 100644
index 0000000000000000000000000000000000000000..7bfe0dfb55d0b5a29a52ef1569d7cb1fc957365e
--- /dev/null
+++ b/db/schema_migrations/20250312042203
@@ -0,0 +1 @@
+abe6b174ca74a5fac711e06d645fb2fc9b549c5075ac03f587fe636183ccd571
\ No newline at end of file
diff --git a/db/structure.sql b/db/structure.sql
index b7b1f4d5852eb5e2f806268adaffed4a298ce67d..a1ebf47055f9714ce4afd0a1658871759b17a713 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -36598,6 +36598,8 @@ CREATE UNIQUE INDEX kubernetes_namespaces_cluster_and_namespace ON clusters_kube
 
 CREATE UNIQUE INDEX lfs_objects_projects_on_project_id_lfs_object_id_null_repo_type ON lfs_objects_projects USING btree (project_id, lfs_object_id) WHERE (repository_type IS NULL);
 
+CREATE UNIQUE INDEX lfs_objects_projects_on_project_id_lfs_object_id_with_repo_type ON lfs_objects_projects USING btree (project_id, lfs_object_id, repository_type) WHERE (repository_type IS NOT NULL);
+
 CREATE UNIQUE INDEX merge_request_user_mentions_on_mr_id_and_note_id_index ON merge_request_user_mentions USING btree (merge_request_id, note_id);
 
 CREATE UNIQUE INDEX merge_request_user_mentions_on_mr_id_index ON merge_request_user_mentions USING btree (merge_request_id) WHERE (note_id IS NULL);