I have a Booking resource with start, duration and user_id attributes. start is a NaiveDateTime and duration is an integer (seconds).
I have created an exclusion constraint, *bookings_cannot_overlap" to prevent overlapping bookings on the same date by the same user. I have also added the name of the constraint to “exclusion constraint names”.
However, when I attempt to create an overlapping booking, I still get an “Ash.Error.Unknown” exception. I was hoping to get a changeset back with an error message on the start attribute.
I’m new to Ash, so probably an error on my end. Any help would be appreciated!
postgres do
table "bookings"
repo Start.Repo
...
exclusion_constraint_names [{:start, "bookings_cannot_overlap", "overlap error"}]
custom_statements do
statement :bookings_cannot_overlap do
up """
ALTER TABLE bookings
ADD CONSTRAINT bookings_cannot_overlap
EXCLUDE USING gist (
box(
point(
extract( epoch from start ), user_id
),
point(
extract( epoch from start ) + duration - 1,
user_id + 0.5
)
)
WITH &&
)
"""
down """
ALTER TABLE bookings
DROP CONSTRAINT bookings_cannot_overlap
"""
end
end
end