diff options
| author | Haelwenn <contact+git.pleroma.social@hacktivis.me> | 2022-12-23 17:43:21 +0000 |
|---|---|---|
| committer | Haelwenn <contact+git.pleroma.social@hacktivis.me> | 2022-12-23 17:43:21 +0000 |
| commit | f76c1d4f70fdda6da621a46fb75891e68e266946 (patch) | |
| tree | 328aec763c24b6426decd30fe3b6a4674510bbee /priv/repo/migrations/20220711182322_add_associated_object_id_function.exs | |
| parent | d8e326467c30b95c5164f6e29512057dce3c2077 (diff) | |
| parent | 91c22637de5f1683a32207a606c33e7ef3b84676 (diff) | |
| download | pleroma-f76c1d4f70fdda6da621a46fb75891e68e266946.tar.gz pleroma-f76c1d4f70fdda6da621a46fb75891e68e266946.zip | |
Merge branch 'release/2.5.0' into 'stable'
Release 2.5.0
See merge request pleroma/pleroma!3816
Diffstat (limited to 'priv/repo/migrations/20220711182322_add_associated_object_id_function.exs')
| -rw-r--r-- | priv/repo/migrations/20220711182322_add_associated_object_id_function.exs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/priv/repo/migrations/20220711182322_add_associated_object_id_function.exs b/priv/repo/migrations/20220711182322_add_associated_object_id_function.exs new file mode 100644 index 000000000..76348f31a --- /dev/null +++ b/priv/repo/migrations/20220711182322_add_associated_object_id_function.exs @@ -0,0 +1,37 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Repo.Migrations.AddAssociatedObjectIdFunction do + use Ecto.Migration + + def up do + statement = """ + CREATE OR REPLACE FUNCTION associated_object_id(data jsonb) RETURNS varchar AS $$ + DECLARE + object_data jsonb; + BEGIN + IF jsonb_typeof(data->'object') = 'array' THEN + object_data := data->'object'->0; + ELSE + object_data := data->'object'; + END IF; + + IF jsonb_typeof(object_data->'id') = 'string' THEN + RETURN object_data->>'id'; + ELSIF jsonb_typeof(object_data) = 'string' THEN + RETURN object_data#>>'{}'; + ELSE + RETURN NULL; + END IF; + END; + $$ LANGUAGE plpgsql IMMUTABLE; + """ + + execute(statement) + end + + def down do + execute("DROP FUNCTION IF EXISTS associated_object_id(data jsonb)") + end +end |
