Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create sessions minimum and max entries constraint #315

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/atomic/activities/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions priv/repo/migrations/20221023200102_create_sessions.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/support/fixtures/activities_fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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]
})
Expand Down