forked from Ivasoft/mattermost-mobile
MM_30476 : ADDED Schema Managers
* The migration array will hold all the migration steps. * The initial app release (e.g. v2 )will have an empty array and subsequent releases (e.g. v2.1 ) will have the steps listed in that array. * On initialization, the database will perform the migration to accomodate for new columns/tables creation and while it will conserve the mobile phone's data, it will also make it conform to this new schema. * If a migration fails, the migration process will rollback any changes. This migration will be thoroughly tested in development before pushing it live.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import keyMirror from '@utils/key_mirror';
|
||||
|
||||
export const MM_TABLES = {
|
||||
DEFAULT: {
|
||||
APP: 'app',
|
||||
@@ -39,6 +41,12 @@ export const MM_TABLES = {
|
||||
},
|
||||
};
|
||||
|
||||
export const DB_NAME = keyMirror({
|
||||
DEFAULT_DATABASE: null,
|
||||
SERVER_DATABASE: null,
|
||||
});
|
||||
|
||||
export default {
|
||||
DB_NAME,
|
||||
MM_TABLES,
|
||||
};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
import {schemaMigrations} from '@nozbe/watermelondb/Schema/migrations';
|
||||
import {Migration} 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: []});
|
||||
export const migrations: Migration [] = [];
|
||||
|
||||
|
||||
22
app/database/managers/schema_manager.ts
Normal file
22
app/database/managers/schema_manager.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {SQLiteAdapterOptions} from '@nozbe/watermelondb/adapters/sqlite';
|
||||
import {defaultSchema} from '../default/schema';
|
||||
import {DB_NAME} from '@constants/database';
|
||||
import {migrations as defaultMigration} from '../default/migration';
|
||||
import {migrations as serverMigration} from '../server/migration';
|
||||
import {schemaMigrations} from '@nozbe/watermelondb/Schema/migrations';
|
||||
import {serverSchema} from '../server/schema';
|
||||
|
||||
export const default_schema_manager:SQLiteAdapterOptions = {
|
||||
dbName: DB_NAME.DEFAULT_DATABASE,
|
||||
schema: defaultSchema,
|
||||
...(defaultMigration.length > 0 && {migrations: schemaMigrations({migrations: defaultMigration})}),
|
||||
};
|
||||
|
||||
export const server_schema_manager:SQLiteAdapterOptions = {
|
||||
dbName: DB_NAME.SERVER_DATABASE,
|
||||
schema: serverSchema,
|
||||
...(serverMigration.length > 0 && {migrations: schemaMigrations({migrations: serverMigration})}),
|
||||
};
|
||||
@@ -1,8 +1,8 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
import {schemaMigrations} from '@nozbe/watermelondb/Schema/migrations';
|
||||
import {Migration} 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: []});
|
||||
export const migrations: Migration [] = [];
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import {AppSchema, appSchema, tableSchema} from '@nozbe/watermelondb';
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
|
||||
export const defaultSchema: AppSchema = appSchema({
|
||||
export const serverSchema: AppSchema = appSchema({
|
||||
version: 1,
|
||||
tables: [
|
||||
tableSchema({
|
||||
|
||||
Reference in New Issue
Block a user