Commit 3dfd38f3 authored by pbair's avatar pbair

Update CREATE TRIGGER to use FUNCTION keyword

Since PG11 the syntax CREATE TRIGGER ... EXECUTE PROCEDURE is
deprecated. Change occurrences in the app to use CREATE TRIGGER ...
EXECUTE FUNCTION.
parent 3625ab69
......@@ -815,7 +815,7 @@ module Gitlab
BEFORE INSERT OR UPDATE
ON #{table}
FOR EACH ROW
EXECUTE PROCEDURE #{trigger}()
EXECUTE FUNCTION #{trigger}()
EOF
end
......
......@@ -25,7 +25,7 @@ module Gitlab
CREATE TRIGGER #{name}
#{fires} ON #{table_name}
FOR EACH ROW
EXECUTE PROCEDURE #{function_name}()
EXECUTE FUNCTION #{function_name}()
SQL
end
......
......@@ -712,7 +712,7 @@ RSpec.describe Gitlab::Database::MigrationHelpers do
expect(model).to receive(:add_not_null_constraint).with(:users, :new)
expect(model).to receive(:execute).with("UPDATE \"users\" SET \"new\" = cast_to_jsonb_with_default(\"users\".\"id\") WHERE \"users\".\"id\" >= #{user.id}")
expect(model).to receive(:execute).with("DROP TRIGGER IF EXISTS #{trigger_name}\nON \"users\"\n")
expect(model).to receive(:execute).with("CREATE TRIGGER #{trigger_name}\nBEFORE INSERT OR UPDATE\nON \"users\"\nFOR EACH ROW\nEXECUTE PROCEDURE #{trigger_name}()\n")
expect(model).to receive(:execute).with("CREATE TRIGGER #{trigger_name}\nBEFORE INSERT OR UPDATE\nON \"users\"\nFOR EACH ROW\nEXECUTE FUNCTION #{trigger_name}()\n")
expect(model).to receive(:execute).with("CREATE OR REPLACE FUNCTION #{trigger_name}()\nRETURNS trigger AS\n$BODY$\nBEGIN\n NEW.\"new\" := NEW.\"id\";\n RETURN NEW;\nEND;\n$BODY$\nLANGUAGE 'plpgsql'\nVOLATILE\n")
model.rename_column_concurrently(:users, :id, :new, type_cast_function: 'cast_to_jsonb_with_default')
......
......@@ -28,8 +28,6 @@ module TriggerHelpers
expect(timing).to eq(expected_timing.to_s)
expect(events).to match_array(Array.wrap(expected_events))
# TODO: Update CREATE TRIGGER syntax to use EXECUTE FUNCTION
# https://gitlab.com/gitlab-org/gitlab/-/issues/227089
expect(definition).to match(%r{execute (?:procedure|function) #{fn_name}()})
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment