Skip to content

fix(persistence): persist channel team field#2700

Open
TheoGermain wants to merge 9 commits into
GetStream:masterfrom
TheoGermain:fix/persist-channel-team-field
Open

fix(persistence): persist channel team field#2700
TheoGermain wants to merge 9 commits into
GetStream:masterfrom
TheoGermain:fix/persist-channel-team-field

Conversation

@TheoGermain
Copy link
Copy Markdown

@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

  • New Features

    • Channels can be associated with teams for improved organization.
  • Bug Fixes

    • Channel team values are now persisted and correctly mapped.
  • Performance

    • Reduced database reads for channel state retrieval.
  • Changed

    • Cache date format changed to ISO‑8601 strings to preserve millisecond precision.
  • Chores

    • Database schema version upgraded; existing databases will migrate on next startup.

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)
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: df066803-33eb-4f7d-ada6-b623a5849292

📥 Commits

Reviewing files that changed from the base of the PR and between 0aec083 and 41a5c57.

📒 Files selected for processing (1)
  • packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart

📝 Walkthrough

Walkthrough

Adds a nullable team column to Channels and bumps Drift schema version to 29; mappers, tests, and changelog are updated. Many generated DAO mixins now expose managers accessors, and generated Drift codegen files were restructured (column declarations, integrity checks, and prefetch/join helpers).

Changes

Channel Team Field

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 is bumped from 28 to 29. A new nullable team text column is added to the Channels Drift table.
Channel entity mapping
packages/stream_chat_persistence/lib/src/mapper/channel_mapper.dart
ChannelEntityX.toChannelModel and ChannelModelX.toEntity now map the team field during conversions.
Tests and changelog
packages/stream_chat_persistence/test/src/dao/channel_query_dao_test.dart, packages/stream_chat_persistence/test/src/mapper/channel_mapper_test.dart, packages/stream_chat_persistence/CHANGELOG.md
Tests updated to set/assert team; CHANGELOG records the persistence bugfix and related notes.

Generated DAO managers & Drift codegen

Layer / File(s) Summary
DAO manager accessors (generated)
packages/stream_chat_persistence/lib/src/dao/*.g.dart
Generated DAO mixins gain managers getters and corresponding *DaoManager classes exposing typed table-manager accessors across many DAOs.
Drift generated DB changes
packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart
Generated file adds the team column/entity wiring, reorganizes column/GeneratedColumnWithTypeConverter emissions, simplifies some validateIntegrity logic, and updates join/prefetch helpers to use sqlEquals with $_itemColumn and explicit generic parameters for prefetches.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • VelikovPetar
  • xsahil03x

Poem

A rabbit hops through tables and rows,
Adds a team where the channel wind blows.
Schema bumped, mappers sing in tune,
Generated managers hum a new rune.
🐰🌿 Persistence grows anew.

🚥 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 'fix(persistence): persist channel team field' accurately and concisely describes the main change: adding the missing team field to the Channels Drift table schema so that channel team data is properly persisted to the local cache.
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
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 (093743a) to head (fc99f16).

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 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.

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!

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.

2 participants