Closed mantyr closed 8 months ago
Solution to this problem:
-- +migrate StatementBegin
SQL
-- +migrate StatementEnd
Example:
cat 20240130094405-events.sql
-- +migrate Up
-- +migrate StatementBegin
CREATE FUNCTION notify_event() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
object json;
notification json;
BEGIN
IF (TG_OP = 'DELETE') THEN
object = row_to_json(OLD);
ELSE
object = row_to_json(NEW);
END IF;
notification = json_build_object(
'object_type', TG_TABLE_NAME,
'object_id', object -> TG_ARGV[0],
'action', TG_OP);
PERFORM pg_notify('events',notification::text);
RETURN NULL;
END;
$$;
-- +migrate StatementEnd
-- +migrate Down
godotenv -f ./env/postgres.env sql-migrate up
Applied 1 migrations
Unexpected behavior.
The same migration via regular psql runs successfully.