Skip to content

Commit

Permalink
add constraint back on challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak committed Nov 14, 2023
1 parent 5ea2a59 commit 9d6f5cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/org/maproulette/models/dal/ChallengeDAL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.joda.time.DateTime
import org.maproulette.Config
import org.maproulette.cache.CacheManager
import org.maproulette.data.{Actions, ChallengeType, ProjectType}
import org.maproulette.exception.{InvalidException, NotFoundException}
import org.maproulette.exception.{InvalidException, NotFoundException, UniqueViolationException}
import org.maproulette.framework.model._
import org.maproulette.framework.repository.{
ChallengeListingRepository,
Expand Down Expand Up @@ -497,7 +497,7 @@ class ChallengeDAL @Inject() (
${challenge.extra.limitReviewTags}, ${challenge.extra.taskStyles}, ${challenge.general.requiresLocal}, ${challenge.extra.isArchived},
${challenge.extra.reviewSetting},
${asJson(challenge.extra.taskWidgetLayout.getOrElse(Json.parse("{}")))}
) RETURNING #${this.retrieveColumns}"""
) ON CONFLICT(parent_id, LOWER(name)) DO NOTHING RETURNING #${this.retrieveColumns}"""
.as(this.parser.*)
.headOption
}
Expand All @@ -513,6 +513,10 @@ class ChallengeDAL @Inject() (
}
} match {
case Some(value) => value
case None =>
throw new UniqueViolationException(
s"Challenge with name ${challenge.name} already exists in the database"
)
}
}

Expand Down
1 change: 0 additions & 1 deletion conf/evolutions/default/94.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# --- !Ups
-- Remove the constraint for a distinct virtual challenge (id,name) tuple, and allow users to create virtual challenges with the same name.
ALTER TABLE virtual_challenges DROP CONSTRAINT IF EXISTS CON_VIRTUAL_CHALLENGES_USER_ID_NAME;
DROP INDEX IF EXISTS idx_challenges_parent_id_name;

# -- !Downs
ALTER TABLE virtual_challenges ADD CONSTRAINT CON_VIRTUAL_CHALLENGES_USER_ID_NAME
Expand Down

0 comments on commit 9d6f5cd

Please sign in to comment.