Remove uneeded database migrations (#6985)

This commit is contained in:
Daniel Espino García
2023-01-19 16:56:30 +01:00
committed by GitHub
parent 2597e06ac2
commit 9c19e4d04a
4 changed files with 4 additions and 60 deletions

View File

@@ -52,7 +52,6 @@ export const MIGRATION_EVENTS = keyMirror({
});
export const SYSTEM_IDENTIFIERS = {
CONFIG: 'config',
CURRENT_CHANNEL_ID: 'currentChannelId',
LAST_UNREAD_CHANNEL_ID: 'lastUnreadChannelId',
CURRENT_TEAM_ID: 'currentTeamId',

View File

@@ -8,7 +8,7 @@ import {DeviceEventEmitter, Platform} from 'react-native';
import DeviceInfo from 'react-native-device-info';
import FileSystem from 'react-native-fs';
import {DatabaseType, MIGRATION_EVENTS, MM_TABLES, SYSTEM_IDENTIFIERS} from '@constants/database';
import {DatabaseType, MIGRATION_EVENTS, MM_TABLES} from '@constants/database';
import AppDatabaseMigrations from '@database/migration/app';
import ServerDatabaseMigrations from '@database/migration/server';
import {InfoModel, GlobalModel, ServersModel} from '@database/models/app';
@@ -24,12 +24,10 @@ import {schema as appSchema} from '@database/schema/app';
import {serverSchema} from '@database/schema/server';
import {beforeUpgrade} from '@helpers/database/upgrade';
import {getActiveServer, getServer, getServerByIdentifier} from '@queries/app/servers';
import {querySystemValue} from '@queries/servers/system';
import {deleteLegacyFileCache} from '@utils/file';
import {emptyFunction} from '@utils/general';
import {logDebug, logError} from '@utils/log';
import {deleteIOSDatabase, getIOSAppGroupDetails, renameIOSDatabase} from '@utils/mattermost_managed';
import {hashCode_DEPRECATED, urlSafeBase64Encode} from '@utils/security';
import {urlSafeBase64Encode} from '@utils/security';
import {removeProtocol} from '@utils/url';
import type {AppDatabase, CreateServerDatabaseArgs, RegisterServerDatabaseArgs, Models, ServerDatabase, ServerDatabases} from '@typings/database/database';
@@ -133,12 +131,6 @@ class DatabaseManager {
if (serverUrl) {
try {
const databaseName = urlSafeBase64Encode(serverUrl);
const oldDatabaseName = hashCode_DEPRECATED(serverUrl);
// Remove any legacy database we may already have.
await this.renameDatabase(oldDatabaseName, databaseName);
deleteLegacyFileCache(serverUrl);
const databaseFilePath = this.getDatabaseFilePath(databaseName);
const migrations = ServerDatabaseMigrations;
const modelClasses = this.serverModels;
@@ -181,38 +173,13 @@ class DatabaseManager {
* @returns {Promise<void>}
*/
private initServerDatabase = async (serverUrl: string): Promise<void> => {
const serverDatabase = await this.createServerDatabase({
await this.createServerDatabase({
config: {
dbName: serverUrl,
dbType: DatabaseType.SERVER,
serverUrl,
},
});
// Migration for config
if (serverDatabase) {
const {database, operator} = serverDatabase;
const oldConfigList = await querySystemValue(database, SYSTEM_IDENTIFIERS.CONFIG).fetch();
if (oldConfigList.length) {
const oldConfigModel = oldConfigList[0];
const oldConfig = oldConfigModel.value as ClientConfig;
const configs = [];
let k: keyof ClientConfig;
for (k in oldConfig) {
// Check to silence eslint (guard-for-in)
if (Object.prototype.hasOwnProperty.call(oldConfig, k)) {
configs.push({
id: k,
value: oldConfig[k],
});
}
}
const models = await operator.handleConfigs({configs, configsToDelete: [], prepareRecordsOnly: true});
operator.batchRecords([...models, oldConfigModel.prepareDestroyPermanently()]);
}
}
};
/**

View File

@@ -18,7 +18,7 @@ import {generateId} from '@utils/general';
import keyMirror from '@utils/key_mirror';
import {logError} from '@utils/log';
import {deleteEntititesFile, getIOSAppGroupDetails} from '@utils/mattermost_managed';
import {hashCode_DEPRECATED, urlSafeBase64Encode} from '@utils/security';
import {urlSafeBase64Encode} from '@utils/security';
import type FileModel from '@typings/database/models/servers/file';
@@ -169,11 +169,6 @@ export async function deleteFileCache(serverUrl: string) {
return deleteFileCacheByDir(serverDir);
}
export async function deleteLegacyFileCache(serverUrl: string) {
const serverDir = hashCode_DEPRECATED(serverUrl);
return deleteFileCacheByDir(serverDir);
}
export async function deleteFileCacheByDir(dir: string) {
if (Platform.OS === 'ios') {
const appGroupCacheDir = `${getIOSAppGroupDetails().appGroupSharedDirectory}/Library/Caches/${dir}`;

View File

@@ -9,23 +9,6 @@ export async function getCSRFFromCookie(url: string) {
return cookies.MMCSRF?.value;
}
// This has been deprecated and is only used for migrations
export const hashCode_DEPRECATED = (str: string): string => {
let hash = 0;
let i;
let chr;
if (!str || str.length === 0) {
return hash.toString();
}
for (i = 0; i < str.length; i++) {
chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash.toString();
};
export const urlSafeBase64Encode = (str: string): string => {
return base64.encode(str).replace(/\+/g, '-').replace(/\//g, '_');
};