sql

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sql is the SQL implementation of the notifications module's stores: webhook subscriptions, their handlers' sealed secrets and the delivery records, with the module's registration with the SQL layer.

Role

notifications module, adapter layer (SQL). Store implements the module's port.Store (port.WebhookStore over the shared unit of work) over a shared dialect.Store, on SQLite and PostgreSQL alike. Module registers the notifications stream (adapters/sql/migrations) and the sealed column webhook_secrets.value, fourth in the canonical module order. The composite SQL store in app/adapters/sql builds one Store over its own dialect store, delegates Webhooks to it and names Module in its module list. The package imports the standard library, the kernel, the platform, the module's core and its stream only.

Inputs

  • New: a *dialect.Store over a database that holds the notifications stream's tables.
  • The port's calls, with the context of the caller's transaction, if there is one.

Outputs

  • Store, from New, with Webhooks, and the dialect store's Tx, AfterCommit and Close.
  • Module: the name notifications, the stream migrations.FS and the sealed column webhook_secrets.value.

Invariants

  • Store is built over the shared *dialect.Store, so every call joins the unit of work that the caller's context carries, whichever module's store began it (decision 0044, "Persistence").
  • Every column the store seals is in Module: webhook_secrets.value, with the purpose "webhook_secrets.value" and the row id "<webhook>/<handler index>/<name>", so key rotation re-seals it (decision 0017). Neither ever changes: both are authenticated with every value.
  • A handler's secrets are rows of webhook_secrets; the subscription's JSON document never holds one.
  • The SQL text, the table names and the error texts are those the metadata store's SQL store used before the module owned them.

References

  • Decision 0011: docs/research/decisions/0011-webhooks.md.
  • Decision 0017: docs/research/decisions/0017-sealed-columns-and-master-key.md.
  • Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md ("Persistence": one dialect.Module per module in the canonical order; "Names the migration introduces", which lists Store, New and Module).
  • Target layout: docs/research/architecture-options/5-modular-monolith.md, line 323 (the notifications adapters), line 617 (the notifications SQL adapter) and lines 631 to 633 (RunModule).
  • Plan: docs/implementation/plan.md#p2-stores, #p11-projects-webhooks-retention-replication and #p9d-modular-monolith-migration, epic STO (https://github.com/weaveplatform/artifactweave/issues/939).
  • https://github.com/weaveplatform/artifactweave/issues/1058

Status

Implemented P2: the webhook store with its sealed secrets, as the metadata store's (pull request 3). Moved here in P9d, which added Store, New and Module. The webhook services that call it arrive with P11.

Testing

  • sql_test.go: TestAccContract runs the notifications contract (adapters/storetest.Run) on SQLite in memory and in a file through sqltest.RunModule. The metadata store's contract runs the same cases on PostgreSQL.
  • webhooks_test.go: TestAccWebhooksFaults (a fault injected after a successful statement fails the write or read), TestAccWebhooksSealed (the secrets refuse a read without the keyring) and TestAccWebhooksUnmigrated (every call reports the driver's error on a database without the schema).

Index

Constants

This section is empty.

Variables

View Source
var Module = dialect.Module{
	Name:       "notifications",
	Migrations: migrations.FS,
	Sealed: []dialect.SealedColumn{
		{
			Table: "webhook_secrets", Column: "value", Purpose: purposeWebhookSecret,
			Keys: []string{"webhook_key", "handler_index", "name"},
			RowID: func(k []string) string {
				i, _ := strconv.Atoi(k[1])
				return secretID(k[0], i, k[2])
			},
		},
	},
}

Module registers the notifications module with the SQL layer: its migration stream, under the name that keys the stream's rows in schema_migrations, and the sealed column its webhook store writes. The column keeps the purpose and the row id the store seals with, because both are authenticated with every value (decision 0017): a change to either makes the stored secrets unreadable.

Functions

This section is empty.

Types

type Store

type Store struct{ *dialect.Store }

Store is the SQL implementation of the notifications module's stores. It is built over a shared dialect.Store, so every call joins the transaction that the caller's context carries, whichever module's store began it.

func New

func New(db *dialect.Store) *Store

New returns the notifications module's stores over db, which must hold the module stream's tables.

func (*Store) Webhooks

func (s *Store) Webhooks() port.WebhookStore

Webhooks returns the webhook store: subscriptions, their handlers' sealed secrets and the delivery records (decision 0011).

Directories

Path Synopsis
Package migrations holds the notifications module's migration stream: the SQLite and PostgreSQL schema of the tables the module's SQL adapter owns.
Package migrations holds the notifications module's migration stream: the SQLite and PostgreSQL schema of the tables the module's SQL adapter owns.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL