@@ -15,17 +15,15 @@ from sqlspec.adapters.sqlite import SqliteConfig
1515spec = SQLSpec()
1616config = SqliteConfig(
1717 connection_config = {" database" : " :memory:" },
18- migration_config = {
19- " script_location" : " migrations" ,
20- " include_extensions" : [" events" ],
21- },
18+ migration_config = {" script_location" : " migrations" },
2219 extension_config = {
2320 " events" : {
2421 " queue_table" : " app_events" ,
2522 }
2623 },
2724)
2825spec.add_config(config)
26+ # Events migrations are auto-included when extension_config["events"] is present
2927
3028channel = spec.event_channel(config)
3129channel.publish(" notifications" , {" type" : " cache_invalidate" , " key" : " user:1" })
@@ -38,7 +36,7 @@ for message in channel.iter_events("notifications"):
3836## PostgreSQL native notifications
3937
4038All async PostgreSQL adapters (AsyncPG, Psycopg async, and Psqlpy) support
41- native ` LISTEN/NOTIFY ` via ` events_backend= "listen_notify"` . When enabled,
39+ native ` LISTEN/NOTIFY ` via ` extension_config["events"]["backend"] = "listen_notify"` . When enabled,
4240events flow directly through PostgreSQL's notification system with no
4341migrations required.
4442
@@ -65,7 +63,7 @@ enabled as described below.
6563
6664## Oracle Advanced Queuing (sync adapters)
6765
68- Set `` config.driver_features["events_backend "] = "advanced_queue"`` to opt into native AQ.
66+ Set `` extension_config["events"]["backend "] = "advanced_queue"`` to opt into native AQ.
6967When enabled, `` EventChannel `` publishes JSON payloads via `` connection.queue `` and
7068skips the durable table migrations. The backend currently targets synchronous drivers
7169(async configs fall back to the queue extension automatically).
@@ -81,21 +79,22 @@ and transparently falls back to the table-backed queue backend.
8179
8280## Enabling the events extension
8381
84- 1 . ** Include the extension migrations**
82+ 1 . ** Extension migrations are auto-included**
83+
84+ When ` extension_config["events"] ` is present, SQLSpec automatically
85+ includes the events extension in ` migration_config["include_extensions"] ` .
86+ Running ` sqlspec upgrade ` (or ` config.migrate_up() ` ) applies
87+ ` ext_events_0001 ` , which creates the queue table and composite index.
88+
89+ To skip the migrations (e.g., for ephemeral ` listen_notify ` backend):
8590
8691 ``` python
8792 migration_config= {
8893 " script_location" : " migrations" ,
89- " include_extensions " : [" events" ],
94+ " exclude_extensions " : [" events" ], # Skip queue table migration
9095 }
9196 ```
9297
93- When ` extension_config["events"] ` is present SQLSpec automatically
94- appends ` "events" ` to ` include_extensions ` , but setting it explicitly makes
95- the intent clear and mirrors other extension guides. Running
96- ` sqlspec upgrade ` (or ` config.migrate_up() ` ) applies
97- ` ext_events_0001 ` , which creates the queue table and composite index.
98-
99982 . ** Provide extension settings (optional)**
10099
101100 ``` python
@@ -200,15 +199,19 @@ Manual iteration is also available via `channel.iter_events(...)` which yields
200199
201200| Option | Default | Description |
202201| ------------------ | ----------------------- | ----------- |
202+ | ` backend ` | adapter-specific | Backend implementation: ` listen_notify ` , ` table_queue ` , ` listen_notify_durable ` , or ` advanced_queue ` . |
203203| ` queue_table ` | ` sqlspec_event_queue ` | Table name used by migrations and runtime. |
204204| ` lease_seconds ` | ` 30 ` | How long a consumer owns a message before it can be retried. |
205205| ` retention_seconds ` | ` 86400 ` | How long acknowledged rows remain before automatic cleanup. |
206206| ` poll_interval ` | adapter-specific | Default sleep window between dequeue attempts; see table below. |
207207| ` in_memory ` | ` False ` | Oracle-only flag that adds ` INMEMORY PRIORITY HIGH ` to the queue table. |
208- | ` aq_queue ` | ` SQLSPEC_EVENTS_QUEUE ` | Native AQ queue name when ` events_backend ="advanced_queue"` . |
208+ | ` aq_queue ` | ` SQLSPEC_EVENTS_QUEUE ` | Native AQ queue name when ` backend ="advanced_queue"` . |
209209| ` aq_wait_seconds ` | ` 5 ` | Wait timeout (seconds) for AQ dequeue operations. |
210210| ` aq_visibility ` | * unset* | Optional visibility constant (e.g., ` AQMSG_VISIBLE ` ). |
211211
212+ To skip migrations for ephemeral backends (e.g., ` listen_notify ` ), use
213+ ` migration_config={"exclude_extensions": ["events"]} ` .
214+
212215### Adapter defaults
213216
214217` EventChannel ` ships with tuned defaults per adapter so you rarely have to tweak the queue knobs. Override any value via ` extension_config["events"] ` when your workload differs from the defaults.
@@ -290,27 +293,28 @@ three backend types:
290293| ` advanced_queue ` | Oracle Advanced Queuing | Enterprise Oracle deployments |
291294| ` table_queue ` | Polling-based queue table | Universal fallback for any database |
292295
293- Configure the backend via ` driver_features["events_backend "]` :
296+ Configure the backend via ` extension_config["events"]["backend "]` :
294297
295298``` python
296299from sqlspec.adapters.asyncpg import AsyncpgConfig
297300
298301# Native LISTEN/NOTIFY (default for PostgreSQL adapters)
299302config = AsyncpgConfig(
300303 connection_config = {" dsn" : " postgresql://localhost/db" },
301- driver_features = {" events_backend " : " listen_notify" },
304+ extension_config = {" events " : { " backend " : " listen_notify" } },
302305)
303306
304307# Hybrid: durable queue with NOTIFY wakeups
305308config = AsyncpgConfig(
306309 connection_config = {" dsn" : " postgresql://localhost/db" },
307- driver_features = {" events_backend " : " listen_notify_durable" },
310+ extension_config = {" events " : { " backend " : " listen_notify_durable" } },
308311)
309312```
310313
311314Queue-backed backends (` listen_notify_durable ` , ` table_queue ` ) require the
312- events extension migrations. Ensure ` migration_config["include_extensions"] `
313- contains ` "events" ` before publishing or consuming.
315+ events extension migrations. When ` extension_config["events"] ` is present,
316+ SQLSpec auto-includes the migrations. For ephemeral ` listen_notify ` only,
317+ use ` migration_config={"exclude_extensions": ["events"]} ` .
314318
315319### Event Queue Stores
316320
0 commit comments