3Stones-io / omedis

Omedis
1 stars 0 forks source link

Bring back unique position index to activities #299

Closed almirsarajcic closed 5 days ago

almirsarajcic commented 3 weeks ago

The index was dropped in #139 (https://github.com/wintermeyer/omedis/pull/139/files#diff-66f19b7cd8e28c94002ac877f0ee558376f1a3d13cc068d0fbcf4c4ae4ffa53b to be exact).

Having the index there breaks the position update functionality from https://github.com/wintermeyer/omedis/blob/main/lib/omedis/accounts/changes/update_log_category_positions.ex. After you recreate the index, you need to fix the functionality.

Running ExUnit with seed: 363064, max_cases: 20

....................................

  1) test move_down/2 authorized user can move an activity down in position (Omedis.Accounts.ActivityTest)
     test/omedis/accounts/activity_test.exs:530
     match (=) failed
     code:  assert {:ok, moved_activity} = Activity.move_down(activity2, actor: authorized_user, tenant: tenant)
     left:  {:ok, moved_activity}
     right: {
              :error,
              %Ash.Error.Invalid{changeset: "#Changeset<>",  errors: [%Ash.Error.Changes.InvalidAttribute{field: :position, message: "has already been taken", private_vars: [constraint: :unique, constraint_name: "activities_unique_position_index"], value: nil, splode: Ash.Error, bread_crumbs: [], vars: [], path: [], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}
            }
     stacktrace:
       test/omedis/accounts/activity_test.exs:536: (test)

.............................................

  2) test move_up/2 tenant owner can move an activity up in position (Omedis.Accounts.ActivityTest)
     test/omedis/accounts/activity_test.exs:439
     match (=) failed
     code:  assert {:ok, moved_activity} = Activity.move_up(activity2, actor: owner, tenant: tenant)
     left:  {:ok, moved_activity}
     right: {
              :error,
              %Ash.Error.Invalid{changeset: "#Changeset<>",  errors: [%Ash.Error.Changes.InvalidAttribute{field: :position, message: "has already been taken", private_vars: [constraint: :unique, constraint_name: "activities_unique_position_index"], value: nil, splode: Ash.Error, bread_crumbs: [], vars: [], path: [], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}
            }
     stacktrace:
       test/omedis/accounts/activity_test.exs:445: (test)

..........................

  3) test move_up/2 authorized user can move an activity up in position (Omedis.Accounts.ActivityTest)
     test/omedis/accounts/activity_test.exs:454
     match (=) failed
     code:  assert {:ok, moved_activity} = Activity.move_up(activity2, actor: authorized_user, tenant: tenant)
     left:  {:ok, moved_activity}
     right: {
              :error,
              %Ash.Error.Invalid{changeset: "#Changeset<>",  errors: [%Ash.Error.Changes.InvalidAttribute{field: :position, message: "has already been taken", private_vars: [constraint: :unique, constraint_name: "activities_unique_position_index"], value: nil, splode: Ash.Error, bread_crumbs: [], vars: [], path: [], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}
            }
     stacktrace:
       test/omedis/accounts/activity_test.exs:460: (test)

..........

  4) test position updates authorized user can move activities up and down (OmedisWeb.ActivityLive.IndexTest)
     test/omedis_web/live/activity_live/index_test.exs:257
     Assertion with == failed
     code:  assert Ash.get!(Activity, second.id, authorize?: false).position == 1
     left:  2
     right: 1
     stacktrace:
       test/omedis_web/live/activity_live/index_test.exs:296: (test)

...................

  5) test move_down/2 tenant owner can move an activity down in position (Omedis.Accounts.ActivityTest)
     test/omedis/accounts/activity_test.exs:515
     match (=) failed
     code:  assert {:ok, moved_activity} = Activity.move_down(activity2, actor: owner, tenant: tenant)
     left:  {:ok, moved_activity}
     right: {
              :error,
              %Ash.Error.Invalid{changeset: "#Changeset<>",  errors: [%Ash.Error.Changes.InvalidAttribute{field: :position, message: "has already been taken", private_vars: [constraint: :unique, constraint_name: "activities_unique_position_index"], value: nil, splode: Ash.Error, bread_crumbs: [], vars: [], path: [], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}
            }
     stacktrace:
       test/omedis/accounts/activity_test.exs:521: (test)

...........................

  6) test position updates tenant owner can move activities up and down (OmedisWeb.ActivityLive.IndexTest)
     test/omedis_web/live/activity_live/index_test.exs:326
     Assertion with == failed
     code:  assert Ash.get!(Activity, second.id, authorize?: false).position == 1
     left:  2
     right: 1
     stacktrace:
       test/omedis_web/live/activity_live/index_test.exs:360: (test)

.................
Finished in 2.3 seconds (2.0s async, 0.2s sync)
186 tests, 6 failures

https://github.com/wintermeyer/omedis/actions/runs/11712570454/job/32623550597

Related: https://elixirforum.com/t/how-to-reorder-items-in-a-list-in-ash-framework/66740.

almirsarajcic commented 3 weeks ago

Not a priority right now.

kagure-nyakio commented 1 week ago

https://elixirforum.com/t/bulk-updates-on-a-column-with-a-unique-constraint/67560