def changeset(delivery, params \\ %{}) do
delivery
|> cast(params, [:user_id, :object_id])
+ |> validate_required([:user_id, :object_id])
|> foreign_key_constraint(:object_id)
|> foreign_key_constraint(:user_id)
|> unique_constraint(:user_id, name: :deliveries_user_id_object_id_index)
def change do
create_if_not_exists table(:deliveries) do
- add(:object_id, references(:objects, type: :id))
- add(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
+ add(:object_id, references(:objects, type: :id), null: false)
+ add(:user_id, references(:users, type: :uuid, on_delete: :delete_all), null: false)
end
create_if_not_exists index(:deliveries, :object_id, name: :deliveries_object_id)
create_if_not_exists(unique_index(:deliveries, [:user_id, :object_id]))