Skip to content

Commit

Permalink
Add index storage parameters for Postgres (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane authored Nov 28, 2023
1 parent d5153e3 commit 2d97915
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ecto/adapters/postgres/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ if Code.ensure_loaded?(Postgrex) do
?),
if_do(include_fields != [], [" INCLUDE ", ?(, include_fields, ?)]),
maybe_nulls_distinct,
if_do(index.options != nil, [" WITH ", ?(, index.options, ?)]),
if_do(index.where, [" WHERE ", to_string(index.where)])
]
]
Expand Down
7 changes: 7 additions & 0 deletions test/ecto/adapters/postgres_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,13 @@ defmodule Ecto.Adapters.PostgresTest do
[~s|CREATE INDEX "posts_permalink_index" ON ONLY "posts" ("permalink")|]
end

test "create an index with storage parameters" do
create = {:create, index(:posts, [:title], options: "fillfactor=50")}

assert execute_ddl(create) ==
[~s|CREATE INDEX "posts_title_index" ON "posts" ("title") WITH (fillfactor=50)|]
end

test "drop index" do
drop = {:drop, index(:posts, [:id], name: "posts$main"), :restrict}
assert execute_ddl(drop) == [~s|DROP INDEX "posts$main"|]
Expand Down

0 comments on commit 2d97915

Please sign in to comment.