Skip to content

WithSchemaName: name the schema of the published changes - #55

Merged
djthorpe merged 2 commits into
masterfrom
djt/1124/change-schema
Nov 24, 2026
Merged

djthorpe merged 2 commits into
masterfrom
djt/1124/change-schema

Conversation

@djthorpe

@djthorpe djthorpe commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

WithBroadcaster publishes every change with Schema: "main", the database's name. So two databases whose tables have the same names, publishing to one broadcaster, can't be told apart. go-llm's webhook store, with webhook and call tables, will share the server's broadcaster with other stores.

sqlite.WithSchemaName(name) publishes the main database's changes under that name instead:

db, err := ncruces.Open(ctx, path,
  sqlite.WithBroadcaster(changes, "webhook", "call"),
  sqlite.WithSchemaName("webhook"),
)
// {Action: create, Schema: webhook, Table: call, Row: 42}
  • Options.Schema, set by WithSchemaName, must be an identifier.
  • Applied when changes are published (collapse), not when rows are recorded. After a failed statement in a transaction, its rows are still checked against main, under the database's real name.
  • Attached databases keep their own names.
  • README: the Changes section mentions it.

The changes of every database are published with the schema main, so
two databases whose tables have the same names, which publish to one
broadcaster, can't be told apart. WithSchemaName names it, such as
webhook. Attached databases' changes keep their names, and a failed
statement's rows are still checked in main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 09:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Schema renaming occurs before publication filtering, causing FTS5 internal shadow-table changes to be published when WithSchemaName is used, violating the existing filtering contract.

1 open issue
What changed in this PR

Adds configurable schema names to SQLite change notifications so databases with identically named tables can share a broadcaster and remain distinguishable.

Changes:

  • Introduces WithSchemaName and validates names as identifiers.
  • Applies the configured name to main-database notifications while leaving attached database names unchanged.
  • Documents the option and tests row changes, failed statements, table-level notifications, and invalid names.
File Description
README.md Documents schema naming for shared broadcasters.
opts.go Adds Options.Schema and WithSchemaName validation.
ncruces/​changes.go Applies the configured schema name when collapsing changes.
ncruces/​changes_test.go Tests renamed notifications and invalid schema names.

Review effort: Balanced

Comment thread ncruces/changes.go Resolved
@github-actions

Copy link
Copy Markdown

Coverage for this change: 90.8%

…re checked

Renaming in collapse made isPublished look up the table in the renamed
schema, which it couldn't find, so FTS5's shadow tables were published.
The change keeps its database's name until it's published.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@djthorpe djthorpe self-assigned this Nov 24, 2026
@djthorpe
djthorpe merged commit 29d96f5 into master Nov 24, 2026
2 checks passed
@djthorpe
djthorpe deleted the djt/1124/change-schema branch November 24, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants