Skip to content

Add Channels data layer: schemas, context, and migration (#4399)#4415

Merged
stuartc merged 6 commits intochannelsfrom
4399-channels-pipeline
Feb 11, 2026
Merged

Add Channels data layer: schemas, context, and migration (#4399)#4415
stuartc merged 6 commits intochannelsfrom
4399-channels-pipeline

Conversation

@stuartc
Copy link
Member

@stuartc stuartc commented Feb 11, 2026

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.

  • Migration creating channels, channel_snapshots, channel_requests, and channel_events tables
  • Ecto schemas for all four entities with type specs, associations, and changesets
  • Lightning.Channels context with CRUD operations (list, get, create, update, delete)
  • Optimistic locking via lock_version (matching the Workflow pattern)
  • has_many :channels association on Project
  • ExMachina factories and context tests

Closes #4399

Validation steps

  1. mix test test/lightning/channels_test.exs — all 11 tests pass
  2. mix ecto.reset — migration runs cleanly
  3. Review schemas against context/architecture/02-data-model.md

Additional notes for the reviewer

  1. This is schemas + CRUD only. Snapshot get_or_create_current/1, the Observer,
    routing, and UI are coming in follow-up PRs.
  2. delete_channel/1 uses foreign_key_constraint on the changeset to handle
    the :restrict FK from channel_snapshots, returning a standard {:error, changeset}.
  3. Credential fields on ChannelSnapshot are plain UUID fields (not FK references)
    because snapshots are immutable — the credential may be deleted after the snapshot
    is created.

AI Usage

  • I have used Claude Code
  • I have used another model
  • I have not used AI

Pre-submission checklist

  • I have performed an AI review of my code (we recommend using /review
    with Claude Code)
  • I have implemented and tested all related authorization policies.
    (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

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
@github-project-automation github-project-automation bot moved this to New Issues in v2 Feb 11, 2026
@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.32%. Comparing base (af21999) to head (bb8f9d4).
⚠️ Report is 5 commits behind head on channels.

Files with missing lines Patch % Lines
lib/lightning/channels/channel_event.ex 50.00% 1 Missing ⚠️
lib/lightning/channels/channel_request.ex 50.00% 1 Missing ⚠️
lib/lightning/channels/channel_snapshot.ex 50.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@stuartc stuartc changed the base branch from main to channels February 11, 2026 12:06
@stuartc stuartc marked this pull request as ready for review February 11, 2026 12:18
@stuartc stuartc merged commit fd6c24e into channels Feb 11, 2026
5 of 7 checks passed
@stuartc stuartc deleted the 4399-channels-pipeline branch February 11, 2026 12:18
@github-project-automation github-project-automation bot moved this from New Issues to Done in v2 Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Channels: Schema and context setup

1 participant

Comments