Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions .github/workflows/check_db_entities.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
name: check_db_entities

on:
pull_request:
pull_request_target:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
# Under pull_request_target, github.ref is the base branch, so we use
# the PR number to keep each PR's runs isolated.
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

# pull_request_target gives a write token even for fork PRs, but only
# if we explicitly request the scopes here.
permissions:
contents: read
pull-requests: write

jobs:
# Centralizes every gating decision for this workflow — currently just a
# path filter. Downstream jobs only need a single
Expand Down Expand Up @@ -47,11 +55,17 @@ jobs:
ENTITY_DIR="packages/stream_chat_persistence/lib/src/entity"
TEMP_FILE="modified_entities"
BASE_BRANCH="${{ github.base_ref }}"
PR_HEAD_SHA="${{ github.event.pull_request.head.sha }}"

echo "Using base branch: origin/$BASE_BRANCH for comparison"

# Fetch the PR head SHA as a ref only — no working-tree update,
# so no smudge filters / hooks run on PR-controlled files
# while we hold the write token.
git fetch --no-tags --depth=1 origin "$PR_HEAD_SHA"

# Check if any entity files have changed compared to the base branch
git diff-index --name-only origin/$BASE_BRANCH -- $ENTITY_DIR | grep -E '\.dart$' > $TEMP_FILE || true
git diff --name-only "origin/$BASE_BRANCH...$PR_HEAD_SHA" -- $ENTITY_DIR | grep -E '\.dart$' > $TEMP_FILE || true

if [ ! -s "$TEMP_FILE" ]; then
echo "✅ No entity files changed."
Expand Down
4 changes: 4 additions & 0 deletions packages/stream_chat_persistence/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- Reduce the number of DB reads in the `ChatPersistenceClient.getChannelStates` method.

🐛 Fixed

- Fixed missing persistence of the `team` field on channel entities.

🔄 Changed

- Changed how dates are stored in the local cache, from integer seconds to ISO-8601 strings, in order to preserve millisecond precision.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DriftChatDatabase extends _$DriftChatDatabase {

// you should bump this number whenever you change or add a table definition.
@override
int get schemaVersion => 28;
int get schemaVersion => 29;

// Store DateTime as ISO-8601 text to preserve sub-second precision.
@override
Expand Down
220 changes: 105 additions & 115 deletions packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/stream_chat_persistence/lib/src/entity/channels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class Channels extends Table {
/// List of filter tags for this channel
TextColumn get filterTags => text().nullable().map(ListConverter<String>())();

/// The team the channel belongs to
TextColumn get team => text().nullable()();
Comment thread
VelikovPetar marked this conversation as resolved.

/// Map of custom channel extraData
TextColumn get extraData => text().nullable().map(MapConverter())();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extension ChannelEntityX on ChannelEntity {
deletedAt: deletedAt,
createdBy: createdBy,
filterTags: filterTags,
team: team,
Comment thread
VelikovPetar marked this conversation as resolved.
extraData: extraData ?? {},
);
}
Expand Down Expand Up @@ -60,6 +61,7 @@ extension ChannelModelX on ChannelModel {
messageCount: messageCount,
createdById: createdBy?.id,
filterTags: filterTags,
team: team,
extraData: extraData,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void main() {
createdAt: now,
memberCount: index + 3,
lastMessageAt: now.add(Duration(hours: index)),
team: 'testTeam$index',
),
).toList(growable: false);

Expand Down Expand Up @@ -124,6 +125,7 @@ void main() {
expect(updatedChannel.cid, insertedChannel.cid);
expect(updatedChannel.memberCount, insertedChannel.memberCount);
expect(updatedChannel.filterTags, insertedChannel.filterTags);
expect(updatedChannel.team, insertedChannel.team);

// Should match createdAt date
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void main() {
createdById: user.id,
filterTags: ['tag1', 'tag2'],
extraData: {'test_extra_data': 'testData'},
team: 'testTeam',
);

test('toChannelModel should map entity into ChannelModel', () {
Expand All @@ -45,6 +46,7 @@ void main() {
expect(channelModel.createdBy!.id, entity.createdById);
expect(channelModel.filterTags, entity.filterTags);
expect(channelModel.extraData, entity.extraData);
expect(channelModel.team, entity.team);
});

test('toChannelState should map entity into ChannelState ', () {
Expand Down Expand Up @@ -109,6 +111,7 @@ void main() {
createdBy: createdBy,
filterTags: ['tag1', 'tag2'],
extraData: {'test_extra_data': 'testData'},
team: 'testTeam',
);

final channelEntity = model.toEntity();
Expand All @@ -130,5 +133,6 @@ void main() {
expect(channelEntity.filterTags, model.filterTags);
expect(channelEntity.extraData, model.extraData);
expect(channelEntity.createdById, model.createdBy!.id);
expect(channelEntity.team, model.team);
});
}
Loading