diff --git a/lib/atomic/activities/session.ex b/lib/atomic/activities/session.ex index 39a957822..f62875764 100644 --- a/lib/atomic/activities/session.ex +++ b/lib/atomic/activities/session.ex @@ -48,6 +48,7 @@ defmodule Atomic.Activities.Session do |> cast(attrs, @required_fields ++ @optional_fields) |> validate_required(@required_fields) |> validate_location() + |> check_constraint(:minimum_entries, name: :minimum_entries_lower_than_maximum_entries) |> maybe_mark_for_deletion() |> maybe_put_departments(attrs) |> maybe_put_speakers(attrs) diff --git a/priv/repo/migrations/20221023200102_create_sessions.exs b/priv/repo/migrations/20221023200102_create_sessions.exs index d189ddf8d..877b59bdd 100644 --- a/priv/repo/migrations/20221023200102_create_sessions.exs +++ b/priv/repo/migrations/20221023200102_create_sessions.exs @@ -18,5 +18,9 @@ defmodule Atomic.Repo.Migrations.CreateSessions do end create index(:sessions, [:activity_id]) + + create constraint(:sessions, :minimum_entries_lower_than_maximum_entries, + check: "minimum_entries < maximum_entries" + ) end end diff --git a/test/support/fixtures/activities_fixtures.ex b/test/support/fixtures/activities_fixtures.ex index 946462121..350eb5c3a 100644 --- a/test/support/fixtures/activities_fixtures.ex +++ b/test/support/fixtures/activities_fixtures.ex @@ -29,7 +29,7 @@ defmodule Atomic.ActivitiesFixtures do attrs |> Enum.into(%{ maximum_entries: 42, - minimum_entries: 42, + minimum_entries: 0, finish: ~N[2022-10-22 20:00:00], start: ~N[2022-10-22 20:00:00] })