Skip to content

Commit

Permalink
Setup cache_order, added unique index for record id/cache version
Browse files Browse the repository at this point in the history
Co-authored-by: Amin Zare <[email protected]>
Co-authored-by: Anna Headley <[email protected]>
Co-authored-by: Eliot Jordan <[email protected]>
Co-authored-by: Shaun Ellis <[email protected]>
  • Loading branch information
5 people committed Jul 24, 2024
1 parent e4dc1a5 commit f79e2f4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule DpulCollections.IndexingPipeline.HydrationCacheEntry do
field :record_id, :string
field :source_cache_order, :utc_datetime

timestamps(type: :utc_datetime)
timestamps(updated_at: :cache_order, inserted_at: false, type: :utc_datetime)
end

@doc false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ defmodule DpulCollections.Repo.Migrations.CreateHydrationCacheEntries do
add :record_id, :string
add :source_cache_order, :utc_datetime

timestamps(type: :utc_datetime)
timestamps(updated_at: :cache_order, inserted_at: false, type: :utc_datetime)
end

create(
unique_index(
:hydration_cache_entries,
[:record_id, :cache_version],
name: :record_id_cache_version_idx
)
)
end
end
54 changes: 43 additions & 11 deletions test/dpul_collections/indexing_pipeline_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,46 @@ defmodule DpulCollections.IndexingPipelineTest do

test "get_hydration_cache_entry!/1 returns the hydration_cache_entry with given id" do
hydration_cache_entry = hydration_cache_entry_fixture()
assert IndexingPipeline.get_hydration_cache_entry!(hydration_cache_entry.id) == hydration_cache_entry

assert IndexingPipeline.get_hydration_cache_entry!(hydration_cache_entry.id) ==
hydration_cache_entry
end

test "create_hydration_cache_entry/1 with valid data creates a hydration_cache_entry" do
valid_attrs = %{data: "some data", cache_version: 42, record_id: "some record_id", source_cache_order: ~U[2024-07-23 20:05:00Z]}
valid_attrs = %{
data: "some data",
cache_version: 42,
record_id: "some record_id",
source_cache_order: ~U[2024-07-23 20:05:00Z]
}

assert {:ok, %HydrationCacheEntry{} = hydration_cache_entry} =
IndexingPipeline.create_hydration_cache_entry(valid_attrs)

assert {:ok, %HydrationCacheEntry{} = hydration_cache_entry} = IndexingPipeline.create_hydration_cache_entry(valid_attrs)
assert hydration_cache_entry.data == "some data"
assert hydration_cache_entry.cache_version == 42
assert hydration_cache_entry.record_id == "some record_id"
assert hydration_cache_entry.source_cache_order == ~U[2024-07-23 20:05:00Z]
end

test "create_hydration_cache_entry/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = IndexingPipeline.create_hydration_cache_entry(@invalid_attrs)
assert {:error, %Ecto.Changeset{}} =
IndexingPipeline.create_hydration_cache_entry(@invalid_attrs)
end

test "update_hydration_cache_entry/2 with valid data updates the hydration_cache_entry" do
hydration_cache_entry = hydration_cache_entry_fixture()
update_attrs = %{data: "some updated data", cache_version: 43, record_id: "some updated record_id", source_cache_order: ~U[2024-07-24 20:05:00Z]}

assert {:ok, %HydrationCacheEntry{} = hydration_cache_entry} = IndexingPipeline.update_hydration_cache_entry(hydration_cache_entry, update_attrs)
update_attrs = %{
data: "some updated data",
cache_version: 43,
record_id: "some updated record_id",
source_cache_order: ~U[2024-07-24 20:05:00Z]
}

assert {:ok, %HydrationCacheEntry{} = hydration_cache_entry} =
IndexingPipeline.update_hydration_cache_entry(hydration_cache_entry, update_attrs)

assert hydration_cache_entry.data == "some updated data"
assert hydration_cache_entry.cache_version == 43
assert hydration_cache_entry.record_id == "some updated record_id"
Expand All @@ -47,19 +65,33 @@ defmodule DpulCollections.IndexingPipelineTest do

test "update_hydration_cache_entry/2 with invalid data returns error changeset" do
hydration_cache_entry = hydration_cache_entry_fixture()
assert {:error, %Ecto.Changeset{}} = IndexingPipeline.update_hydration_cache_entry(hydration_cache_entry, @invalid_attrs)
assert hydration_cache_entry == IndexingPipeline.get_hydration_cache_entry!(hydration_cache_entry.id)

assert {:error, %Ecto.Changeset{}} =
IndexingPipeline.update_hydration_cache_entry(
hydration_cache_entry,
@invalid_attrs
)

assert hydration_cache_entry ==
IndexingPipeline.get_hydration_cache_entry!(hydration_cache_entry.id)
end

test "delete_hydration_cache_entry/1 deletes the hydration_cache_entry" do
hydration_cache_entry = hydration_cache_entry_fixture()
assert {:ok, %HydrationCacheEntry{}} = IndexingPipeline.delete_hydration_cache_entry(hydration_cache_entry)
assert_raise Ecto.NoResultsError, fn -> IndexingPipeline.get_hydration_cache_entry!(hydration_cache_entry.id) end

assert {:ok, %HydrationCacheEntry{}} =
IndexingPipeline.delete_hydration_cache_entry(hydration_cache_entry)

assert_raise Ecto.NoResultsError, fn ->
IndexingPipeline.get_hydration_cache_entry!(hydration_cache_entry.id)
end
end

test "change_hydration_cache_entry/1 returns a hydration_cache_entry changeset" do
hydration_cache_entry = hydration_cache_entry_fixture()
assert %Ecto.Changeset{} = IndexingPipeline.change_hydration_cache_entry(hydration_cache_entry)

assert %Ecto.Changeset{} =
IndexingPipeline.change_hydration_cache_entry(hydration_cache_entry)
end
end
end

0 comments on commit f79e2f4

Please sign in to comment.