Skip to content

fix(persistence): persist channel team field#2700

Merged
xsahil03x merged 11 commits into
GetStream:masterfrom
TheoGermain:fix/persist-channel-team-field
Jun 4, 2026
Merged

fix(persistence): persist channel team field#2700
xsahil03x merged 11 commits into
GetStream:masterfrom
TheoGermain:fix/persist-channel-team-field

Conversation

@TheoGermain
Copy link
Copy Markdown
Contributor

@TheoGermain TheoGermain commented Jun 1, 2026

Summary

The `team` field of `ChannelModel` was missing from the `Channels` table schema in `stream_chat_persistence`. As a result, `channel.team` was always `null` when read from the local SQLite cache, even when the value had been correctly set server-side.

Root cause

`channels.dart` defines the Drift table for channel data. While most scalar fields of `ChannelModel` are stored as dedicated columns (e.g. `frozen`, `memberCount`, `lastMessageAt`), `team` was never added. It is listed in `ChannelModel.topLevelFields` and serialised correctly over the network, but was silently dropped during persistence.

Changes

  • `channels.dart` — add `TextColumn get team => text().nullable()();`
  • `channel_mapper.dart` — include `team` in both `toChannelModel()` and `toEntity()`
  • `drift_chat_database.dart` — bump `schemaVersion` from 28 → 29 (existing destructive migration handles this automatically)

Impact

Without this fix, any logic depending on `channel.team` behaves incorrectly on first render of each session (cache returns `null`), requiring a network round-trip before the correct value is available. This is particularly visible in multi-tenant setups where `team` determines channel routing or UI visibility.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed persistence of the channel "team" field so team information is correctly saved and restored locally.
  • Chores
    • Local database schema updated; upgrading may trigger a full local migration which can recreate tables and affect locally stored data.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5a5bcd58-5c25-4883-8aab-4692f9ca021f

📥 Commits

Reviewing files that changed from the base of the PR and between b6ea68c and 7ddf74a.

📒 Files selected for processing (1)
  • packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart
✅ Files skipped from review due to trivial changes (1)
  • packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart

📝 Walkthrough

Walkthrough

Adds a nullable team column to the Channels table and bumps the Drift schema to 29, propagates team through channel mappers and generated DB code (entities, companions, composers, prefetch), restructures generated validateIntegrity logic, and updates tests and the changelog to assert team persistence.

Changes

Channel Team Field & Schema

Layer / File(s) Summary
Schema version and team column
packages/stream_chat_persistence/lib/src/db/drift_chat_database.dart, packages/stream_chat_persistence/lib/src/entity/channels.dart
Schema version incremented from 28 to 29; nullable team column added to Channels table.
Team field mapping and wiring
packages/stream_chat_persistence/lib/src/mapper/channel_mapper.dart, packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart
Mappers populate team bidirectionally between ChannelEntity and ChannelModel; generated Channels entity/companion/composers and prefetch wiring include team.
Generated validation logic cleanup
packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart
Removed redundant VerificationResult.success() uses and re-emitted/inlined some GeneratedColumnWithTypeConverter declarations across validateIntegrity implementations for multiple tables.
Reference and prefetch manager updates
packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart
Join/filter predicates updated to use sqlEquals with $_itemColumn comparisons; prefetch _getPrefetchedData calls use explicit generics for messages, drafts, pinned/polls, reactions, members/reads.
Tests and changelog
packages/stream_chat_persistence/CHANGELOG.md, packages/stream_chat_persistence/test/src/dao/channel_query_dao_test.dart, packages/stream_chat_persistence/test/src/mapper/channel_mapper_test.dart
DAO and mapper tests updated to include team in fixtures and assertions; CHANGELOG documents the fix for persisted team field.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • renefloor

Poem

🐰 I hopped through tables, added a team line,
Schema went up — now it's twenty-nine.
Mappers pass data both ways with cheer,
Generated checks tidy, tests now clear.
A tiny rabbit celebrates code that's fine. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding persistence for the channel team field through schema updates, mapper changes, and version bump.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@TheoGermain TheoGermain changed the title fix(stream_chat_persistence): persist channel team field fix(persistence): persist channel team field Jun 1, 2026
Copy link
Copy Markdown
Contributor

@VelikovPetar VelikovPetar left a comment

Choose a reason for hiding this comment

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

It would be great if you can also update the relevant CHANGELOG.md file (from the stream_chat_persistence package).

Additionally, please make sure to sign the Stream CLA - We cannot merge the PR otherwise.

Comment thread packages/stream_chat_persistence/lib/src/mapper/channel_mapper.dart
Comment thread packages/stream_chat_persistence/lib/src/entity/channels.dart
@TheoGermain
Copy link
Copy Markdown
Contributor Author

Thanks for the review! I've updated the CHANGELOG, added team field coverage to the relevant unit tests (channel_mapper_test.dart and channel_query_dao_test.dart), and re-generated the drift files with melos run generate:dart. The CLA has been signed as well.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.64%. Comparing base (bf32995) to head (7ddf74a).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2700   +/-   ##
=======================================
  Coverage   65.64%   65.64%           
=======================================
  Files         423      423           
  Lines       26708    26710    +2     
=======================================
+ Hits        17533    17535    +2     
  Misses       9175     9175           

☔ View full report in Codecov by Harness.
📢 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.

Copy link
Copy Markdown
Contributor

@VelikovPetar VelikovPetar left a comment

Choose a reason for hiding this comment

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

We are looking into the failing CI job, we'll merge the PR as soon as we resolve it!

The check_db_entities workflow used `on: pull_request`, which gives
GITHUB_TOKEN read-only perms on fork PRs and made
peter-evans/create-or-update-comment fail with HTTP 403.

Switch to pull_request_target with least-privilege permissions
(contents: read, pull-requests: write). Avoid the usual
pull_request_target footgun by never checking out the PR head into a
working tree: fetch the PR head SHA as a ref and diff between SHAs,
so attacker-controlled file contents never reach checkout/smudge
filters/hooks while the write token is in scope.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@xsahil03x xsahil03x changed the base branch from master to fix/ci-check-db-entities-fork-perms June 3, 2026 10:19
TheoGermain and others added 6 commits June 3, 2026 12:24
The `team` field of `ChannelModel` was not included in the `Channels`
table schema, causing it to be lost on every app session. The field was
always read as null from the local cache, even after the network response
had populated it correctly.

- Add `team` column to the `Channels` drift table
- Map `team` in both `toChannelModel()` and `toEntity()`
- Bump schema version to 29 (migration is destructive by design)
@xsahil03x xsahil03x force-pushed the fix/persist-channel-team-field branch from fc99f16 to 166a000 Compare June 3, 2026 10:24
@xsahil03x xsahil03x force-pushed the fix/ci-check-db-entities-fork-perms branch 6 times, most recently from c9b9232 to 4efdc45 Compare June 3, 2026 11:00
@xsahil03x xsahil03x deleted the branch GetStream:master June 3, 2026 11:03
@xsahil03x xsahil03x closed this Jun 3, 2026
@xsahil03x xsahil03x reopened this Jun 3, 2026
@xsahil03x xsahil03x changed the base branch from fix/ci-check-db-entities-fork-perms to master June 3, 2026 11:07
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

⚠️ Database Entity Files Modified

The following database entity files have been modified in this PR:

packages/stream_chat_persistence/lib/src/entity/channels.dart

📝 Remember to:

  1. Update database version in db/drift_chat_database.dart.
  2. Update entity schema tests if necessary.

Note: This comment is automatically generated by the CI workflow.

Regenerating with drift_dev 2.22.1 had removed VerificationMeta entries
for columns using type converters (ownCapabilities, config, filterTags,
extraData). Restore them to match master and avoid unintended diff noise
unrelated to the team field addition.
@xsahil03x xsahil03x merged commit e155fca into GetStream:master Jun 4, 2026
22 checks passed
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.

3 participants