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

Feat: Implement cid (Content ID) for items #410

Closed
4 tasks done
nelsonic opened this issue Aug 22, 2023 · 7 comments
Closed
4 tasks done

Feat: Implement cid (Content ID) for items #410

nelsonic opened this issue Aug 22, 2023 · 7 comments
Assignees
Labels
discuss Share your constructive thoughts on how to make progress with this issue elixir Pull requests that update Elixir code enhancement New feature or enhancement of existing functionality priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T1h Time Estimate 1 Hour tech-debt A feature/requirement implemented in a sub-optimal way & must be re-written technical A technical issue that requires understanding of the code, infrastructure or dependencies

Comments

@nelsonic
Copy link
Member

nelsonic commented Aug 22, 2023

At present items use the built-in bigint id as a primary key:

image

This is fine in a single DB instance and **server-side rendered App.
But it won't work for offline-first Mobile App ...

Todo

  • add cid https://github.com/dwyl/cid to item schema and
  • create a cid based on the initial content of of the item to insert into the DB.
  • use the cid for all public facing API calls instead of the numeric index to make unique content addresses.
  • Use the item.cid in the list_items.seq Reordering items #145 so they are Strings not Bigint.
@nelsonic nelsonic added enhancement New feature or enhancement of existing functionality technical A technical issue that requires understanding of the code, infrastructure or dependencies discuss Share your constructive thoughts on how to make progress with this issue T1h Time Estimate 1 Hour tech-debt A feature/requirement implemented in a sub-optimal way & must be re-written elixir Pull requests that update Elixir code labels Aug 22, 2023
@nelsonic nelsonic self-assigned this Aug 22, 2023
@nelsonic nelsonic added the priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished label Aug 23, 2023
@nelsonic nelsonic moved this to 🔖 Ready for Development in dwyl app kanban Aug 23, 2023
This was referenced Aug 23, 2023
nelsonic added a commit to dwyl/book that referenced this issue Aug 24, 2023
nelsonic added a commit to dwyl/book that referenced this issue Aug 24, 2023
nelsonic added a commit to dwyl/book that referenced this issue Aug 24, 2023
nelsonic added a commit to dwyl/book that referenced this issue Aug 26, 2023
nelsonic added a commit to dwyl/book that referenced this issue Aug 26, 2023
@nelsonic
Copy link
Member Author

items with cid:
mvp-items-with-cid

@nelsonic
Copy link
Member Author

  def update_all_items_cid do
    items = list_items()
    Enum.each(items, fn i ->
      item = %{
        person_id: i.person_id,
        status: i.status,
        text: i.text,
        id: i.id,
      }
      i
      |> changeset(Map.put(item, :cid, Cid.cid(item)))
      |> Repo.update()
    end)
  end
end

mvp-items-with-cid-populated

@nelsonic
Copy link
Member Author

lists also have a cid:
image

@nelsonic
Copy link
Member Author

list_items now uses the item.cid:
mvp-list_items-seq-uses_cid

Double-click to view (and copy) the contents:
mvp-list_items-seq-insepct-cell-content

Which means that the query works: 🎉
image

@nelsonic
Copy link
Member Author

But sadly, getting the following error:

** (Postgrex.Error) ERROR 42883 (undefined_function) function string_to_array(unknown) does not exist

Specifically:

  1) test accumulate timers for a list of items #103 Item.items_with_timers/1 returns a list of items with timers (App.ItemTest)
     test/app/item_test.exs:195
     ** (Postgrex.Error) ERROR 42883 (undefined_function) function string_to_array(unknown) does not exist

         query: SELECT i.id, i.cid, i.text, i.status, i.person_id, i.updated_at,
       t.start, t.stop, t.id as timer_id
     FROM items i
     FULL JOIN timers AS t ON t.item_id = i.id
     WHERE i.cid = any(string_to_array($1))
     AND i.status IS NOT NULL
     AND i.text IS NOT NULL
     ORDER BY timer_id ASC;


         hint: No function matches the given name and argument types. You might need to add explicit type casts.
     code: item_timers = Item.items_with_timers(1)
     stacktrace:
       (ecto_sql 3.10.1) lib/ecto/adapters/sql.ex:913: Ecto.Adapters.SQL.raise_sql_call_error/1
       (app 1.0.0) lib/app/item.ex:246: App.Item.items_with_timers/1
       test/app/item_test.exs:219: (test)

.......
Finished in 0.1 seconds (0.00s async, 0.1s sync)
11 tests, 1 failure

😢

@nelsonic
Copy link
Member Author

Next error:

** (DBConnection.EncodeError) Postgrex expected an integer in -9223372036854775808..9223372036854775807, got "zb2rhYCKqpWk4v5DKMq19itBhsTqf6GJ51JB8sYQuwvNLEmjV". Please make sure the value you are passing matches the definition in your table or in your query or convert the value accordingly.

 27) test edit-item (AppWeb.AppLiveTest)
     test/app_web/live/app_live_test.exs:179
     ** (DBConnection.EncodeError) Postgrex expected an integer in -9223372036854775808..9223372036854775807, got "zb2rhYCKqpWk4v5DKMq19itBhsTqf6GJ51JB8sYQuwvNLEmjV". Please make sure the value you are passing matches the definition in your table or in your query or convert the value accordingly.
     stacktrace:
       (postgrex 0.17.2) lib/postgrex/type_module.ex:947: Postgrex.DefaultTypes.encode_params/3
       (postgrex 0.17.2) lib/postgrex/query.ex:75: DBConnection.Query.Postgrex.Query.encode/3
       (db_connection 2.5.0) lib/db_connection.ex:1323: DBConnection.encode/5
       (db_connection 2.5.0) lib/db_connection.ex:1423: DBConnection.run_prepare_execute/5
       (db_connection 2.5.0) lib/db_connection.ex:1527: DBConnection.run/6
       (db_connection 2.5.0) lib/db_connection.ex:656: DBConnection.parsed_prepare_execute/5
       (db_connection 2.5.0) lib/db_connection.ex:648: DBConnection.prepare_execute/4
       (postgrex 0.17.2) lib/postgrex.ex:361: Postgrex.query_prepare_execute/4
       (ecto_sql 3.10.1) lib/ecto/adapters/sql.ex:438: Ecto.Adapters.SQL.query!/4
       (app 1.0.0) lib/app/list_items.ex:54: App.ListItems.get_list_items/1
       (app 1.0.0) lib/app/item.ex:228: App.Item.items_with_timers/1
       (app 1.0.0) lib/app_web/live/app_live.ex:34: AppWeb.AppLive.mount/3
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/utils.ex:391: anonymous fn/6 in Phoenix.LiveView.Utils.maybe_call_live_view_mount!/5
       (telemetry 1.2.1) /Users/n/code/mvp/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/static.ex:278: Phoenix.LiveView.Static.call_mount_and_handle_params!/5
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/static.ex:119: Phoenix.LiveView.Static.render/3
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
       (phoenix 1.7.7) lib/phoenix/router.ex:430: Phoenix.Router.__call__/5
       (app 1.0.0) lib/app_web/endpoint.ex:1: AppWeb.Endpoint.plug_builder_call/2
       (app 1.0.0) lib/app_web/endpoint.ex:1: AppWeb.Endpoint.call/2

yes, 28 tests are failing with this error ... 🙃
but this one should be straightforward to pinpoint and fix. 🤞

@nelsonic
Copy link
Member Author

Reordering working with cid:

mvp-reordering-with-cids.mov

Included in #345

@github-project-automation github-project-automation bot moved this from 🔖 Ready for Development to ✅ Done in dwyl app kanban Aug 31, 2023
nelsonic added a commit that referenced this issue Sep 10, 2023
…to enusre the item.cid is created for testing #410
nelsonic added a commit that referenced this issue Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Share your constructive thoughts on how to make progress with this issue elixir Pull requests that update Elixir code enhancement New feature or enhancement of existing functionality priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T1h Time Estimate 1 Hour tech-debt A feature/requirement implemented in a sub-optimal way & must be re-written technical A technical issue that requires understanding of the code, infrastructure or dependencies
Projects
Status: Done
Status: Done
Development

No branches or pull requests

1 participant