forked from Ivasoft/mattermost-mobile
MM_30476 [v2] Section 'Group' of the server schema (#5072)
* MM_30476 : Added all isolated tables from the server schema * MM_30476 : Updated 'test' script in package.json * MM_30476 : ADDED team section of the server schema * MM_30476 : ADDED section for Group from the server schema * MM_30476 : One PR for one section only * MM_30476 : One PR for one section only * MM_30476 : Apply suggestions from code review Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * MM_30476 : ADDED lazy queries to group_membership model * MM_30476 : Update model to match definition - GroupsInChannel * MM_30476 : Updated all comments to match their variable/field name Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
This commit is contained in:
@@ -36,10 +36,10 @@ export default class ChannelMembership extends Model {
|
||||
@field('user_id') userId!: string;
|
||||
|
||||
/** memberChannel : The related channel this member belongs to */
|
||||
@immutableRelation(CHANNEL, 'channel_id') channel!: Relation<Channel>;
|
||||
@immutableRelation(CHANNEL, 'channel_id') memberChannel!: Relation<Channel>;
|
||||
|
||||
/** memberUser : The related member belonging to the channel */
|
||||
@immutableRelation(USER, 'user_id') user!: Relation<User>;
|
||||
@immutableRelation(USER, 'user_id') memberUser!: Relation<User>;
|
||||
|
||||
/**
|
||||
* getAllChannelsForUser - Retrieves all the channels that the user is part of
|
||||
|
||||
50
app/database/server/models/group.ts
Normal file
50
app/database/server/models/group.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import Model, {Associations} from '@nozbe/watermelondb/Model';
|
||||
import {children, field} from '@nozbe/watermelondb/decorators';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
import GroupMembership from '@typings/database/group_membership';
|
||||
import GroupsInChannel from '@typings/database/groups_in_channel';
|
||||
import GroupsInTeam from '@typings/database/groups_in_team';
|
||||
|
||||
const {GROUP, GROUPS_IN_CHANNEL, GROUPS_IN_TEAM, GROUP_MEMBERSHIP} = MM_TABLES.SERVER;
|
||||
|
||||
/**
|
||||
* The Group model unifies/assembles users, teams and channels based on a common ground. For example, a group can be
|
||||
* all users who are in the mobile team. If one needs to send that group a message, then s/he can mention the group's
|
||||
* name in the message. (e.g @mobile_team)
|
||||
*/
|
||||
export default class Group extends Model {
|
||||
/** table (entity name) : Group */
|
||||
static table = GROUP;
|
||||
|
||||
/** associations : Describes every relationship to this entity. */
|
||||
static associations: Associations = {
|
||||
|
||||
/** A GROUP has a 1:N relationship with GROUPS_IN_CHANNEL */
|
||||
[GROUPS_IN_CHANNEL]: {type: 'has_many', foreignKey: 'group_id'},
|
||||
|
||||
/** A GROUP has a 1:N relationship with GROUPS_IN_TEAM */
|
||||
[GROUPS_IN_TEAM]: {type: 'has_many', foreignKey: 'group_id'},
|
||||
|
||||
/** A GROUP has a 1:N relationship with GROUP_MEMBERSHIP */
|
||||
[GROUP_MEMBERSHIP]: {type: 'has_many', foreignKey: 'group_id'},
|
||||
};
|
||||
|
||||
/** display_name : The display name for the group */
|
||||
@field('display_name') displayName!: string;
|
||||
|
||||
/** name : The name of the group */
|
||||
@field('name') name!: string;
|
||||
|
||||
/** groupsInChannel : All the related children records from GroupsInChannel */
|
||||
@children(GROUPS_IN_CHANNEL) groupsInChannel!: GroupsInChannel[];
|
||||
|
||||
/** groupsInTeam : All the related children records from GroupsInTeam */
|
||||
@children(GROUPS_IN_TEAM) groupsInTeam!: GroupsInTeam[];
|
||||
|
||||
/** groupMemberships : All the related children records from GroupMembership */
|
||||
@children(GROUP_MEMBERSHIP) groupMemberships!: GroupMembership[];
|
||||
}
|
||||
53
app/database/server/models/group_membership.ts
Normal file
53
app/database/server/models/group_membership.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {Q, Query, Relation} from '@nozbe/watermelondb';
|
||||
import Model, {Associations} from '@nozbe/watermelondb/Model';
|
||||
import {field, immutableRelation, lazy} from '@nozbe/watermelondb/decorators';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
import Group from '@typings/database/group';
|
||||
import User from '@typings/database/user';
|
||||
|
||||
const {GROUP, GROUP_MEMBERSHIP, USER} = MM_TABLES.SERVER;
|
||||
|
||||
/**
|
||||
* The GroupMembership model represents the 'association table' where many groups have users and many users are in
|
||||
* groups (relationship type N:N)
|
||||
*/
|
||||
export default class GroupMembership extends Model {
|
||||
/** table (entity name) : GroupMembership */
|
||||
static table = GROUP_MEMBERSHIP;
|
||||
|
||||
/** associations : Describes every relationship to this entity */
|
||||
static associations: Associations = {
|
||||
|
||||
/** A GROUP can have multiple users in it */
|
||||
[GROUP]: {type: 'belongs_to', key: 'group_id'},
|
||||
|
||||
/** A USER can be part of multiple groups */
|
||||
[USER]: {type: 'belongs_to', key: 'user_id'},
|
||||
};
|
||||
|
||||
/* group_id: The foreign key to the related Group record*/
|
||||
@field('group_id') groupId!: string;
|
||||
|
||||
/* user_id: The foreign key to the related User record*/
|
||||
@field('user_id') userId!: string;
|
||||
|
||||
/** memberGroup : The related group this user belongs to */
|
||||
@immutableRelation(GROUP, 'group_id') memberGroup!: Relation<Group>;
|
||||
|
||||
/** memberUser : The related user in the group */
|
||||
@immutableRelation(USER, 'user_id') memberUser!: Relation<User>;
|
||||
|
||||
/**
|
||||
* getAllGroupsForUser : Retrieves all the groups that the user is part of
|
||||
*/
|
||||
@lazy getAllGroupsForUser = this.collections.get(GROUP).query(Q.on(USER, 'id', this.userId)) as Query<Group>
|
||||
|
||||
/**
|
||||
* getAllUsersInGroup : Retrieves all the users who are part of this group
|
||||
*/
|
||||
@lazy getAllUsersInGroup = this.collections.get(USER).query(Q.on(GROUP, 'id', this.groupId)) as Query<User>
|
||||
}
|
||||
48
app/database/server/models/groups_in_channel.ts
Normal file
48
app/database/server/models/groups_in_channel.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {Relation} from '@nozbe/watermelondb';
|
||||
import Model, {Associations} from '@nozbe/watermelondb/Model';
|
||||
import {field, immutableRelation} from '@nozbe/watermelondb/decorators';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
import Channel from '@typings/database/channel';
|
||||
import Group from '@typings/database/group';
|
||||
|
||||
const {GROUP, GROUPS_IN_CHANNEL, CHANNEL} = MM_TABLES.SERVER;
|
||||
|
||||
/**
|
||||
* The GroupsInChannel links the Channel model with the Group model
|
||||
*/
|
||||
export default class GroupsInChannel extends Model {
|
||||
/** table (entity name) : GroupsInChannel */
|
||||
static table = GROUPS_IN_CHANNEL;
|
||||
|
||||
/** associations : Describes every relationship to this entity. */
|
||||
static associations: Associations = {
|
||||
|
||||
/** A GROUP can be associated with multiple GROUPS_IN_CHANNEL (relationship is 1:N) */
|
||||
[GROUP]: {type: 'belongs_to', key: 'group_id'},
|
||||
|
||||
/** A CHANNEL can be associated with multiple GROUPS_IN_CHANNEL (relationship is 1:N) */
|
||||
[CHANNEL]: {type: 'belongs_to', key: 'channel_id'},
|
||||
};
|
||||
|
||||
/** channel_id : The foreign key of the related CHANNEL model */
|
||||
@field('channel_id') channelId!: string;
|
||||
|
||||
/** group_id : The foreign key of the related GROUP model */
|
||||
@field('group_id') groupId!: string;
|
||||
|
||||
/** member_count : The number of members in that group */
|
||||
@field('member_count') memberCount!: number;
|
||||
|
||||
/** timezone_count : The number of timezones in that group */
|
||||
@field('timezone_count') timezoneCount!: number;
|
||||
|
||||
/** channel : The related record to the parent Channel model */
|
||||
@immutableRelation(CHANNEL, 'channel_id') channel!: Relation<Channel>;
|
||||
|
||||
/** group : The related record to the parent Group model */
|
||||
@immutableRelation(GROUP, 'group_id') group!: Relation<Group>;
|
||||
}
|
||||
48
app/database/server/models/groups_in_team.ts
Normal file
48
app/database/server/models/groups_in_team.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {Relation} from '@nozbe/watermelondb';
|
||||
import Model, {Associations} from '@nozbe/watermelondb/Model';
|
||||
import {field, immutableRelation} from '@nozbe/watermelondb/decorators';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
import Group from '@typings/database/group';
|
||||
import Team from '@typings/database/team';
|
||||
|
||||
const {GROUP, GROUPS_IN_TEAM, TEAM} = MM_TABLES.SERVER;
|
||||
|
||||
/**
|
||||
* The GroupsInTeam links the Team model with the Group model
|
||||
*/
|
||||
export default class GroupsInTeam extends Model {
|
||||
/** table (entity name) : GroupsInTeam */
|
||||
static table = GROUPS_IN_TEAM;
|
||||
|
||||
/** associations : Describes every relationship to this entity. */
|
||||
static associations: Associations = {
|
||||
|
||||
/** GroupsInTeam can belong to only one Group */
|
||||
[GROUP]: {type: 'belongs_to', key: 'group_id'},
|
||||
|
||||
/** GroupsInTeam can belong to only one Team */
|
||||
[TEAM]: {type: 'belongs_to', key: 'team_id'},
|
||||
};
|
||||
|
||||
/** group_id : The foreign key to the related Group record */
|
||||
@field('group_id') groupId!: string;
|
||||
|
||||
/** member_count : The number of users in that group */
|
||||
@field('member_count') memberCount!: number;
|
||||
|
||||
/** team_id : The foreign key to the related Team record */
|
||||
@field('team_id') teamId!: string;
|
||||
|
||||
/** timezone_count : The number of timezones */
|
||||
@field('timezone_count') timezoneCount!: number;
|
||||
|
||||
/** team : The related record to the parent Team model */
|
||||
@immutableRelation(TEAM, 'team_id') team!: Relation<Team>;
|
||||
|
||||
/** group : The related record to the parent Team model */
|
||||
@immutableRelation(GROUP, 'group_id') group!: Relation<Group>;
|
||||
}
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
export {default as ChannelMembership} from './channel_membership';
|
||||
export {default as CustomEmoji} from './custom_emoji';
|
||||
export {default as GroupMembership} from './group_membership';
|
||||
export {default as GroupsInChannel} from './groups_in_channel';
|
||||
export {default as GroupsInTeam} from './groups_in_team';
|
||||
export {default as Group} from './group';
|
||||
export {default as MyTeam} from './my_team';
|
||||
export {default as Preference} from './preference';
|
||||
export {default as Reaction} from './reaction';
|
||||
|
||||
@@ -36,6 +36,6 @@ export default class MyTeam extends Model {
|
||||
/** team_id : The foreign key of the 'parent' Team entity */
|
||||
@field('team_id') teamId!: string;
|
||||
|
||||
/** teams : The relation to the entity TEAM, that this user belongs to */
|
||||
/** team : The relation to the entity TEAM, that this user belongs to */
|
||||
@relation(MY_TEAM, 'team_id') team!: Relation<Team>
|
||||
}
|
||||
|
||||
@@ -40,9 +40,9 @@ export default class Reaction extends Model {
|
||||
/** user_id : The related User's foreign key by which this reaction was expressed */
|
||||
@field('user_id') userId!: string;
|
||||
|
||||
/** reactionUser : The related record to the User model */
|
||||
/** user : The related record to the User model */
|
||||
@immutableRelation(USER, 'user_id') user!: Relation<User>;
|
||||
|
||||
/** reactionPost : The related record to the Post model */
|
||||
/** post : The related record to the Post model */
|
||||
@immutableRelation(POST, 'post_id') post!: Relation<Post>;
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@ export default class TeamSearchHistory extends Model {
|
||||
[TEAM]: {type: 'belongs_to', key: 'team_id'},
|
||||
};
|
||||
|
||||
/** createdAt : The timestamp at which this search was performed */
|
||||
/** created_at : The timestamp at which this search was performed */
|
||||
@field('created_at') createdAt!: number;
|
||||
|
||||
/** teamId : The foreign key to the parent Team model */
|
||||
/** team_id : The foreign key to the parent Team model */
|
||||
@field('team_id') teamId!: string;
|
||||
|
||||
/** displayTerm : The term that we display to the user */
|
||||
/** display_term : The term that we display to the user */
|
||||
@field('display_term') displayTerm!: string;
|
||||
|
||||
/** term : The term that is sent to the server to perform the search */
|
||||
|
||||
@@ -6,6 +6,10 @@ import {AppSchema, appSchema} from '@nozbe/watermelondb';
|
||||
import {
|
||||
ChannelMembershipSchema,
|
||||
CustomEmojiSchema,
|
||||
GroupMembershipSchema,
|
||||
GroupSchema,
|
||||
GroupsInChannelSchema,
|
||||
GroupsInTeamSchema,
|
||||
MyTeamSchema,
|
||||
PreferenceSchema,
|
||||
ReactionSchema,
|
||||
@@ -25,6 +29,10 @@ export const serverSchema: AppSchema = appSchema({
|
||||
tables: [
|
||||
ChannelMembershipSchema,
|
||||
CustomEmojiSchema,
|
||||
GroupMembershipSchema,
|
||||
GroupSchema,
|
||||
GroupsInChannelSchema,
|
||||
GroupsInTeamSchema,
|
||||
MyTeamSchema,
|
||||
PreferenceSchema,
|
||||
ReactionSchema,
|
||||
|
||||
16
app/database/server/schema/table_schemas/group.ts
Normal file
16
app/database/server/schema/table_schemas/group.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {tableSchema} from '@nozbe/watermelondb';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
|
||||
const {GROUP} = MM_TABLES.SERVER;
|
||||
|
||||
export default tableSchema({
|
||||
name: GROUP,
|
||||
columns: [
|
||||
{name: 'display_name', type: 'string'},
|
||||
{name: 'name', type: 'string'},
|
||||
],
|
||||
});
|
||||
16
app/database/server/schema/table_schemas/group_membership.ts
Normal file
16
app/database/server/schema/table_schemas/group_membership.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {tableSchema} from '@nozbe/watermelondb';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
|
||||
const {GROUP_MEMBERSHIP} = MM_TABLES.SERVER;
|
||||
|
||||
export default tableSchema({
|
||||
name: GROUP_MEMBERSHIP,
|
||||
columns: [
|
||||
{name: 'group_id', type: 'string', isIndexed: true},
|
||||
{name: 'user_id', type: 'string', isIndexed: true},
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {tableSchema} from '@nozbe/watermelondb';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
|
||||
const {GROUPS_IN_CHANNEL} = MM_TABLES.SERVER;
|
||||
|
||||
export default tableSchema({
|
||||
name: GROUPS_IN_CHANNEL,
|
||||
columns: [
|
||||
{name: 'channel_id', type: 'string', isIndexed: true},
|
||||
{name: 'group_id', type: 'string', isIndexed: true},
|
||||
{name: 'member_count', type: 'number'},
|
||||
{name: 'timezone_count', type: 'number'},
|
||||
],
|
||||
});
|
||||
18
app/database/server/schema/table_schemas/groups_in_team.ts
Normal file
18
app/database/server/schema/table_schemas/groups_in_team.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {tableSchema} from '@nozbe/watermelondb';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
|
||||
const {GROUPS_IN_TEAM} = MM_TABLES.SERVER;
|
||||
|
||||
export default tableSchema({
|
||||
name: GROUPS_IN_TEAM,
|
||||
columns: [
|
||||
{name: 'group_id', type: 'string', isIndexed: true},
|
||||
{name: 'member_count', type: 'number'},
|
||||
{name: 'team_id', type: 'string', isIndexed: true},
|
||||
{name: 'timezone_count', type: 'number'},
|
||||
],
|
||||
});
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
export {default as ChannelMembershipSchema} from './channel_membership';
|
||||
export {default as CustomEmojiSchema} from './custom_emoji';
|
||||
export {default as GroupMembershipSchema} from './group_membership';
|
||||
export {default as GroupSchema} from './group';
|
||||
export {default as GroupsInChannelSchema} from './groups_in_channel';
|
||||
export {default as GroupsInTeamSchema} from './groups_in_team';
|
||||
export {default as MyTeamSchema} from './my_team';
|
||||
export {default as PreferenceSchema} from './preference';
|
||||
export {default as ReactionSchema} from './reaction';
|
||||
|
||||
@@ -8,6 +8,10 @@ import {serverSchema} from './index';
|
||||
const {
|
||||
CHANNEL_MEMBERSHIP,
|
||||
CUSTOM_EMOJI,
|
||||
GROUP,
|
||||
GROUPS_IN_CHANNEL,
|
||||
GROUPS_IN_TEAM,
|
||||
GROUP_MEMBERSHIP,
|
||||
MY_TEAM,
|
||||
PREFERENCE,
|
||||
REACTION,
|
||||
@@ -47,6 +51,58 @@ describe('*** Test schema for SERVER database ***', () => {
|
||||
{name: 'name', type: 'string'},
|
||||
],
|
||||
},
|
||||
[GROUP]: {
|
||||
name: GROUP,
|
||||
columns: {
|
||||
display_name: {name: 'display_name', type: 'string'},
|
||||
name: {name: 'name', type: 'string'},
|
||||
},
|
||||
columnArray: [
|
||||
{name: 'display_name', type: 'string'},
|
||||
{name: 'name', type: 'string'},
|
||||
],
|
||||
},
|
||||
[GROUPS_IN_CHANNEL]: {
|
||||
name: GROUPS_IN_CHANNEL,
|
||||
columns: {
|
||||
channel_id: {name: 'channel_id', type: 'string', isIndexed: true},
|
||||
group_id: {name: 'group_id', type: 'string', isIndexed: true},
|
||||
member_count: {name: 'member_count', type: 'number'},
|
||||
timezone_count: {name: 'timezone_count', type: 'number'},
|
||||
},
|
||||
columnArray: [
|
||||
{name: 'channel_id', type: 'string', isIndexed: true},
|
||||
{name: 'group_id', type: 'string', isIndexed: true},
|
||||
{name: 'member_count', type: 'number'},
|
||||
{name: 'timezone_count', type: 'number'},
|
||||
],
|
||||
},
|
||||
[GROUPS_IN_TEAM]: {
|
||||
name: GROUPS_IN_TEAM,
|
||||
columns: {
|
||||
group_id: {name: 'group_id', type: 'string', isIndexed: true},
|
||||
member_count: {name: 'member_count', type: 'number'},
|
||||
team_id: {name: 'team_id', type: 'string', isIndexed: true},
|
||||
timezone_count: {name: 'timezone_count', type: 'number'},
|
||||
},
|
||||
columnArray: [
|
||||
{name: 'group_id', type: 'string', isIndexed: true},
|
||||
{name: 'member_count', type: 'number'},
|
||||
{name: 'team_id', type: 'string', isIndexed: true},
|
||||
{name: 'timezone_count', type: 'number'},
|
||||
],
|
||||
},
|
||||
[GROUP_MEMBERSHIP]: {
|
||||
name: GROUP_MEMBERSHIP,
|
||||
columns: {
|
||||
group_id: {name: 'group_id', type: 'string', isIndexed: true},
|
||||
user_id: {name: 'user_id', type: 'string', isIndexed: true},
|
||||
},
|
||||
columnArray: [
|
||||
{name: 'group_id', type: 'string', isIndexed: true},
|
||||
{name: 'user_id', type: 'string', isIndexed: true},
|
||||
],
|
||||
},
|
||||
[PREFERENCE]: {
|
||||
name: PREFERENCE,
|
||||
columns: {
|
||||
|
||||
Reference in New Issue
Block a user