Can't get exclusion_constraint_names to work

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

That constraint name option not working seems like working seems like a bug. Could you create a reproduction project and open an issue? Something to also try is configuring the constraint name in one of the other options like AshPostgres.DataLayer — ash_postgres v2.5.6

I tried replacing “exclusion constraint names” with “unique index names”, but got the same result.

I’ll make a reproduction project and open an issue.

Thanks!

I have opened exclusion_constraint_names not working as expected · Issue #1833 · ash-project/ash · GitHub

Reproduction project: GitHub - trisager/constraint-issue

Thanks for your assistance!

Fixed by @ken-kost :tada:

1 Like