Merge pull request #7227 from mattermost/MM-44655_add-files-count-column-in-channel-info-table

[MM-44655 ]: Add files_count column in ChannelInfo table and DB migration
This commit is contained in:
Ashish Dhama
2023-03-29 23:04:54 +05:30
committed by GitHub
16 changed files with 43 additions and 5 deletions

View File

@@ -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});
}

View File

@@ -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'},
],
}),
],
},
]});

View File

@@ -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;
/** files_count : The number of files in this channel */
@field('files_count') filesCount!: number;
/** purpose: The intention behind this channel */
@field('purpose') purpose!: string;

View File

@@ -188,6 +188,7 @@ const ChannelHandler = <TBase extends Constructor<ServerDataOperatorBase>>(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);

View File

@@ -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 ',
},
},

View File

@@ -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 ?? '';
};

View File

@@ -39,7 +39,7 @@ import {
} from './table_schemas';
export const serverSchema: AppSchema = appSchema({
version: 1,
version: 2,
tables: [
CategorySchema,
CategoryChannelSchema,

View File

@@ -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'},
],
});

View File

@@ -45,7 +45,7 @@ const {
describe('*** Test schema for SERVER database ***', () => {
it('=> The SERVER SCHEMA should strictly match', () => {
expect(serverSchema).toEqual({
version: 1,
version: 2,
unsafeSql: undefined,
tables: {
[CATEGORY]: {
@@ -92,6 +92,7 @@ describe('*** Test schema for SERVER database ***', () => {
header: {name: 'header', type: 'string'},
member_count: {name: 'member_count', type: 'number'},
pinned_post_count: {name: 'pinned_post_count', type: 'number'},
files_count: {name: 'files_count', type: 'number'},
purpose: {name: 'purpose', type: 'string'},
},
columnArray: [
@@ -99,6 +100,7 @@ describe('*** Test schema for SERVER database ***', () => {
{name: 'header', type: 'string'},
{name: 'member_count', type: 'number'},
{name: 'pinned_post_count', type: 'number'},
{name: 'files_count', type: 'number'},
{name: 'purpose', type: 'string'},
],
},

View File

@@ -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,
});
}

View File

@@ -172,6 +172,7 @@ export const gqlToClientChannelStats = (s: Partial<GQLChannel>): ChannelStats =>
guest_count: s.stats?.guestCount || 0,
member_count: s.stats?.memberCount || 0,
pinnedpost_count: s.stats?.pinnePostCount || 0,
files_count: s.stats?.filesCount || 0,
};
};

View File

@@ -1,4 +1,4 @@
# Server Database - Schema Version 1
# Server Database - Schema Version 2
# Please bump the version by 1, any time the schema changes.
# Also, include the migration plan under app/database/migration/server,
# update all models, relationships and types.
@@ -48,6 +48,7 @@ guest_count number
header string
member_count number
pinned_post_count number
files_count number
purpose string
ChannelMembership

View File

@@ -6,6 +6,7 @@ type ChannelStats = {
guest_count: number;
member_count: number;
pinnedpost_count: number;
files_count: number;
};
type NotificationLevel = 'default' | 'all' | 'mention' | 'none';

View File

@@ -174,6 +174,7 @@ type GQLStats = {
guestCount: number;
memberCount: number;
pinnePostCount: number;
filesCount: number;
}
type GQLRole = {

View File

@@ -26,6 +26,9 @@ declare class ChannelInfoModel extends Model {
/** pinned_post_count : The number of post pinned in this channel */
pinnedPostCount: number;
/** files_count : The number of files in this channel */
filesCount: number;
/** purpose: The intention behind this channel */
purpose: string;

View File

@@ -13,6 +13,7 @@ type ChannelInfo = {
header: string;
member_count: number;
pinned_post_count: number;
files_count: number;
purpose: string;
};