Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/priv/repo/migrations/20261028000000_backfill_instances_from_users.exs b/priv/repo/migrations/20261028000000_backfill_instances_from_users.exs
new file mode 100644
index 000000000..13d805c30
--- /dev/null
+++ b/priv/repo/migrations/20261028000000_backfill_instances_from_users.exs
@@ -0,0 +1,29 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2026 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Repo.Migrations.BackfillInstancesFromUsers do
+ use Ecto.Migration
+
+ # Remote users now create an instances row; add the hosts of existing ones,
+ # so the peer list can come from the instances table.
+ def up do
+ Pleroma.Repo.query!(
+ """
+ INSERT INTO instances (host, inserted_at, updated_at)
+ SELECT DISTINCT host, now(), now()
+ FROM (
+ SELECT substring(ap_id from '^[A-Za-z][A-Za-z0-9+.-]*://([^/:?#]+)') AS host
+ FROM users
+ WHERE local = false AND ap_id IS NOT NULL
+ ) AS hosts
+ WHERE host IS NOT NULL
+ ON CONFLICT (host) DO NOTHING
+ """,
+ [],
+ timeout: :infinity
+ )
+ end
+
+ def down, do: :ok
+end
diff --git a/test/pleroma/repo/migrations/backfill_instances_from_users_test.exs b/test/pleroma/repo/migrations/backfill_instances_from_users_test.exs
new file mode 100644
index 000000000..733c6644b
--- /dev/null
+++ b/test/pleroma/repo/migrations/backfill_instances_from_users_test.exs
@@ -0,0 +1,31 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2026 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Repo.Migrations.BackfillInstancesFromUsersTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+ import Pleroma.Tests.Helpers
+
+ alias Pleroma.Instances.Instance
+
+ setup_all do: require_migration("20261028000000_backfill_instances_from_users")
+
+ test "up/0 adds the hosts of remote users and keeps existing records", %{migration: migration} do
+ unreachable_since = ~N[2020-01-01 00:00:00.000000]
+ insert(:instance, host: "known.example", unreachable_since: unreachable_since)
+
+ insert(:user, local: false, ap_id: "https://known.example/users/a")
+ insert(:user, local: false, ap_id: "https://new.example/users/a")
+ insert(:user, local: false, ap_id: "https://new.example/users/b")
+ insert(:user, local: false, ap_id: "https://ported.example:8443/users/c")
+ insert(:user, local: true)
+
+ migration.up()
+
+ hosts = Instance |> Repo.all() |> Enum.map(& &1.host) |> Enum.sort()
+ assert hosts == ["known.example", "new.example", "ported.example"]
+
+ assert %{unreachable_since: ^unreachable_since} = Repo.get_by(Instance, host: "known.example")
+ end
+end

File Metadata

Mime Type
text/x-diff
Expires
Sat, Oct 31, 3:15 AM (16 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1800964
Default Alt Text
(2 KB)

Event Timeline