Align event_tags partition lifecycle with events
This commit is contained in:
@@ -64,7 +64,8 @@ defmodule Parrhesia.Storage.Adapters.Postgres.QueryPlanRegressionTest do
|
||||
)
|
||||
|
||||
plan = Enum.map_join(explain.rows, "\n", &hd/1)
|
||||
assert plan =~ "event_tags_h_value_created_at_idx"
|
||||
assert plan =~ "Index Scan using event_tags_"
|
||||
refute plan =~ "Filter: ((name)::text = 'h'::text)"
|
||||
end
|
||||
|
||||
test "#i-heavy query plan uses dedicated event_tags i index" do
|
||||
@@ -111,7 +112,8 @@ defmodule Parrhesia.Storage.Adapters.Postgres.QueryPlanRegressionTest do
|
||||
)
|
||||
|
||||
plan = Enum.map_join(explain.rows, "\n", &hd/1)
|
||||
assert plan =~ "event_tags_i_value_created_at_idx"
|
||||
assert plan =~ "Index Scan using event_tags_"
|
||||
refute plan =~ "Filter: ((name)::text = 'i'::text)"
|
||||
end
|
||||
|
||||
defp persist_event(overrides) do
|
||||
|
||||
@@ -15,7 +15,7 @@ defmodule Parrhesia.Storage.ArchiverTest do
|
||||
assert is_list(partitions)
|
||||
end
|
||||
|
||||
test "ensure_monthly_partitions creates named monthly partitions" do
|
||||
test "ensure_monthly_partitions creates aligned monthly partitions for events and event_tags" do
|
||||
assert :ok =
|
||||
Archiver.ensure_monthly_partitions(reference_date: ~D[2026-06-14], months_ahead: 1)
|
||||
|
||||
@@ -25,6 +25,9 @@ defmodule Parrhesia.Storage.ArchiverTest do
|
||||
|
||||
assert "events_2026_06" in monthly_partition_names
|
||||
assert "events_2026_07" in monthly_partition_names
|
||||
|
||||
assert table_exists?("event_tags_2026_06")
|
||||
assert table_exists?("event_tags_2026_07")
|
||||
end
|
||||
|
||||
test "archive_sql builds insert-select statement" do
|
||||
@@ -35,6 +38,21 @@ defmodule Parrhesia.Storage.ArchiverTest do
|
||||
test "drop_partition returns an error for protected partitions" do
|
||||
assert {:error, :protected_partition} = Archiver.drop_partition("events_default")
|
||||
assert {:error, :protected_partition} = Archiver.drop_partition("events")
|
||||
assert {:error, :protected_partition} = Archiver.drop_partition("event_tags_default")
|
||||
assert {:error, :protected_partition} = Archiver.drop_partition("event_tags")
|
||||
end
|
||||
|
||||
test "drop_partition removes aligned event_tags partition for monthly event partition" do
|
||||
assert :ok =
|
||||
Archiver.ensure_monthly_partitions(reference_date: ~D[2026-08-14], months_ahead: 0)
|
||||
|
||||
assert table_exists?("events_2026_08")
|
||||
assert table_exists?("event_tags_2026_08")
|
||||
|
||||
assert :ok = Archiver.drop_partition("events_2026_08")
|
||||
|
||||
refute table_exists?("events_2026_08")
|
||||
refute table_exists?("event_tags_2026_08")
|
||||
end
|
||||
|
||||
test "database_size_bytes returns the current database size" do
|
||||
@@ -48,4 +66,12 @@ defmodule Parrhesia.Storage.ArchiverTest do
|
||||
Archiver.archive_sql("events_default; DROP TABLE events", "events_archive")
|
||||
end
|
||||
end
|
||||
|
||||
defp table_exists?(table_name) when is_binary(table_name) do
|
||||
case Repo.query("SELECT to_regclass($1)", ["public." <> table_name]) do
|
||||
{:ok, %{rows: [[nil]]}} -> false
|
||||
{:ok, %{rows: [[_relation_name]]}} -> true
|
||||
_other -> false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user