Skip to content

Commit 0010d95

Browse files
committed
Adjust rabbitmq doc
1 parent 464ae08 commit 0010d95

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

docs/rabbitmq.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,36 +52,34 @@ create extension amqp;
5252
5353
### 🏗 Use pg_amqp
5454

55-
Add to a migration file, e.g. `10-create_api_schema.sql`.
56-
57-
<details>
58-
<summary>Click to view file</summary>
55+
Publish messages in a migration script, e.g. `03-create_api_schema.sql`:
5956

6057
```sql
6158
-- 10-create_api_schema.sql
6259
begin;
6360

61+
-- Create task table
6462
create table api.task (
6563
id serial primary key,
6664
name text not null
6765
);
6866

67+
-- Publish changes to the task table
6968
create function api.task_updated() returns void
7069
language plpgsql as $$
7170
begin
7271
perform amqp.publish(1, 'amq.topic', 'tasks', json_build_object('event', 'task_updated', 'command', command)::text);
7372
end;
7473
$$;
7574

75+
-- Trigger the task_updated function on update
7676
create trigger task_updated
77-
before update on api.task
77+
before insert or update on api.task
7878
for each row execute procedure api.task_updated();
7979

8080
commit;
8181
```
8282

83-
</details>
84-
8583
## ▶️ 3. Run the Migrations
8684

8785
Once your migrations are ready:

0 commit comments

Comments
 (0)