[Gekidou] [Migration] Adds member_count to groups table (#6468)

* Adds member_count to groups table

* Newline
This commit is contained in:
Shaz MJ
2022-07-15 17:01:54 +10:00
committed by GitHub
parent b25f5b10b2
commit de2c240bc7
9 changed files with 26 additions and 3 deletions

View File

@@ -9,11 +9,23 @@ import {schemaMigrations, addColumns} from '@nozbe/watermelondb/Schema/migration
import {MM_TABLES} from '@constants/database';
const {SERVER: {
GROUP,
MY_CHANNEL,
THREAD,
}} = MM_TABLES;
export default schemaMigrations({migrations: [
{
toVersion: 3,
steps: [
addColumns({
table: GROUP,
columns: [
{name: 'member_count', type: 'number'},
],
}),
],
},
{
toVersion: 2,
steps: [

View File

@@ -57,6 +57,9 @@ export default class GroupModel extends Model implements GroupInterface {
/** remote_id : The remote id for the group (i.e. in a shared channel) */
@field('remote_id') remoteId!: string;
/** member_count : The number of members in the group */
@field('member_count') memberCount!: number;
/** created_at : The creation date for this row */
@field('created_at') createdAt!: number;

View File

@@ -23,6 +23,7 @@ describe('*** GROUP Prepare Records Test ***', () => {
name: 'recent',
source: 'custom',
remote_id: 'custom',
member_count: 10,
} as Group,
},
});

View File

@@ -35,6 +35,7 @@ export const transformGroupRecord = ({action, database, value}: TransformerArgs)
group.displayName = raw.display_name;
group.source = raw.source;
group.remoteId = raw.remote_id;
group.memberCount = raw.member_count || 0;
};
return prepareBaseRecord({

View File

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

View File

@@ -18,5 +18,6 @@ export default tableSchema({
{name: 'created_at', type: 'number'},
{name: 'updated_at', type: 'number'},
{name: 'deleted_at', type: 'number'},
{name: 'member_count', type: 'number'},
],
});

View File

@@ -43,7 +43,7 @@ const {
describe('*** Test schema for SERVER database ***', () => {
it('=> The SERVER SCHEMA should strictly match', () => {
expect(serverSchema).toEqual({
version: 2,
version: 3,
tables: {
[CATEGORY]: {
name: CATEGORY,
@@ -257,6 +257,7 @@ describe('*** Test schema for SERVER database ***', () => {
created_at: {name: 'created_at', type: 'number'},
updated_at: {name: 'updated_at', type: 'number'},
deleted_at: {name: 'deleted_at', type: 'number'},
member_count: {name: 'member_count', type: 'number'},
},
columnArray: [
{name: 'display_name', type: 'string'},
@@ -267,6 +268,7 @@ describe('*** Test schema for SERVER database ***', () => {
{name: 'created_at', type: 'number'},
{name: 'updated_at', type: 'number'},
{name: 'deleted_at', type: 'number'},
{name: 'member_count', type: 'number'},
],
},
[GROUP_CHANNEL]: {

View File

@@ -8,7 +8,7 @@ type Group = {
description: string;
source: string;
remote_id: string;
member_count: number;
member_count?: number;
allow_reference: boolean;
create_at: number;
update_at: number;

View File

@@ -43,6 +43,9 @@ export default class GroupModel extends Model {
/** deleted_at : The timestamp for when it was deleted */
deletedAt: number;
/** member_count : The number of members in the group */
memberCount: number;
/** channels : All the channels associated with this group */
@lazy channels: Query<ChannelModel>;