forked from Ivasoft/mattermost-mobile
MM-30475 [v2] watermelondb default schema (#4977)
* MM_30475 : ADDED default schema * MM_30475 : Updated typings and references to MM_TABLES * MM_30475 : Removed the app_id (The id field will be overwritten at the time of creation.) * MM_30475 : Updated PR as per comments
This commit is contained in:
44
app/constants/database.ts
Normal file
44
app/constants/database.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
export const MM_TABLES = {
|
||||
DEFAULT: {
|
||||
APP: 'app',
|
||||
GLOBAL: 'global',
|
||||
SERVERS: 'servers',
|
||||
},
|
||||
SERVER: {
|
||||
CHANNEL: 'Channel',
|
||||
CHANNEL_INFO: 'ChannelInfo',
|
||||
CHANNEL_MEMBERSHIP: 'ChannelMembership',
|
||||
CUSTOM_EMOJI: 'CustomEmoji',
|
||||
DRAFT: 'Draft',
|
||||
FILE: 'File',
|
||||
GROUP: 'Group',
|
||||
GROUPS_IN_CHANNEL: 'GroupsInChannel',
|
||||
GROUPS_IN_TEAM: 'GroupsInTeam',
|
||||
GROUP_MEMBERSHIP: 'GroupMembership',
|
||||
MY_CHANNEL: 'MyChannel',
|
||||
MY_CHANNEL_SETTINGS: 'MyChannelSettings',
|
||||
MY_TEAM: 'MyTeam',
|
||||
POST: 'Post',
|
||||
POSTS_IN_CHANNEL: 'PostsInChannel',
|
||||
POSTS_IN_THREAD: 'PostsInThread',
|
||||
POST_METADATA: 'PostMetadata',
|
||||
PREFERENCE: 'Preference',
|
||||
REACTION: 'Reaction',
|
||||
ROLE: 'Role',
|
||||
SLASH_COMMAND: 'SlashCommand',
|
||||
SYSTEM: 'System',
|
||||
TEAM: 'Team',
|
||||
TEAM_CHANNEL_HISTORY: 'TeamChannelHistory',
|
||||
TEAM_MEMBERSHIP: 'TeamMembership',
|
||||
TEAM_SEARCH_HISTORY: 'TeamSearchHistory',
|
||||
TERMS_OF_SERVICE: 'TermsOfService',
|
||||
USER: 'User',
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
MM_TABLES,
|
||||
};
|
||||
8
app/database/default/migration/index.ts
Normal file
8
app/database/default/migration/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
// 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: []});
|
||||
14
app/database/default/models/app.ts
Normal file
14
app/database/default/models/app.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {Model} from '@nozbe/watermelondb';
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
import field from '@nozbe/watermelondb/decorators/field';
|
||||
|
||||
export default class App extends Model {
|
||||
static table = MM_TABLES.DEFAULT.APP
|
||||
|
||||
@field('build_number') buildNumber!: string
|
||||
@field('created_at') createdAt!: number
|
||||
@field('version_number') versionNumber!: string
|
||||
}
|
||||
18
app/database/default/models/global.ts
Normal file
18
app/database/default/models/global.ts
Normal file
@@ -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 {MM_TABLES} from '@constants/database';
|
||||
import field from '@nozbe/watermelondb/decorators/field';
|
||||
import json from '@nozbe/watermelondb/decorators/json';
|
||||
|
||||
export default class Global extends Model {
|
||||
static table = MM_TABLES.DEFAULT.GLOBAL
|
||||
|
||||
@field('name') name!: string
|
||||
|
||||
// TODO : add TS definitions to sanitizer function signature.
|
||||
|
||||
// TODO : atm, the return type for 'value' is string[]. However, this return type can change to string/number/etc. A broader definition will need to be applied and this return type updated accordingly.
|
||||
@json('value', (rawJson) => rawJson) value!: string[]
|
||||
}
|
||||
16
app/database/default/models/server.ts
Normal file
16
app/database/default/models/server.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
// 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/field';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
|
||||
export default class Server extends Model {
|
||||
static table = MM_TABLES.DEFAULT.SERVERS
|
||||
|
||||
@field('db_path') dbPath!: string
|
||||
@field('display_name') displayName!: string
|
||||
@field('mention_count') mentionCount!: number
|
||||
@field('unread_count') unreadCount!: number
|
||||
@field('url') url!: string
|
||||
}
|
||||
35
app/database/default/schema/index.ts
Normal file
35
app/database/default/schema/index.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
import {AppSchema, appSchema, tableSchema} from '@nozbe/watermelondb';
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
|
||||
export const defaultSchema: AppSchema = appSchema({
|
||||
version: 1,
|
||||
tables: [
|
||||
tableSchema({
|
||||
name: MM_TABLES.DEFAULT.APP,
|
||||
columns: [
|
||||
{name: 'build_number', type: 'string'},
|
||||
{name: 'created_at', type: 'number'},
|
||||
{name: 'version_number', type: 'string'},
|
||||
],
|
||||
}),
|
||||
tableSchema({
|
||||
name: MM_TABLES.DEFAULT.GLOBAL,
|
||||
columns: [
|
||||
{name: 'name', type: 'string', isIndexed: true},
|
||||
{name: 'value', type: 'string'},
|
||||
],
|
||||
}),
|
||||
tableSchema({
|
||||
name: MM_TABLES.DEFAULT.SERVERS,
|
||||
columns: [
|
||||
{name: 'db_path', type: 'string'},
|
||||
{name: 'display_name', type: 'string'},
|
||||
{name: 'mention_count', type: 'number'},
|
||||
{name: 'unread_count', type: 'number'},
|
||||
{name: 'url', type: 'string', isIndexed: true},
|
||||
],
|
||||
}),
|
||||
],
|
||||
});
|
||||
@@ -741,11 +741,11 @@ SPEC CHECKSUMS:
|
||||
UMReactNativeAdapter: 2c175f151cfe5ff011ced7bc79ccb08bf124f6c3
|
||||
UMSensorsInterface: 1df848f22690ccd23a821777f00df230fe5a28e3
|
||||
UMTaskManagerInterface: dfc62edf51844ae87dafc1fe849b594871fda1e5
|
||||
WatermelonDB: 553035ef459ca26be2dbb5a73b183d1976c47a35
|
||||
WatermelonDB: 0aa53ec3f017fd52cd953ad6e69e4eec36c04044
|
||||
XCDYouTubeKit: 79baadb0560673a67c771eba45f83e353fd12c1f
|
||||
Yoga: 7d13633d129fd179e01b8953d38d47be90db185a
|
||||
YoutubePlayer-in-WKWebView: af2f5929fc78882d94bfdfeea999b661b78d9717
|
||||
|
||||
PODFILE CHECKSUM: 93ddf37519d321c69692a52e0a30c3e7fb27b0e0
|
||||
|
||||
COCOAPODS: 1.10.0.rc.1
|
||||
COCOAPODS: 1.10.0
|
||||
|
||||
12
package-lock.json
generated
12
package-lock.json
generated
@@ -5965,6 +5965,13 @@
|
||||
"rambdax": "2.15.0",
|
||||
"rxjs": "^6.5.3",
|
||||
"sql-escape-string": "^1.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"lokijs": {
|
||||
"version": "npm:@nozbe/lokijs@1.5.10-wmelon3",
|
||||
"resolved": "https://registry.npmjs.org/@nozbe/lokijs/-/lokijs-1.5.10-wmelon3.tgz",
|
||||
"integrity": "sha512-yfuj/SzYiVVn0e3OP8vjcbekumUR62Df90deG8uH7+5nqJqTLe4HkEzlmwJfss9UE0K8PsTQLACFOUq/2aAJ2A=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@nozbe/with-observables": {
|
||||
@@ -22743,11 +22750,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"lokijs": {
|
||||
"version": "npm:@nozbe/lokijs@1.5.10-wmelon3",
|
||||
"resolved": "https://registry.npmjs.org/@nozbe/lokijs/-/lokijs-1.5.10-wmelon3.tgz",
|
||||
"integrity": "sha512-yfuj/SzYiVVn0e3OP8vjcbekumUR62Df90deG8uH7+5nqJqTLe4HkEzlmwJfss9UE0K8PsTQLACFOUq/2aAJ2A=="
|
||||
},
|
||||
"loose-envify": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"target": "esnext",
|
||||
"lib": [
|
||||
"es6"
|
||||
|
||||
9
types/database/app.d.ts
vendored
Normal file
9
types/database/app.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
import {Model} from '@nozbe/watermelondb';
|
||||
export default class App extends Model {
|
||||
static table: string;
|
||||
buildNumber: string;
|
||||
createdAt: number;
|
||||
versionNumber: string;
|
||||
}
|
||||
10
types/database/global.d.ts
vendored
Normal file
10
types/database/global.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
import {Model} from '@nozbe/watermelondb';
|
||||
export default class Global extends Model {
|
||||
static table: string;
|
||||
name: string;
|
||||
|
||||
// TODO : atm, the return type for 'value' is string[]. However, this return type can change to string/number/etc. A broader definition will need to be applied and this return type updated accordingly.
|
||||
value: string[];
|
||||
}
|
||||
11
types/database/server.d.ts
vendored
Normal file
11
types/database/server.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
import {Model} from '@nozbe/watermelondb';
|
||||
export default class Server extends Model {
|
||||
static table: string;
|
||||
dbPath: string;
|
||||
displayName: string;
|
||||
mentionCount: number;
|
||||
unreadCount: number;
|
||||
url: string;
|
||||
}
|
||||
Reference in New Issue
Block a user