aboutsummaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
Diffstat (limited to 'priv')
-rw-r--r--priv/repo/migrations/20191007123056_add_ap_id_column_to_objects.exs2
-rw-r--r--priv/repo/migrations/20191007160755_fill_object_ap_id_field.exs7
-rw-r--r--priv/repo/migrations/20191007170423_add_object_ap_id_trigger.exs25
3 files changed, 33 insertions, 1 deletions
diff --git a/priv/repo/migrations/20191007123056_add_ap_id_column_to_objects.exs b/priv/repo/migrations/20191007123056_add_ap_id_column_to_objects.exs
index ebc94833c..fb38fa29c 100644
--- a/priv/repo/migrations/20191007123056_add_ap_id_column_to_objects.exs
+++ b/priv/repo/migrations/20191007123056_add_ap_id_column_to_objects.exs
@@ -6,6 +6,6 @@ defmodule Pleroma.Repo.Migrations.AddApIdColumnToObjects do
add :ap_id, :string
end
- create unique_index(:objects, [:ap_id], concurrently: true)
+ create unique_index(:objects, [:ap_id])
end
end
diff --git a/priv/repo/migrations/20191007160755_fill_object_ap_id_field.exs b/priv/repo/migrations/20191007160755_fill_object_ap_id_field.exs
new file mode 100644
index 000000000..55834b3e1
--- /dev/null
+++ b/priv/repo/migrations/20191007160755_fill_object_ap_id_field.exs
@@ -0,0 +1,7 @@
+defmodule Pleroma.Repo.Migrations.FillObjectApIdField do
+ use Ecto.Migration
+
+ def change do
+ execute("update objects set ap_id = data->>'id'")
+ end
+end
diff --git a/priv/repo/migrations/20191007170423_add_object_ap_id_trigger.exs b/priv/repo/migrations/20191007170423_add_object_ap_id_trigger.exs
new file mode 100644
index 000000000..99ffa79e6
--- /dev/null
+++ b/priv/repo/migrations/20191007170423_add_object_ap_id_trigger.exs
@@ -0,0 +1,25 @@
+defmodule Pleroma.Repo.Migrations.AddObjectApIdTrigger do
+ use Ecto.Migration
+
+ def change do
+ execute("""
+ CREATE OR REPLACE FUNCTION set_ap_id()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $BODY$
+ BEGIN
+ NEW.ap_id = NEW.data->>'id';
+ RETURN NEW;
+ END
+ $BODY$;
+ """)
+
+ execute("""
+ CREATE TRIGGER object_ap_id_extraction
+ BEFORE INSERT OR UPDATE
+ ON objects
+ FOR EACH ROW
+ EXECUTE PROCEDURE set_ap_id();
+ """)
+ end
+end