Browse Source

Merge branch 'fix-db-trigger' into 'main'

Only trigger refresh_instances when the actor being changed is a relay

Closes #1103

See merge request framasoft/mobilizon!1230
chapril
Thomas Citharel 3 months ago
parent
commit
a84ec21aba
  1. 45
      priv/repo/migrations/20220505091224_change_refresh_instance_trigger_to_only_execute_on_relays.exs

45
priv/repo/migrations/20220505091224_change_refresh_instance_trigger_to_only_execute_on_relays.exs

@ -0,0 +1,45 @@
defmodule Mobilizon.Storage.Repo.Migrations.ChangeRefreshInstanceTriggerToOnlyExecuteOnRelays do
use Ecto.Migration
def up do
execute("""
DROP TRIGGER IF EXISTS refresh_instances_trigger ON actors;
""")
execute("""
CREATE TRIGGER refresh_instances_trigger_new
AFTER INSERT OR UPDATE
ON actors
FOR EACH ROW
WHEN (NEW.preferred_username = 'relay')
EXECUTE PROCEDURE refresh_instances();
""")
execute("""
CREATE TRIGGER refresh_instances_trigger_old
AFTER DELETE
ON actors
FOR EACH ROW
WHEN (OLD.preferred_username = 'relay')
EXECUTE PROCEDURE refresh_instances();
""")
end
def down do
execute("""
DROP TRIGGER IF EXISTS refresh_instances_trigger_new ON actors;
""")
execute("""
DROP TRIGGER IF EXISTS refresh_instances_trigger_old ON actors;
""")
execute("""
CREATE TRIGGER refresh_instances_trigger
AFTER INSERT OR UPDATE OR DELETE
ON actors
FOR EACH STATEMENT
EXECUTE PROCEDURE refresh_instances();
""")
end
end
Loading…
Cancel
Save