mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 05:46:00 +00:00
fix: restore backup before 1.0 (#4228)
* fix: restore backup before 1.0 * chore: test * chore: test * chore: rename plugins
This commit is contained in:
parent
9c4fde6ed6
commit
9e37140197
@ -30,6 +30,20 @@ describe('dumper', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.skip('should restore from version 0.21 backup file', async () => {
|
||||
const file = path.resolve(__dirname, 'files', 'backup_20240429_110942_7061.nbdump');
|
||||
|
||||
const restorer = new Restorer(app, {
|
||||
backUpFilePath: file,
|
||||
});
|
||||
|
||||
const { dumpableCollectionsGroupByGroup } = await restorer.parseBackupFile();
|
||||
|
||||
await restorer.restore({
|
||||
groups: new Set(Object.keys(dumpableCollectionsGroupByGroup)),
|
||||
});
|
||||
});
|
||||
|
||||
it('should write sql content', async () => {
|
||||
const dumper = new Dumper(app);
|
||||
|
||||
@ -422,7 +436,8 @@ describe('dumper', () => {
|
||||
await db.getRepository('collections').create({
|
||||
values: {
|
||||
name: 'tests',
|
||||
sql: `select count(*) as count from ${userCollection.getTableNameWithSchemaAsString()}`,
|
||||
sql: `select count(*) as count
|
||||
from ${userCollection.getTableNameWithSchemaAsString()}`,
|
||||
fields: [
|
||||
{
|
||||
type: 'integer',
|
||||
|
@ -16,6 +16,35 @@ type RestoreOptions = {
|
||||
groups: Set<DumpRulesGroupType>;
|
||||
};
|
||||
|
||||
const renamePlugins = async (app) => {
|
||||
const names = {
|
||||
oidc: '@nocobase/plugin-auth-oidc',
|
||||
cas: '@nocobase/plugin-auth-cas',
|
||||
saml: '@nocobase/plugin-auth-saml',
|
||||
'collection-manager': '@nocobase/plugin-data-source-main',
|
||||
'china-region': '@nocobase/plugin-field-china-region',
|
||||
'custom-request': '@nocobase/plugin-action-custom-request',
|
||||
export: '@nocobase/plugin-action-export',
|
||||
import: '@nocobase/plugin-action-import',
|
||||
'formula-field': '@nocobase/plugin-field-formula',
|
||||
'iframe-block': '@nocobase/plugin-block-iframe',
|
||||
'localization-management': '@nocobase/plugin-localization',
|
||||
'sequence-field': '@nocobase/plugin-field-sequence',
|
||||
'sms-auth': '@nocobase/plugin-auth-sms',
|
||||
};
|
||||
for (const original of Object.keys(names)) {
|
||||
await app.pm.repository.update({
|
||||
filter: {
|
||||
name: original,
|
||||
},
|
||||
values: {
|
||||
name: names[original].replace('@nocobase/plugin-', ''),
|
||||
packageName: names[original],
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export class Restorer extends AppMigrator {
|
||||
direction = 'restore' as const;
|
||||
backUpFilePath: string;
|
||||
@ -120,17 +149,22 @@ export class Restorer extends AppMigrator {
|
||||
});
|
||||
};
|
||||
|
||||
const preImportCollections = ['applicationPlugins'];
|
||||
const { dumpableCollectionsGroupByGroup, delayCollections } = await this.parseBackupFile();
|
||||
|
||||
// import plugins
|
||||
await importCollection('applicationPlugins');
|
||||
// import pre import collections
|
||||
for (const collectionName of preImportCollections) {
|
||||
await importCollection(collectionName);
|
||||
}
|
||||
|
||||
await renamePlugins(this.app);
|
||||
await this.app.reload();
|
||||
|
||||
// import required collections
|
||||
const metaCollections = dumpableCollectionsGroupByGroup.required;
|
||||
|
||||
for (const collection of metaCollections) {
|
||||
if (collection.name === 'applicationPlugins') {
|
||||
if (preImportCollections.includes(collection.name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user