Notification channels and their delivery history replace webhook subscriptions in storage, and existing subscriptions and permissions migrate #151

Open
opened 2026-10-31 12:42:16 -04:00 by claude · 0 comments
Owner
  • Draft: PN-14
  • Priority: high
  • Agent: storage-coder
  • Depends on: #150
  • Decisions: Q-PN-7, Q-PN-8, R2-RENAME

Why

#149 fixes the model. The upgrade must keep every webhook subscription working with its id and delivery history, on all five engines, and an older build must refuse the upgraded database.

What changes

  • src/dotnet/src/Ninlil.Dns.Common/Enum/: new NotificationChannelKindEnum (Webhook = 0, Email = 1, [EnumMember] strings). Rename WebhookDeliveryAttemptStatusEnum to NotificationDeliveryStatusEnum; the stored strings do not change.
  • src/dotnet/src/Ninlil.Dns.Data.Abstractions/Entity/: NotificationChannelEntity and NotificationDeliveryEntity replace WebhookSubscriptionEntity and WebhookDeliveryAttemptEntity, with the fields listed in #149. Repository interfaces INotificationChannelRepository (the methods of IWebhookSubscriptionRepository plus an optional Kind filter on SearchAsync/CountAsync) and INotificationDeliveryRepository (the methods of IWebhookDeliveryAttemptRepository, renamed).
  • EF configuration in Ninlil.Dns.Data.EntityFrameworkCore/Configuration/: tables NinlilDnsNotificationChannels and NinlilDnsNotificationDeliveries. Keep the indexes and the UTC-ticks conversions of WebhookDeliveryAttemptConfiguration.cs:31-78; give the composite index an explicit name of at most 64 characters (MySQL). Kind and ChannelKind are strings of at most 32; EmailRecipients uses JsonStringListValueConverter like EventTypeNames (WebhookSubscriptionConfiguration.cs:31-33).
  • Migrations, two per relational provider, through the AGENTS.md loop plus file-scoped-namespaces.sh:
    1. AddNotificationChannels, generated while the model holds both the old and the new entities. Add to Up: INSERT ... SELECT copying every subscription into the channels table (same Id, Kind = 'Webhook') and every attempt into the deliveries table (SubscriptionId to ChannelId, SubscriptionName to ChannelName, PayloadJson to Payload, ChannelKind = 'Webhook'); UPDATE of ClaimValue in NinlilDnsRoleClaims and NinlilDnsUserClaims: webhooks:read/webhooks:write to notifications:read/notifications:write, and webhookdeliverysettings:read/webhookdeliverysettings:write to notificationdeliverysettings:read/notificationdeliverysettings:write. Down reverses the claim updates.
    2. RemoveWebhookSubscriptions, generated after the old entities are deleted. Add to Down: copy the Webhook channels and their deliveries back into the recreated tables.
    • Technical call: two generated migrations instead of a table rename. EF Core emits drop-and-create for a renamed entity, and AGENTS.md allows only added SQL in generated files, so the copy must sit in a migration where both tables exist.
  • MongoDB: collections NinlilDnsNotificationChannels and NinlilDnsNotificationDeliveries in NinlilDnsMongoContext (replacing lines 273-280), class maps in MongoClassMapRegistrar.cs:95-96, repositories, MongoIndexCatalog.cs:258-277. New step NotificationChannelsReplaceWebhookSubscriptions in MongoSchemaSteps.Known with a backfill (shaped like DnsClientAddressLegacyBackfill) that upserts each old document by _id into the new collection with the renamed fields and Kind: "Webhook", renames the four claim values in the user and role claim collections, then drops the old collections. Upserts by _id make a rerun after a crash safe.
  • Compile-time consumers, with unchanged behaviour (every channel is a webhook until #154 and #155): WebhookDeliveryService, NotificationDeliveryRetrySweepService, NotificationDeliverySubscriber, WebhookDeliveryHealthCheck.cs, WebhooksController.cs (acts only on Webhook rows until #156 removes it), DI registrations in both storage extensions, NinlilDnsContext DbSets, and BackupEntityCatalog.cs:103-105 (entry name NotificationChannels; the exclusion note at line 35 names the deliveries entity). The [RequirePermission] strings of WebhooksController become notifications:read/notifications:write and those of WebhookDeliverySettingsController (:49, :68) become notificationdeliverysettings:read/notificationdeliverysettings:write, so the renamed claims keep granting access. Existing tests are renamed and updated, including PermissionsEndpointTests.cs:72.
  • Interim note: until #158 the console's webhook pages are gated on the old permission names in nav-item.model.ts, so a non-admin user loses those menu entries between this issue and #158; the wildcard admin role (PermissionAuthorizationHandler.cs:20) is unaffected. All of PN-14 to #158 ship in one milestone.

Acceptance

  • This test fails first: in src/dotnet/tests/Ninlil.Dns.Data.Integration.Tests/Migrations/, a new base class shaped like WebhookAttemptMigrationTestsBase (migrate to the migration before AddNotificationChannels, insert a subscription, an attempt and role claims webhooks:write and webhookdeliverysettings:read with raw SQL, migrate to the end) asserts NotificationChannelEntity with the same Id, Kind == Webhook and the same TargetUrl, one delivery with ChannelId equal to that Id, and the claim values notifications:write and notificationdeliverysettings:read. One subclass per relational engine; non-SQLite ones carry [Trait("Category", "RequiresDocker")].
  • A Mongo test seeds the old collections, runs the step twice and finds one channel, one delivery and the renamed claims.
  • A multi-engine round-trip of an Email channel with two recipients.
  • Two migrations per provider; generated files untouched apart from the added SQL.
  • dotnet build Ninlil.slnx -p:NinlilSkipAngularBuild=true reports 0 warnings.
  • Gate: dotnet test src/dotnet/tests/Ninlil.Dns.Data.Integration.Tests, dotnet test src/dotnet/tests/Ninlil.Dns.Server.Notifications.Tests, dotnet test src/dotnet/tests/Ninlil.Dns.Server.Backup.Tests, dotnet test src/dotnet/tests/Ninlil.Web.Tests, then the whole solution (Ninlil.Dns.Common changed).

Source

audit-feature-parity.md §2A #12; AGENTS.md "Storage".
Owner decision 2026-10-31: "ONE UNIFIED notification-channel entity (replaces webhook subscriptions)" (Q-PN-7).
Owner decision 2026-10-31, round 2 (R2-RENAME): the delivery settings permissions move to notification names too.

- **Draft:** PN-14 - **Priority:** high - **Agent:** storage-coder - **Depends on:** #150 - **Decisions:** Q-PN-7, Q-PN-8, R2-RENAME ### Why #149 fixes the model. The upgrade must keep every webhook subscription working with its id and delivery history, on all five engines, and an older build must refuse the upgraded database. ### What changes - `src/dotnet/src/Ninlil.Dns.Common/Enum/`: new `NotificationChannelKindEnum` (`Webhook = 0`, `Email = 1`, `[EnumMember]` strings). Rename `WebhookDeliveryAttemptStatusEnum` to `NotificationDeliveryStatusEnum`; the stored strings do not change. - `src/dotnet/src/Ninlil.Dns.Data.Abstractions/Entity/`: `NotificationChannelEntity` and `NotificationDeliveryEntity` replace `WebhookSubscriptionEntity` and `WebhookDeliveryAttemptEntity`, with the fields listed in #149. Repository interfaces `INotificationChannelRepository` (the methods of `IWebhookSubscriptionRepository` plus an optional `Kind` filter on `SearchAsync`/`CountAsync`) and `INotificationDeliveryRepository` (the methods of `IWebhookDeliveryAttemptRepository`, renamed). - EF configuration in `Ninlil.Dns.Data.EntityFrameworkCore/Configuration/`: tables `NinlilDnsNotificationChannels` and `NinlilDnsNotificationDeliveries`. Keep the indexes and the UTC-ticks conversions of `WebhookDeliveryAttemptConfiguration.cs:31-78`; give the composite index an explicit name of at most 64 characters (MySQL). `Kind` and `ChannelKind` are strings of at most 32; `EmailRecipients` uses `JsonStringListValueConverter` like `EventTypeNames` (`WebhookSubscriptionConfiguration.cs:31-33`). - Migrations, two per relational provider, through the AGENTS.md loop plus `file-scoped-namespaces.sh`: 1. `AddNotificationChannels`, generated while the model holds both the old and the new entities. Add to `Up`: `INSERT ... SELECT` copying every subscription into the channels table (same `Id`, `Kind = 'Webhook'`) and every attempt into the deliveries table (`SubscriptionId` to `ChannelId`, `SubscriptionName` to `ChannelName`, `PayloadJson` to `Payload`, `ChannelKind = 'Webhook'`); `UPDATE` of `ClaimValue` in `NinlilDnsRoleClaims` and `NinlilDnsUserClaims`: `webhooks:read`/`webhooks:write` to `notifications:read`/`notifications:write`, and `webhookdeliverysettings:read`/`webhookdeliverysettings:write` to `notificationdeliverysettings:read`/`notificationdeliverysettings:write`. `Down` reverses the claim updates. 2. `RemoveWebhookSubscriptions`, generated after the old entities are deleted. Add to `Down`: copy the `Webhook` channels and their deliveries back into the recreated tables. - Technical call: two generated migrations instead of a table rename. EF Core emits drop-and-create for a renamed entity, and AGENTS.md allows only added SQL in generated files, so the copy must sit in a migration where both tables exist. - MongoDB: collections `NinlilDnsNotificationChannels` and `NinlilDnsNotificationDeliveries` in `NinlilDnsMongoContext` (replacing lines 273-280), class maps in `MongoClassMapRegistrar.cs:95-96`, repositories, `MongoIndexCatalog.cs:258-277`. New step `NotificationChannelsReplaceWebhookSubscriptions` in `MongoSchemaSteps.Known` with a backfill (shaped like `DnsClientAddressLegacyBackfill`) that upserts each old document by `_id` into the new collection with the renamed fields and `Kind: "Webhook"`, renames the four claim values in the user and role claim collections, then drops the old collections. Upserts by `_id` make a rerun after a crash safe. - Compile-time consumers, with unchanged behaviour (every channel is a webhook until #154 and #155): `WebhookDeliveryService`, `NotificationDeliveryRetrySweepService`, `NotificationDeliverySubscriber`, `WebhookDeliveryHealthCheck.cs`, `WebhooksController.cs` (acts only on `Webhook` rows until #156 removes it), DI registrations in both storage extensions, `NinlilDnsContext` DbSets, and `BackupEntityCatalog.cs:103-105` (entry name `NotificationChannels`; the exclusion note at line 35 names the deliveries entity). The `[RequirePermission]` strings of `WebhooksController` become `notifications:read`/`notifications:write` and those of `WebhookDeliverySettingsController` (`:49`, `:68`) become `notificationdeliverysettings:read`/`notificationdeliverysettings:write`, so the renamed claims keep granting access. Existing tests are renamed and updated, including `PermissionsEndpointTests.cs:72`. - Interim note: until #158 the console's webhook pages are gated on the old permission names in `nav-item.model.ts`, so a non-admin user loses those menu entries between this issue and #158; the wildcard admin role (`PermissionAuthorizationHandler.cs:20`) is unaffected. All of PN-14 to #158 ship in one milestone. ### Acceptance - [ ] This test fails first: in `src/dotnet/tests/Ninlil.Dns.Data.Integration.Tests/Migrations/`, a new base class shaped like `WebhookAttemptMigrationTestsBase` (migrate to the migration before `AddNotificationChannels`, insert a subscription, an attempt and role claims `webhooks:write` and `webhookdeliverysettings:read` with raw SQL, migrate to the end) asserts `NotificationChannelEntity` with the same `Id`, `Kind == Webhook` and the same `TargetUrl`, one delivery with `ChannelId` equal to that `Id`, and the claim values `notifications:write` and `notificationdeliverysettings:read`. One subclass per relational engine; non-SQLite ones carry `[Trait("Category", "RequiresDocker")]`. - [ ] A Mongo test seeds the old collections, runs the step twice and finds one channel, one delivery and the renamed claims. - [ ] A multi-engine round-trip of an `Email` channel with two recipients. - [ ] Two migrations per provider; generated files untouched apart from the added SQL. - [ ] `dotnet build Ninlil.slnx -p:NinlilSkipAngularBuild=true` reports 0 warnings. - [ ] Gate: `dotnet test src/dotnet/tests/Ninlil.Dns.Data.Integration.Tests`, `dotnet test src/dotnet/tests/Ninlil.Dns.Server.Notifications.Tests`, `dotnet test src/dotnet/tests/Ninlil.Dns.Server.Backup.Tests`, `dotnet test src/dotnet/tests/Ninlil.Web.Tests`, then the whole solution (`Ninlil.Dns.Common` changed). ### Source `audit-feature-parity.md` §2A #12; AGENTS.md "Storage". Owner decision 2026-10-31: "ONE UNIFIED notification-channel entity (replaces webhook subscriptions)" (Q-PN-7). Owner decision 2026-10-31, round 2 (R2-RENAME): the delivery settings permissions move to notification names too.
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lantea-one/ninlil#151
No description provided.