From 763df58ef881a2f1eda244bd3fc9cdb0eb7c2844 Mon Sep 17 00:00:00 2001 From: Ashish Dhama Date: Wed, 22 Mar 2023 15:36:57 +0530 Subject: [PATCH] add files count column in channel info table and db migration --- app/actions/remote/channel.ts | 1 + app/database/migration/server/index.ts | 20 +++++++++++++++++-- app/database/models/server/channel_info.ts | 3 +++ .../server_data_operator/handlers/channel.ts | 1 + .../transformers/channel.test.ts | 1 + .../transformers/channel.ts | 1 + app/database/schema/server/index.ts | 2 +- .../server/table_schemas/channel_info.ts | 1 + app/queries/servers/channel.ts | 4 ++++ types/api/channels.d.ts | 1 + types/database/models/servers/channel_info.ts | 2 ++ types/database/raw_values.d.ts | 1 + 12 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/actions/remote/channel.ts b/app/actions/remote/channel.ts index 5d5488ed9..8f75d80b9 100644 --- a/app/actions/remote/channel.ts +++ b/app/actions/remote/channel.ts @@ -429,6 +429,7 @@ export async function fetchChannelStats(serverUrl: string, channelId: string, fe id: channelId, member_count: stats.member_count, pinned_post_count: stats.pinnedpost_count, + files_count: stats.files_count, }]; await operator.handleChannelInfo({channelInfos, prepareRecordsOnly: false}); } diff --git a/app/database/migration/server/index.ts b/app/database/migration/server/index.ts index 3c5d0ae24..cacdeaa56 100644 --- a/app/database/migration/server/index.ts +++ b/app/database/migration/server/index.ts @@ -4,6 +4,22 @@ // NOTE : To implement migration, please follow this document // https://nozbe.github.io/WatermelonDB/Advanced/Migrations.html -import {schemaMigrations} from '@nozbe/watermelondb/Schema/migrations'; +import {addColumns, schemaMigrations} from '@nozbe/watermelondb/Schema/migrations'; -export default schemaMigrations({migrations: []}); +import {MM_TABLES} from '@constants/database'; + +const {CHANNEL_INFO} = MM_TABLES.SERVER; + +export default schemaMigrations({migrations: [ + { + toVersion: 2, + steps: [ + addColumns({ + table: CHANNEL_INFO, + columns: [ + {name: 'files_count', type: 'number'}, + ], + }), + ], + }, +]}); diff --git a/app/database/models/server/channel_info.ts b/app/database/models/server/channel_info.ts index f25726863..b10a06b1e 100644 --- a/app/database/models/server/channel_info.ts +++ b/app/database/models/server/channel_info.ts @@ -37,6 +37,9 @@ export default class ChannelInfoModel extends Model implements ChannelInfoInterf /** pinned_post_count : The number of post pinned in this channel */ @field('pinned_post_count') pinnedPostCount!: number; + /** pinned_post_count : The number of files in this channel */ + @field('files_count') filesCount!: number; + /** purpose: The intention behind this channel */ @field('purpose') purpose!: string; diff --git a/app/database/operator/server_data_operator/handlers/channel.ts b/app/database/operator/server_data_operator/handlers/channel.ts index 807a35e96..c5b750721 100644 --- a/app/database/operator/server_data_operator/handlers/channel.ts +++ b/app/database/operator/server_data_operator/handlers/channel.ts @@ -188,6 +188,7 @@ const ChannelHandler = >(super ci.member_count !== e.memberCount || ci.header !== e.header || ci.pinned_post_count !== e.pinnedPostCount || + ci.files_count !== e.filesCount || ci.purpose !== e.purpose ) { res.push(ci); diff --git a/app/database/operator/server_data_operator/transformers/channel.test.ts b/app/database/operator/server_data_operator/transformers/channel.test.ts index 571bec3dc..4c4d337f2 100644 --- a/app/database/operator/server_data_operator/transformers/channel.test.ts +++ b/app/database/operator/server_data_operator/transformers/channel.test.ts @@ -103,6 +103,7 @@ describe('*** CHANNEL Prepare Records Test ***', () => { header: 'channel info header', member_count: 10, pinned_post_count: 3, + files_count: 0, purpose: 'sample channel ', }, }, diff --git a/app/database/operator/server_data_operator/transformers/channel.ts b/app/database/operator/server_data_operator/transformers/channel.ts index bc79a7ffa..4c124c691 100644 --- a/app/database/operator/server_data_operator/transformers/channel.ts +++ b/app/database/operator/server_data_operator/transformers/channel.ts @@ -101,6 +101,7 @@ export const transformChannelInfoRecord = ({action, database, value}: Transforme channelInfo.header = raw.header ?? channelInfo.header ?? ''; channelInfo.memberCount = raw.member_count ?? channelInfo.memberCount ?? 0; channelInfo.pinnedPostCount = raw.pinned_post_count ?? channelInfo.pinnedPostCount ?? 0; + channelInfo.filesCount = raw.files_count ?? channelInfo.filesCount ?? 0; channelInfo.purpose = raw.purpose ?? channelInfo.purpose ?? ''; }; diff --git a/app/database/schema/server/index.ts b/app/database/schema/server/index.ts index e5c837e4b..cf5f107ea 100644 --- a/app/database/schema/server/index.ts +++ b/app/database/schema/server/index.ts @@ -39,7 +39,7 @@ import { } from './table_schemas'; export const serverSchema: AppSchema = appSchema({ - version: 1, + version: 2, tables: [ CategorySchema, CategoryChannelSchema, diff --git a/app/database/schema/server/table_schemas/channel_info.ts b/app/database/schema/server/table_schemas/channel_info.ts index 621944188..7a97f3c52 100644 --- a/app/database/schema/server/table_schemas/channel_info.ts +++ b/app/database/schema/server/table_schemas/channel_info.ts @@ -14,6 +14,7 @@ export default tableSchema({ {name: 'header', type: 'string'}, {name: 'member_count', type: 'number'}, {name: 'pinned_post_count', type: 'number'}, + {name: 'files_count', type: 'number'}, {name: 'purpose', type: 'string'}, ], }); diff --git a/app/queries/servers/channel.ts b/app/queries/servers/channel.ts index 3fec06123..e679ea64d 100644 --- a/app/queries/servers/channel.ts +++ b/app/queries/servers/channel.ts @@ -41,6 +41,7 @@ export function prepareMissingChannelsForAllTeams(operator: ServerDataOperator, guest_count: 0, member_count: 0, pinned_post_count: 0, + files_count: 0, }); } @@ -95,12 +96,14 @@ export const prepareMyChannelsForTeam = async (operator: ServerDataOperator, tea let member_count = 0; let guest_count = 0; let pinned_post_count = 0; + let files_count = 0; if (storedChannel) { storedInfo = allChannelsInfoForTeam[c.id]; if (storedInfo) { member_count = storedInfo.memberCount; guest_count = storedInfo.guestCount; pinned_post_count = storedInfo.pinnedPostCount; + files_count = storedInfo.filesCount; } } @@ -111,6 +114,7 @@ export const prepareMyChannelsForTeam = async (operator: ServerDataOperator, tea guest_count, member_count, pinned_post_count, + files_count, }); } diff --git a/types/api/channels.d.ts b/types/api/channels.d.ts index 48ae8c1fd..26baed1ce 100644 --- a/types/api/channels.d.ts +++ b/types/api/channels.d.ts @@ -6,6 +6,7 @@ type ChannelStats = { guest_count: number; member_count: number; pinnedpost_count: number; + files_count: number; }; type NotificationLevel = 'default' | 'all' | 'mention' | 'none'; diff --git a/types/database/models/servers/channel_info.ts b/types/database/models/servers/channel_info.ts index 79d522ef3..da718b3e9 100644 --- a/types/database/models/servers/channel_info.ts +++ b/types/database/models/servers/channel_info.ts @@ -26,6 +26,8 @@ declare class ChannelInfoModel extends Model { /** pinned_post_count : The number of post pinned in this channel */ pinnedPostCount: number; + filesCount: number; + /** purpose: The intention behind this channel */ purpose: string; diff --git a/types/database/raw_values.d.ts b/types/database/raw_values.d.ts index 3d6e40a18..d059df55f 100644 --- a/types/database/raw_values.d.ts +++ b/types/database/raw_values.d.ts @@ -13,6 +13,7 @@ type ChannelInfo = { header: string; member_count: number; pinned_post_count: number; + files_count: number; purpose: string; };