Add Channels data layer: schemas, context, and migration (#4399)#4415
Merged
Add Channels data layer: schemas, context, and migration (#4399)#4415
Conversation
Create the four core database tables for the channels feature: channels, channel_snapshots, channel_requests, and channel_events with all indexes, foreign keys, and constraints per the data model spec.
Create four Ecto schemas under lib/lightning/channels/: - Channel: core config with optimistic locking - ChannelSnapshot: immutable point-in-time copies - ChannelRequest: proxy request tracking with Ecto.Enum state - ChannelEvent: detailed request/response event log
Create Lightning.Channels context with CRUD operations: list_channels_for_project/1, get_channel!/1, create_channel/1, update_channel/2, delete_channel/1 (with :has_history guard). Wire up has_many :channels on Project schema.
Add ExMachina factories for all 4 channel schemas. Create context test covering CRUD operations, uniqueness constraints, optimistic locking, and deletion protection for channels with history. Fix lock_version default to 0 (matching Workflow pattern) and use stale_error_field for clean changeset errors on version conflicts.
Add module documentation to all four channel schemas to satisfy credo --strict readability checks.
- Align migration lock_version default to 0, matching Workflow pattern - Replace rescue ConstraintError with foreign_key_constraint changeset
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## channels #4415 +/- ##
============================================
- Coverage 89.39% 89.32% -0.07%
============================================
Files 425 430 +5
Lines 20051 20064 +13
============================================
- Hits 17924 17922 -2
- Misses 2127 2142 +15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds the foundational data layer for Channels — HTTP proxy configurations
that forward requests from a source to a sink within a project.
channels,channel_snapshots,channel_requests, andchannel_eventstablesLightning.Channelscontext with CRUD operations (list, get, create, update, delete)lock_version(matching the Workflow pattern)has_many :channelsassociation on ProjectCloses #4399
Validation steps
mix test test/lightning/channels_test.exs— all 11 tests passmix ecto.reset— migration runs cleanlycontext/architecture/02-data-model.mdAdditional notes for the reviewer
get_or_create_current/1, the Observer,routing, and UI are coming in follow-up PRs.
delete_channel/1usesforeign_key_constrainton the changeset to handlethe
:restrictFK fromchannel_snapshots, returning a standard{:error, changeset}.ChannelSnapshotare plain UUID fields (not FK references)because snapshots are immutable — the credential may be deleted after the snapshot
is created.
AI Usage
Pre-submission checklist
/reviewwith Claude Code)
(e.g.,
:owner,:admin,:editor,:viewer)