forked from Ivasoft/mattermost-mobile
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:
@@ -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});
|
||||
}
|
||||
|
||||
@@ -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'},
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
]});
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 ',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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 ?? '';
|
||||
};
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ import {
|
||||
} from './table_schemas';
|
||||
|
||||
export const serverSchema: AppSchema = appSchema({
|
||||
version: 1,
|
||||
version: 2,
|
||||
tables: [
|
||||
CategorySchema,
|
||||
CategoryChannelSchema,
|
||||
|
||||
@@ -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'},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -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'},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
1
types/api/channels.d.ts
vendored
1
types/api/channels.d.ts
vendored
@@ -6,6 +6,7 @@ type ChannelStats = {
|
||||
guest_count: number;
|
||||
member_count: number;
|
||||
pinnedpost_count: number;
|
||||
files_count: number;
|
||||
};
|
||||
|
||||
type NotificationLevel = 'default' | 'all' | 'mention' | 'none';
|
||||
|
||||
1
types/api/graphql.d.ts
vendored
1
types/api/graphql.d.ts
vendored
@@ -174,6 +174,7 @@ type GQLStats = {
|
||||
guestCount: number;
|
||||
memberCount: number;
|
||||
pinnePostCount: number;
|
||||
filesCount: number;
|
||||
}
|
||||
|
||||
type GQLRole = {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
1
types/database/raw_values.d.ts
vendored
1
types/database/raw_values.d.ts
vendored
@@ -13,6 +13,7 @@ type ChannelInfo = {
|
||||
header: string;
|
||||
member_count: number;
|
||||
pinned_post_count: number;
|
||||
files_count: number;
|
||||
purpose: string;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user