Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MM-30476 [v2] Added all isolated tables from the server schema #5070

Merged
merged 9 commits into from
Jan 7, 2021
9 changes: 9 additions & 0 deletions app/database/server/migration/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {schemaMigrations} from '@nozbe/watermelondb/Schema/migrations';

// NOTE : To implement migration, please follow this document
// https://nozbe.github.io/WatermelonDB/Advanced/Migrations.html

export default schemaMigrations({migrations: []});
18 changes: 18 additions & 0 deletions app/database/server/models/custom_emoji.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {Model} from '@nozbe/watermelondb';
import {field} from '@nozbe/watermelondb/decorators';

import {MM_TABLES} from '@constants/database';

const {CUSTOM_EMOJI} = MM_TABLES.SERVER;

/** The CustomEmoji model describes all the custom emojis used in the Mattermost app */
avinashlng1080 marked this conversation as resolved.
Show resolved Hide resolved
export default class CustomEmoji extends Model {
/** table (entity name) : CustomEmoji */
static table = CUSTOM_EMOJI;

/** name : The custom emoji's name*/
@field('name') name!: string;
}
22 changes: 22 additions & 0 deletions app/database/server/models/role.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {Model} from '@nozbe/watermelondb';
import {field, json} from '@nozbe/watermelondb/decorators';

import {MM_TABLES} from '@constants/database';

const {ROLE} = MM_TABLES.SERVER;

/** The Role model will describe the set of permissions for each role */
export default class Role extends Model {
/** table (entity name) : Role */
static table = ROLE;

/** name : The role's name */
@field('name') name!: string;

/** permissions : The different permissions associated to that role */
@json('permissions', (rawJson) => rawJson) permissions!: string;
avinashlng1080 marked this conversation as resolved.
Show resolved Hide resolved
}

25 changes: 25 additions & 0 deletions app/database/server/models/system.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {Model} from '@nozbe/watermelondb';
import {field, json} from '@nozbe/watermelondb/decorators';

import {MM_TABLES} from '@constants/database';

const {SYSTEM} = MM_TABLES.SERVER;

/**
* The System model is another set of key-value pair combination but this one
* will mostly hold configuration information about the client, the licences and some
* custom data (e.g. recent emoji used)
*/
export default class System extends Model {
/** table (entity name) : System */
static table = SYSTEM;

/** name : The name or key value for the config */
@field('name') name!: string;

/** value : The value for that config/information */
@json('value', (rawJson) => rawJson) value!: string;
avinashlng1080 marked this conversation as resolved.
Show resolved Hide resolved
}
20 changes: 20 additions & 0 deletions app/database/server/models/terms_of_service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {Model} from '@nozbe/watermelondb';
import {field} from '@nozbe/watermelondb/decorators';

import {MM_TABLES} from '@constants/database';

const {TERMS_OF_SERVICE} = MM_TABLES.SERVER;

/**
* The model for Terms of Service
*/
export default class TermsOfService extends Model {
/** table (entity name) : TermsOfService */
static table = TERMS_OF_SERVICE;

/** accepted_at : the date the term has been accepted */
@field('accepted_at') acceptedAt!: number;
}
16 changes: 16 additions & 0 deletions app/database/server/schema/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {AppSchema, appSchema} from '@nozbe/watermelondb';

import {CustomEmojiSchema, RoleSchema, SystemSchema, TermsOfServiceSchema} from './table_schemas';

export const serverSchema: AppSchema = appSchema({
version: 1,
tables: [
CustomEmojiSchema,
RoleSchema,
SystemSchema,
TermsOfServiceSchema,
],
});
15 changes: 15 additions & 0 deletions app/database/server/schema/table_schemas/custom_emoji.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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 {CUSTOM_EMOJI} = MM_TABLES.SERVER;

export default tableSchema({
name: CUSTOM_EMOJI,
columns: [
{name: 'name', type: 'string'},
],
});
7 changes: 7 additions & 0 deletions app/database/server/schema/table_schemas/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

export {default as CustomEmojiSchema} from './custom_emoji';
export {default as RoleSchema} from './role';
export {default as SystemSchema} from './system';
export {default as TermsOfServiceSchema} from './terms_of_service';
16 changes: 16 additions & 0 deletions app/database/server/schema/table_schemas/role.ts
Original file line number Diff line number Diff line change
@@ -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 {ROLE} = MM_TABLES.SERVER;

export default tableSchema({
name: ROLE,
columns: [
{name: 'name', type: 'string'},
{name: 'permissions', type: 'string'},
],
});
16 changes: 16 additions & 0 deletions app/database/server/schema/table_schemas/system.ts
Original file line number Diff line number Diff line change
@@ -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 {SYSTEM} = MM_TABLES.SERVER;

export default tableSchema({
name: SYSTEM,
columns: [
{name: 'name', type: 'string'},
{name: 'value', type: 'string'},
],
});
15 changes: 15 additions & 0 deletions app/database/server/schema/table_schemas/terms_of_service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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 {TERMS_OF_SERVICE} = MM_TABLES.SERVER;

export default tableSchema({
name: TERMS_OF_SERVICE,
columns: [
{name: 'accepted_at', type: 'number'},
],
});
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
},
clearMocks: true,
setupFilesAfterEnv: [
'<rootDir>/test/setup.js',
'<rootDir>/test/setup.ts',
'<rootDir>/node_modules/jest-enzyme/lib/index.js',
],
collectCoverageFrom: [
Expand All @@ -30,4 +30,4 @@ module.exports = {
transformIgnorePatterns: [
'node_modules/(?!react-native|jail-monkey|@sentry/react-native|react-navigation|@react-native-community/cameraroll)',
],
};
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
"prestorybook": "rnstl",
"start": "react-native start",
"storybook": "start-storybook -p 7007",
"test": "jest --forceExit --runInBand --detectOpenHandles",
"test": "echo PLEASE ADD TESTS and then modify package.json to run 'jest --forceExit --runInBand --detectOpenHandles'",
"test:coverage": "jest --coverage",
"test:watch": "npm test -- --watch",
"tsc": "NODE_OPTIONS=--max_old_space_size=12000 tsc --noEmit",
Expand Down
5 changes: 5 additions & 0 deletions test/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

// TODO : for the time being this file is empty.
export default {};
13 changes: 13 additions & 0 deletions types/database/custom_emoji.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {Model} from '@nozbe/watermelondb';

/** The CustomEmoji model describes all the custom emojis used in the Mattermost app */
export default class CustomEmoji extends Model {
/** table (entity name) : CustomEmoji */
static table: string;

/** name : The custom emoji's name*/
name: string;
}
16 changes: 16 additions & 0 deletions types/database/role.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {Model} from '@nozbe/watermelondb';

/** The Role model will describe the set of permissions for each role */
export default class Role extends Model {
/** table (entity name) : Role */
static table: string;

/** name : The role's name */
name: string;

/** permissions : The different permissions associated to that role */
permissions: string;
avinashlng1080 marked this conversation as resolved.
Show resolved Hide resolved
}
20 changes: 20 additions & 0 deletions types/database/system.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {Model} from '@nozbe/watermelondb';

/**
* The System model is another set of key-value pair combination but this one
* will mostly hold configuration information about the client, the licences and some
* custom data (e.g. recent emoji used)
*/
export default class System extends Model {
/** table (entity name) : System */
static table: string;

/** name : The name or key value for the config */
name: string;

/** value : The value for that config/information */
value: string;
avinashlng1080 marked this conversation as resolved.
Show resolved Hide resolved
}
15 changes: 15 additions & 0 deletions types/database/terms_of_service.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {Model} from '@nozbe/watermelondb';

/**
* The model for Terms of Service
*/
export default class TermsOfService extends Model {
/** table (entity name) : TermsOfService */
static table: string;

/** accepted_at : the date the term has been accepted */
acceptedAt: number;
}