Skip to content

Commit

Permalink
Let Elixir do its magic
Browse files Browse the repository at this point in the history
  • Loading branch information
RichDom2185 committed Oct 14, 2024
1 parent d6df4b7 commit 270fc49
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/cadet/assessments/submission.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ defmodule Cadet.Assessments.Submission do
|> validate_xor_relationship
|> validate_required(@required_fields)
|> foreign_key_constraint(:student_id)
|> foreign_key_constraint(:team_id)
|> foreign_key_constraint(:assessment_id)
|> foreign_key_constraint(:unsubmitted_by_id)
|> unique_constraint(:unique_team_id, name: :submissions_team_id_assessment_id_unique_index)
end

defp validate_xor_relationship(changeset) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
defmodule Cadet.Repo.Migrations.CreateTeamsSubmissionConstraint do
use Ecto.Migration

def up do
create(
unique_index(
:submissions,
[:team_id, :assessment_id],
name: :submissions_team_id_assessment_id_unique_index
)
)
end

def down do
drop(constraint(:submissions, :submissions_team_id_assessment_id_unique_index))
def change do
create(index(:submissions, :team_id))
create(unique_index(:submissions, [:assessment_id, :team_id]))
end
end

0 comments on commit 270fc49

Please sign in to comment.