diff options
author | Maksim Pechnikov <parallel588@gmail.com> | 2020-08-04 12:00:51 +0300 |
---|---|---|
committer | Maksim Pechnikov <parallel588@gmail.com> | 2020-08-04 21:17:42 +0300 |
commit | a545c6e1e68ffad18853eeee9868dfafa60a3c23 (patch) | |
tree | 4eadabab80af57da29d6523b3a7721a9cf073e41 | |
parent | e3953923aca1706ab508bfda1ab892304b29c09a (diff) | |
download | pleroma-a545c6e1e68ffad18853eeee9868dfafa60a3c23.tar.gz |
added index
-rw-r--r-- | priv/repo/migrations/20200804055848_add_object_attachment_urls_function_and_index_to_object.exs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/priv/repo/migrations/20200804055848_add_object_attachment_urls_function_and_index_to_object.exs b/priv/repo/migrations/20200804055848_add_object_attachment_urls_function_and_index_to_object.exs new file mode 100644 index 000000000..9536ad9f1 --- /dev/null +++ b/priv/repo/migrations/20200804055848_add_object_attachment_urls_function_and_index_to_object.exs @@ -0,0 +1,37 @@ +defmodule Pleroma.Repo.Migrations.AddObjectAttachmentUrlsFunctionAndIndexToObject do + use Ecto.Migration + + @disable_ddl_transaction true + @disable_migration_lock true + + def up do + """ + CREATE OR REPLACE FUNCTION object_attachment_urls(j jsonb) + RETURNS text[] AS $$ + BEGIN + RETURN ARRAY( + SELECT elem->> 'href' + FROM jsonb_array_elements(j #> '{url}') elem + WHERE jsonb_typeof(j::jsonb #> '{url}') = 'array' + ); + END; + $$ LANGUAGE plpgsql IMMUTABLE; + """ + |> execute() + + create( + index(:objects, ["object_attachment_urls(data)"], + name: :object_attachment_urls_index, + concurrently: true + ) + ) + end + + def down do + drop_if_exists( + index(:objects, ["object_attachment_urls(data)"], name: :object_attachment_urls_index) + ) + + execute("drop function if exists object_attachment_urls(j jsonb)") + end +end |