Skip to content

Commit e369bde

Browse files
author
morten.lund@maskon.no
committed
Rename methods
1 parent c985952 commit e369bde

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

lib/partitioning.ex

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,25 @@ defmodule AshPostgres.Partitioning do
2727
@doc """
2828
Check if partition exists
2929
"""
30-
def exists?(resource, opts) do
30+
def existing_partition?(resource, opts) do
3131
repo = AshPostgres.DataLayer.Info.repo(resource)
32-
partition_name = partition_name(resource, opts)
3332

34-
partition_exists?(repo, resource, partition_name, opts)
33+
resource
34+
|> AshPostgres.DataLayer.Info.partitioning_method()
35+
|> case do
36+
:range ->
37+
false
38+
39+
:list ->
40+
partition_name = partition_name(resource, opts)
41+
schema_exists?(repo, resource, partition_name, opts)
42+
43+
:hash ->
44+
false
45+
46+
unsupported_method ->
47+
raise "Invalid partition method, got: #{unsupported_method}"
48+
end
3549
end
3650

3751
# TBI
@@ -47,15 +61,15 @@ defmodule AshPostgres.Partitioning do
4761
Keyword.get(opts, :tenant)
4862
|> tenant_schema(resource)
4963

50-
if partition_exists?(repo, resource, partition_name, opts) do
64+
if schema_exists?(repo, resource, partition_name, opts) do
5165
{:error, :already_exists}
5266
else
5367
Ecto.Adapters.SQL.query(
5468
repo,
5569
"CREATE TABLE \"#{schema}\".\"#{partition_name}\" PARTITION OF \"#{schema}\".\"#{table}\" FOR VALUES IN ('#{key}')"
5670
)
5771

58-
if partition_exists?(repo, resource, partition_name, opts) do
72+
if schema_exists?(repo, resource, partition_name, opts) do
5973
:ok
6074
else
6175
{:error, "Unable to create partition"}
@@ -67,7 +81,7 @@ defmodule AshPostgres.Partitioning do
6781
defp create_hash_partition(_repo, _resource, _opts) do
6882
end
6983

70-
defp partition_exists?(repo, resource, parition_name, opts) do
84+
defp schema_exists?(repo, resource, parition_name, opts) do
7185
schema =
7286
Keyword.get(opts, :tenant)
7387
|> tenant_schema(resource)

test/partition_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ defmodule AshPostgres.PartitionTest do
33
alias AshPostgres.Test.PartitionedPost
44

55
test "seeding data works" do
6-
assert false == AshPostgres.Partitioning.exists?(PartitionedPost, key: 1)
6+
assert false == AshPostgres.Partitioning.existing_partition?(PartitionedPost, key: 1)
77
assert :ok == AshPostgres.Partitioning.create_partition(PartitionedPost, key: 1)
8-
assert true == AshPostgres.Partitioning.exists?(PartitionedPost, key: 1)
8+
assert true == AshPostgres.Partitioning.existing_partition?(PartitionedPost, key: 1)
99

1010
Ash.Seed.seed!(%PartitionedPost{key: 1})
1111

0 commit comments

Comments
 (0)