@nocobase/plugin-backup-restore 1.2.12-alpha → 1.3.0-alpha.20240710084543
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/dist/client/Configuration.d.ts +0 -10
- package/dist/client/DuplicatorProvider.d.ts +0 -10
- package/dist/client/index.d.ts +0 -13
- package/dist/client/index.js +0 -10
- package/dist/client/locale/index.d.ts +0 -12
- package/dist/externalVersion.js +0 -23
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -48
- package/dist/locale/en-US.json +0 -44
- package/dist/locale/ja-JP.d.ts +0 -33
- package/dist/locale/ja-JP.js +0 -55
- package/dist/locale/ko_KR.json +0 -50
- package/dist/locale/pt-BR.d.ts +0 -34
- package/dist/locale/pt-BR.js +0 -57
- package/dist/locale/zh-CN.json +0 -50
- package/dist/node_modules/@hapi/topo/lib/index.d.ts +0 -60
- package/dist/node_modules/@hapi/topo/lib/index.js +0 -1
- package/dist/node_modules/@hapi/topo/package.json +0 -1
- package/dist/node_modules/archiver/LICENSE +0 -22
- package/dist/node_modules/archiver/index.js +0 -68
- package/dist/node_modules/archiver/lib/core.js +0 -974
- package/dist/node_modules/archiver/lib/error.js +0 -40
- package/dist/node_modules/archiver/lib/plugins/json.js +0 -110
- package/dist/node_modules/archiver/lib/plugins/tar.js +0 -167
- package/dist/node_modules/archiver/lib/plugins/zip.js +0 -120
- package/dist/node_modules/archiver/node_modules/readable-stream/errors-browser.js +0 -127
- package/dist/node_modules/archiver/node_modules/readable-stream/errors.js +0 -116
- package/dist/node_modules/archiver/node_modules/readable-stream/experimentalWarning.js +0 -17
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_duplex.js +0 -126
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_passthrough.js +0 -37
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_readable.js +0 -1027
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_transform.js +0 -190
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_writable.js +0 -641
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/async_iterator.js +0 -180
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/buffer_list.js +0 -183
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/destroy.js +0 -96
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +0 -86
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/from-browser.js +0 -3
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/from.js +0 -52
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/pipeline.js +0 -86
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/state.js +0 -22
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/stream-browser.js +0 -1
- package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/stream.js +0 -1
- package/dist/node_modules/archiver/node_modules/readable-stream/package.json +0 -68
- package/dist/node_modules/archiver/node_modules/readable-stream/readable-browser.js +0 -9
- package/dist/node_modules/archiver/node_modules/readable-stream/readable.js +0 -16
- package/dist/node_modules/archiver/node_modules/string_decoder/lib/string_decoder.js +0 -296
- package/dist/node_modules/archiver/node_modules/string_decoder/package.json +0 -34
- package/dist/node_modules/archiver/node_modules/tar-stream/extract.js +0 -257
- package/dist/node_modules/archiver/node_modules/tar-stream/headers.js +0 -295
- package/dist/node_modules/archiver/node_modules/tar-stream/index.js +0 -2
- package/dist/node_modules/archiver/node_modules/tar-stream/pack.js +0 -255
- package/dist/node_modules/archiver/node_modules/tar-stream/package.json +0 -58
- package/dist/node_modules/archiver/node_modules/tar-stream/sandbox.js +0 -11
- package/dist/node_modules/archiver/package.json +0 -1
- package/dist/node_modules/decompress/index.js +0 -16
- package/dist/node_modules/decompress/license +0 -9
- package/dist/node_modules/decompress/node_modules/make-dir/index.js +0 -85
- package/dist/node_modules/decompress/node_modules/make-dir/license +0 -9
- package/dist/node_modules/decompress/node_modules/make-dir/node_modules/pify/index.js +0 -84
- package/dist/node_modules/decompress/node_modules/make-dir/node_modules/pify/license +0 -9
- package/dist/node_modules/decompress/node_modules/make-dir/node_modules/pify/package.json +0 -51
- package/dist/node_modules/decompress/node_modules/make-dir/package.json +0 -54
- package/dist/node_modules/decompress/package.json +0 -1
- package/dist/node_modules/mkdirp/LICENSE +0 -21
- package/dist/node_modules/mkdirp/bin/cmd.js +0 -68
- package/dist/node_modules/mkdirp/index.js +0 -1
- package/dist/node_modules/mkdirp/lib/find-made.js +0 -29
- package/dist/node_modules/mkdirp/lib/mkdirp-manual.js +0 -64
- package/dist/node_modules/mkdirp/lib/mkdirp-native.js +0 -39
- package/dist/node_modules/mkdirp/lib/opts-arg.js +0 -23
- package/dist/node_modules/mkdirp/lib/path-arg.js +0 -29
- package/dist/node_modules/mkdirp/lib/use-native.js +0 -10
- package/dist/node_modules/mkdirp/package.json +0 -1
- package/dist/node_modules/mkdirp/readme.markdown +0 -266
- package/dist/node_modules/semver/LICENSE +0 -15
- package/dist/node_modules/semver/bin/semver.js +0 -197
- package/dist/node_modules/semver/classes/comparator.js +0 -141
- package/dist/node_modules/semver/classes/index.js +0 -5
- package/dist/node_modules/semver/classes/range.js +0 -539
- package/dist/node_modules/semver/classes/semver.js +0 -302
- package/dist/node_modules/semver/functions/clean.js +0 -6
- package/dist/node_modules/semver/functions/cmp.js +0 -52
- package/dist/node_modules/semver/functions/coerce.js +0 -52
- package/dist/node_modules/semver/functions/compare-build.js +0 -7
- package/dist/node_modules/semver/functions/compare-loose.js +0 -3
- package/dist/node_modules/semver/functions/compare.js +0 -5
- package/dist/node_modules/semver/functions/diff.js +0 -65
- package/dist/node_modules/semver/functions/eq.js +0 -3
- package/dist/node_modules/semver/functions/gt.js +0 -3
- package/dist/node_modules/semver/functions/gte.js +0 -3
- package/dist/node_modules/semver/functions/inc.js +0 -19
- package/dist/node_modules/semver/functions/lt.js +0 -3
- package/dist/node_modules/semver/functions/lte.js +0 -3
- package/dist/node_modules/semver/functions/major.js +0 -3
- package/dist/node_modules/semver/functions/minor.js +0 -3
- package/dist/node_modules/semver/functions/neq.js +0 -3
- package/dist/node_modules/semver/functions/parse.js +0 -16
- package/dist/node_modules/semver/functions/patch.js +0 -3
- package/dist/node_modules/semver/functions/prerelease.js +0 -6
- package/dist/node_modules/semver/functions/rcompare.js +0 -3
- package/dist/node_modules/semver/functions/rsort.js +0 -3
- package/dist/node_modules/semver/functions/satisfies.js +0 -10
- package/dist/node_modules/semver/functions/sort.js +0 -3
- package/dist/node_modules/semver/functions/valid.js +0 -6
- package/dist/node_modules/semver/index.js +0 -1
- package/dist/node_modules/semver/internal/constants.js +0 -35
- package/dist/node_modules/semver/internal/debug.js +0 -9
- package/dist/node_modules/semver/internal/identifiers.js +0 -23
- package/dist/node_modules/semver/internal/parse-options.js +0 -15
- package/dist/node_modules/semver/internal/re.js +0 -212
- package/dist/node_modules/semver/package.json +0 -1
- package/dist/node_modules/semver/preload.js +0 -2
- package/dist/node_modules/semver/range.bnf +0 -16
- package/dist/node_modules/semver/ranges/gtr.js +0 -4
- package/dist/node_modules/semver/ranges/intersects.js +0 -7
- package/dist/node_modules/semver/ranges/ltr.js +0 -4
- package/dist/node_modules/semver/ranges/max-satisfying.js +0 -25
- package/dist/node_modules/semver/ranges/min-satisfying.js +0 -24
- package/dist/node_modules/semver/ranges/min-version.js +0 -61
- package/dist/node_modules/semver/ranges/outside.js +0 -80
- package/dist/node_modules/semver/ranges/simplify.js +0 -47
- package/dist/node_modules/semver/ranges/subset.js +0 -247
- package/dist/node_modules/semver/ranges/to-comparators.js +0 -8
- package/dist/node_modules/semver/ranges/valid.js +0 -11
- package/dist/server/app-migrator.d.ts +0 -25
- package/dist/server/app-migrator.js +0 -70
- package/dist/server/commands/restore-command.d.ts +0 -10
- package/dist/server/commands/restore-command.js +0 -77
- package/dist/server/dumper.d.ts +0 -79
- package/dist/server/dumper.js +0 -420
- package/dist/server/errors/restore-check-error.d.ts +0 -11
- package/dist/server/errors/restore-check-error.js +0 -41
- package/dist/server/field-value-writer.d.ts +0 -17
- package/dist/server/field-value-writer.js +0 -110
- package/dist/server/index.d.ts +0 -9
- package/dist/server/index.js +0 -42
- package/dist/server/locale/zh-CN.d.ts +0 -17
- package/dist/server/locale/zh-CN.js +0 -39
- package/dist/server/migrations/20240618103927-update-snippet-name.d.ts +0 -14
- package/dist/server/migrations/20240618103927-update-snippet-name.js +0 -60
- package/dist/server/resourcers/backup-files.d.ts +0 -33
- package/dist/server/resourcers/backup-files.js +0 -202
- package/dist/server/restorer.d.ts +0 -43
- package/dist/server/restorer.js +0 -363
- package/dist/server/server.d.ts +0 -13
- package/dist/server/server.js +0 -54
- package/dist/server/utils.d.ts +0 -13
- package/dist/server/utils.js +0 -87
- package/dist/swagger/index.d.ts +0 -400
- package/dist/swagger/index.js +0 -456
package/dist/server/restorer.js
DELETED
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __export = (target, all) => {
|
|
17
|
-
for (var name in all)
|
|
18
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
-
};
|
|
20
|
-
var __copyProps = (to, from, except, desc) => {
|
|
21
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
-
for (let key of __getOwnPropNames(from))
|
|
23
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
-
}
|
|
26
|
-
return to;
|
|
27
|
-
};
|
|
28
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
-
mod
|
|
35
|
-
));
|
|
36
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
-
var restorer_exports = {};
|
|
38
|
-
__export(restorer_exports, {
|
|
39
|
-
Restorer: () => Restorer
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(restorer_exports);
|
|
42
|
-
var import_decompress = __toESM(require("decompress"));
|
|
43
|
-
var import_fs = __toESM(require("fs"));
|
|
44
|
-
var import_promises = __toESM(require("fs/promises"));
|
|
45
|
-
var import_path = __toESM(require("path"));
|
|
46
|
-
var import_app_migrator = require("./app-migrator");
|
|
47
|
-
var import_utils = require("./utils");
|
|
48
|
-
var import_database = require("@nocobase/database");
|
|
49
|
-
var import_lodash = __toESM(require("lodash"));
|
|
50
|
-
var import_field_value_writer = require("./field-value-writer");
|
|
51
|
-
var Topo = __toESM(require("@hapi/topo"));
|
|
52
|
-
var import_restore_check_error = require("./errors/restore-check-error");
|
|
53
|
-
var import_semver = __toESM(require("semver"));
|
|
54
|
-
const renamePlugins = async (app) => {
|
|
55
|
-
const names = {
|
|
56
|
-
oidc: "@nocobase/plugin-auth-oidc",
|
|
57
|
-
cas: "@nocobase/plugin-auth-cas",
|
|
58
|
-
saml: "@nocobase/plugin-auth-saml",
|
|
59
|
-
"collection-manager": "@nocobase/plugin-data-source-main",
|
|
60
|
-
"china-region": "@nocobase/plugin-field-china-region",
|
|
61
|
-
"custom-request": "@nocobase/plugin-action-custom-request",
|
|
62
|
-
export: "@nocobase/plugin-action-export",
|
|
63
|
-
import: "@nocobase/plugin-action-import",
|
|
64
|
-
"formula-field": "@nocobase/plugin-field-formula",
|
|
65
|
-
"iframe-block": "@nocobase/plugin-block-iframe",
|
|
66
|
-
"localization-management": "@nocobase/plugin-localization",
|
|
67
|
-
"sequence-field": "@nocobase/plugin-field-sequence",
|
|
68
|
-
"sms-auth": "@nocobase/plugin-auth-sms"
|
|
69
|
-
};
|
|
70
|
-
for (const original of Object.keys(names)) {
|
|
71
|
-
await app.pm.repository.update({
|
|
72
|
-
filter: {
|
|
73
|
-
name: original
|
|
74
|
-
},
|
|
75
|
-
values: {
|
|
76
|
-
name: names[original].replace("@nocobase/plugin-", ""),
|
|
77
|
-
packageName: names[original]
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
class Restorer extends import_app_migrator.AppMigrator {
|
|
83
|
-
direction = "restore";
|
|
84
|
-
backUpFilePath;
|
|
85
|
-
decompressed = false;
|
|
86
|
-
importedCollections = [];
|
|
87
|
-
constructor(app, options) {
|
|
88
|
-
super(app, options);
|
|
89
|
-
const { backUpFilePath } = options;
|
|
90
|
-
if (backUpFilePath) {
|
|
91
|
-
this.setBackUpFilePath(backUpFilePath);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
static sortCollectionsByInherits(collections) {
|
|
95
|
-
var _a;
|
|
96
|
-
const sorter = new Topo.Sorter();
|
|
97
|
-
for (const collection of collections) {
|
|
98
|
-
const options = {
|
|
99
|
-
group: collection.name
|
|
100
|
-
};
|
|
101
|
-
if ((_a = collection.inherits) == null ? void 0 : _a.length) {
|
|
102
|
-
options.after = collection.inherits;
|
|
103
|
-
}
|
|
104
|
-
sorter.add(collection, options);
|
|
105
|
-
}
|
|
106
|
-
return sorter.sort();
|
|
107
|
-
}
|
|
108
|
-
setBackUpFilePath(backUpFilePath) {
|
|
109
|
-
if (import_path.default.isAbsolute(backUpFilePath)) {
|
|
110
|
-
this.backUpFilePath = backUpFilePath;
|
|
111
|
-
} else if (import_path.default.basename(backUpFilePath) === backUpFilePath) {
|
|
112
|
-
const dirname = import_path.default.resolve(process.cwd(), "storage", "duplicator");
|
|
113
|
-
this.backUpFilePath = import_path.default.resolve(dirname, backUpFilePath);
|
|
114
|
-
} else {
|
|
115
|
-
this.backUpFilePath = import_path.default.resolve(process.cwd(), backUpFilePath);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
async parseBackupFile() {
|
|
119
|
-
await this.decompressBackup(this.backUpFilePath);
|
|
120
|
-
return await this.getImportMeta();
|
|
121
|
-
}
|
|
122
|
-
async restore(options) {
|
|
123
|
-
await this.decompressBackup(this.backUpFilePath);
|
|
124
|
-
await this.checkMeta();
|
|
125
|
-
await this.importCollections(options);
|
|
126
|
-
await this.importDb(options);
|
|
127
|
-
await this.clearWorkDir();
|
|
128
|
-
}
|
|
129
|
-
async getImportMeta() {
|
|
130
|
-
const metaFile = import_path.default.resolve(this.workDir, "meta");
|
|
131
|
-
return JSON.parse(await import_promises.default.readFile(metaFile, "utf8"));
|
|
132
|
-
}
|
|
133
|
-
async checkMeta() {
|
|
134
|
-
const meta = await this.getImportMeta();
|
|
135
|
-
if (!this.app.db.inDialect(meta["dialect"])) {
|
|
136
|
-
throw new import_restore_check_error.RestoreCheckError(`this backup file can only be imported in database ${meta["dialect"]}`);
|
|
137
|
-
}
|
|
138
|
-
const checkEnv = (envName) => {
|
|
139
|
-
const valueInPackage = meta[envName] || "";
|
|
140
|
-
const valueInEnv = process.env[envName] || "";
|
|
141
|
-
if (valueInPackage && valueInEnv !== valueInPackage) {
|
|
142
|
-
throw new import_restore_check_error.RestoreCheckError(`for use this backup file, please set ${envName}=${valueInPackage}`);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
for (const envName of ["DB_UNDERSCORED", "DB_SCHEMA", "COLLECTION_MANAGER_SCHEMA", "DB_TABLE_PREFIX"]) {
|
|
146
|
-
checkEnv(envName);
|
|
147
|
-
}
|
|
148
|
-
const version = meta["version"];
|
|
149
|
-
if (import_semver.default.lt(version, "0.18.0-alpha.2")) {
|
|
150
|
-
throw new import_restore_check_error.RestoreCheckError(`this backup file can only be imported in nocobase ${version}`);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
async importCollections(options) {
|
|
154
|
-
const importCollection = async (collectionName) => {
|
|
155
|
-
await this.importCollection({
|
|
156
|
-
name: collectionName
|
|
157
|
-
});
|
|
158
|
-
};
|
|
159
|
-
const preImportCollections = ["applicationPlugins"];
|
|
160
|
-
const { dumpableCollectionsGroupByGroup, delayCollections } = await this.parseBackupFile();
|
|
161
|
-
for (const collectionName of preImportCollections) {
|
|
162
|
-
await importCollection(collectionName);
|
|
163
|
-
}
|
|
164
|
-
await renamePlugins(this.app);
|
|
165
|
-
await this.app.reload();
|
|
166
|
-
const metaCollections = dumpableCollectionsGroupByGroup.required;
|
|
167
|
-
for (const collection of metaCollections) {
|
|
168
|
-
if (preImportCollections.includes(collection.name)) {
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
if (delayCollections.includes(collection.name)) {
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
await importCollection(collection.name);
|
|
175
|
-
}
|
|
176
|
-
options.groups.delete("required");
|
|
177
|
-
const importGroups = [...options.groups];
|
|
178
|
-
for (const group of importGroups) {
|
|
179
|
-
const collections = dumpableCollectionsGroupByGroup[group];
|
|
180
|
-
if (!collections) {
|
|
181
|
-
this.app.log.warn(`group ${group} not found`);
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
for (const collection of Restorer.sortCollectionsByInherits(collections)) {
|
|
185
|
-
await importCollection(collection.name);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
await this.app.reload();
|
|
189
|
-
await this.app.db.getRepository("collections").load();
|
|
190
|
-
await this.app.db.sync();
|
|
191
|
-
for (const collectionName of delayCollections) {
|
|
192
|
-
const delayRestore = this.app.db.getCollection(collectionName).options.dumpRules["delayRestore"];
|
|
193
|
-
await delayRestore(this);
|
|
194
|
-
}
|
|
195
|
-
await this.emitAsync("restoreCollectionsFinished");
|
|
196
|
-
}
|
|
197
|
-
async decompressBackup(backupFilePath) {
|
|
198
|
-
if (!this.decompressed)
|
|
199
|
-
await (0, import_decompress.default)(backupFilePath, this.workDir);
|
|
200
|
-
}
|
|
201
|
-
async readCollectionMeta(collectionName) {
|
|
202
|
-
const dir = this.workDir;
|
|
203
|
-
const collectionMetaPath = import_path.default.resolve(dir, "collections", collectionName, "meta");
|
|
204
|
-
const metaContent = await import_promises.default.readFile(collectionMetaPath, "utf8");
|
|
205
|
-
return JSON.parse(metaContent);
|
|
206
|
-
}
|
|
207
|
-
async importCollection(options) {
|
|
208
|
-
const app = this.app;
|
|
209
|
-
const db = app.db;
|
|
210
|
-
const collectionName = options.name;
|
|
211
|
-
if (!collectionName) {
|
|
212
|
-
throw new Error("collection name is required");
|
|
213
|
-
}
|
|
214
|
-
const dir = this.workDir;
|
|
215
|
-
const collectionDataPath = import_path.default.resolve(dir, "collections", collectionName, "data");
|
|
216
|
-
const collectionMetaPath = import_path.default.resolve(dir, "collections", collectionName, "meta");
|
|
217
|
-
try {
|
|
218
|
-
await import_promises.default.stat(collectionMetaPath);
|
|
219
|
-
} catch (e) {
|
|
220
|
-
app.logger.info(`${collectionName} has no meta`);
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const metaContent = await import_promises.default.readFile(collectionMetaPath, "utf8");
|
|
224
|
-
const meta = JSON.parse(metaContent);
|
|
225
|
-
let addSchemaTableName = meta.tableName;
|
|
226
|
-
if (!this.app.db.inDialect("postgres") && (0, import_lodash.isPlainObject)(addSchemaTableName)) {
|
|
227
|
-
addSchemaTableName = addSchemaTableName.tableName;
|
|
228
|
-
}
|
|
229
|
-
const columns = meta["columns"];
|
|
230
|
-
if (columns.length == 0) {
|
|
231
|
-
app.logger.info(`${collectionName} has no columns`);
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
const fieldAttributes = import_lodash.default.mapValues(meta.attributes, (attr) => {
|
|
235
|
-
if (attr.isCollectionField) {
|
|
236
|
-
const fieldClass = db.fieldTypes.get(attr.type);
|
|
237
|
-
if (!fieldClass)
|
|
238
|
-
throw new Error(`field type ${attr.type} not found`);
|
|
239
|
-
return new fieldClass(attr.typeOptions, {
|
|
240
|
-
database: db
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
return void 0;
|
|
244
|
-
});
|
|
245
|
-
const rawAttributes = import_lodash.default.mapValues(meta.attributes, (attr, key) => {
|
|
246
|
-
if (attr.isCollectionField) {
|
|
247
|
-
const field = fieldAttributes[key];
|
|
248
|
-
return {
|
|
249
|
-
...field.toSequelize(),
|
|
250
|
-
field: attr.field
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
const DataTypeClass = import_database.DataTypes[db.options.dialect][attr.type] || import_database.DataTypes[attr.type];
|
|
254
|
-
const obj = {
|
|
255
|
-
...attr,
|
|
256
|
-
type: new DataTypeClass()
|
|
257
|
-
};
|
|
258
|
-
if (attr.defaultValue && ["JSON", "JSONB", "JSONTYPE"].includes(attr.type)) {
|
|
259
|
-
obj.defaultValue = JSON.stringify(attr.defaultValue);
|
|
260
|
-
}
|
|
261
|
-
return obj;
|
|
262
|
-
});
|
|
263
|
-
if (options.clear !== false) {
|
|
264
|
-
await db.sequelize.getQueryInterface().dropTable(addSchemaTableName, {
|
|
265
|
-
cascade: true
|
|
266
|
-
});
|
|
267
|
-
await db.sequelize.getQueryInterface().createTable(addSchemaTableName, rawAttributes);
|
|
268
|
-
if (meta.inherits) {
|
|
269
|
-
for (const inherit of import_lodash.default.uniq(meta.inherits)) {
|
|
270
|
-
const parentMeta = await this.readCollectionMeta(inherit);
|
|
271
|
-
const sql2 = `ALTER TABLE ${app.db.utils.quoteTable(addSchemaTableName)} INHERIT ${app.db.utils.quoteTable(
|
|
272
|
-
parentMeta.tableName
|
|
273
|
-
)};`;
|
|
274
|
-
await db.sequelize.query(sql2);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
const rows = await (0, import_utils.readLines)(collectionDataPath);
|
|
279
|
-
if (rows.length == 0) {
|
|
280
|
-
app.logger.info(`${collectionName} has no data to import`);
|
|
281
|
-
this.importedCollections.push(collectionName);
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
const rowsWithMeta = rows.map(
|
|
285
|
-
(row) => JSON.parse(row).map((val, index) => [columns[index], val]).reduce((carry, [column, val]) => {
|
|
286
|
-
const field = fieldAttributes[column];
|
|
287
|
-
carry[column] = field ? import_field_value_writer.FieldValueWriter.write(field, val) : val;
|
|
288
|
-
return carry;
|
|
289
|
-
}, {})
|
|
290
|
-
).filter((row) => {
|
|
291
|
-
if (options.rowCondition) {
|
|
292
|
-
return options.rowCondition(row);
|
|
293
|
-
}
|
|
294
|
-
return true;
|
|
295
|
-
});
|
|
296
|
-
if (rowsWithMeta.length == 0) {
|
|
297
|
-
app.logger.info(`${collectionName} has no data to import`);
|
|
298
|
-
this.importedCollections.push(collectionName);
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
const insertGeneratorAttributes = import_lodash.default.mapKeys(rawAttributes, (value, key) => {
|
|
302
|
-
return value.field;
|
|
303
|
-
});
|
|
304
|
-
const sql = db.sequelize.queryInterface.queryGenerator.bulkInsertQuery(
|
|
305
|
-
addSchemaTableName,
|
|
306
|
-
rowsWithMeta,
|
|
307
|
-
{},
|
|
308
|
-
insertGeneratorAttributes
|
|
309
|
-
);
|
|
310
|
-
if (options.insert === false) {
|
|
311
|
-
return sql;
|
|
312
|
-
}
|
|
313
|
-
await app.db.sequelize.query(sql, {
|
|
314
|
-
type: "INSERT"
|
|
315
|
-
});
|
|
316
|
-
app.logger.info(`${collectionName} imported with ${rowsWithMeta.length} rows`);
|
|
317
|
-
if (meta.autoIncrement) {
|
|
318
|
-
const queryInterface = app.db.queryInterface;
|
|
319
|
-
await queryInterface.setAutoIncrementVal({
|
|
320
|
-
tableInfo: (0, import_lodash.isPlainObject)(meta.tableName) ? meta.tableName : {
|
|
321
|
-
schema: "public",
|
|
322
|
-
tableName: meta.tableName
|
|
323
|
-
},
|
|
324
|
-
columnName: meta.autoIncrement.fieldName,
|
|
325
|
-
seqName: meta.autoIncrement.seqName,
|
|
326
|
-
currentVal: meta.autoIncrement.currentVal
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
this.importedCollections.push(collectionName);
|
|
330
|
-
}
|
|
331
|
-
async importDb(options) {
|
|
332
|
-
const sqlContentPath = import_path.default.resolve(this.workDir, "sql-content.json");
|
|
333
|
-
if (!import_fs.default.existsSync(sqlContentPath)) {
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
const sqlData = JSON.parse(await import_promises.default.readFile(sqlContentPath, "utf8"));
|
|
337
|
-
const sqlContent = Object.keys(sqlData).filter((key) => options.groups.has(sqlData[key].group)).reduce((acc, key) => {
|
|
338
|
-
acc[key] = sqlData[key];
|
|
339
|
-
return acc;
|
|
340
|
-
}, {});
|
|
341
|
-
const queries = Object.values(
|
|
342
|
-
sqlContent
|
|
343
|
-
);
|
|
344
|
-
for (const sqlData2 of queries) {
|
|
345
|
-
try {
|
|
346
|
-
this.app.log.info(`import sql: ${sqlData2.sql}`);
|
|
347
|
-
for (const sql of import_lodash.default.castArray(sqlData2.sql)) {
|
|
348
|
-
await this.app.db.sequelize.query(sql);
|
|
349
|
-
}
|
|
350
|
-
} catch (e) {
|
|
351
|
-
if (e.name === "SequelizeDatabaseError") {
|
|
352
|
-
this.app.logger.error(e.message);
|
|
353
|
-
} else {
|
|
354
|
-
throw e;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
361
|
-
0 && (module.exports = {
|
|
362
|
-
Restorer
|
|
363
|
-
});
|
package/dist/server/server.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
import { Plugin } from '@nocobase/server';
|
|
10
|
-
export default class PluginBackupRestoreServer extends Plugin {
|
|
11
|
-
beforeLoad(): void;
|
|
12
|
-
load(): Promise<void>;
|
|
13
|
-
}
|
package/dist/server/server.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __export = (target, all) => {
|
|
17
|
-
for (var name in all)
|
|
18
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
-
};
|
|
20
|
-
var __copyProps = (to, from, except, desc) => {
|
|
21
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
-
for (let key of __getOwnPropNames(from))
|
|
23
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
-
}
|
|
26
|
-
return to;
|
|
27
|
-
};
|
|
28
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
-
mod
|
|
35
|
-
));
|
|
36
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
-
var server_exports = {};
|
|
38
|
-
__export(server_exports, {
|
|
39
|
-
default: () => PluginBackupRestoreServer
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(server_exports);
|
|
42
|
-
var import_server = require("@nocobase/server");
|
|
43
|
-
var import_backup_files = __toESM(require("./resourcers/backup-files"));
|
|
44
|
-
class PluginBackupRestoreServer extends import_server.Plugin {
|
|
45
|
-
beforeLoad() {
|
|
46
|
-
this.app.acl.registerSnippet({
|
|
47
|
-
name: `pm.${this.name}`,
|
|
48
|
-
actions: ["backupFiles:*"]
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
async load() {
|
|
52
|
-
this.app.resourcer.define(import_backup_files.default);
|
|
53
|
-
}
|
|
54
|
-
}
|
package/dist/server/utils.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
import { Database } from '@nocobase/database';
|
|
10
|
-
export declare const DUMPED_EXTENSION = "nbdump";
|
|
11
|
-
export declare function sqlAdapter(database: Database, sql: string): string;
|
|
12
|
-
export declare function readLines(filePath: string): Promise<any[]>;
|
|
13
|
-
export declare function humanFileSize(bytes: any, si?: boolean, dp?: number): string;
|
package/dist/server/utils.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __export = (target, all) => {
|
|
17
|
-
for (var name in all)
|
|
18
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
-
};
|
|
20
|
-
var __copyProps = (to, from, except, desc) => {
|
|
21
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
-
for (let key of __getOwnPropNames(from))
|
|
23
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
-
}
|
|
26
|
-
return to;
|
|
27
|
-
};
|
|
28
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
-
mod
|
|
35
|
-
));
|
|
36
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
-
var utils_exports = {};
|
|
38
|
-
__export(utils_exports, {
|
|
39
|
-
DUMPED_EXTENSION: () => DUMPED_EXTENSION,
|
|
40
|
-
humanFileSize: () => humanFileSize,
|
|
41
|
-
readLines: () => readLines,
|
|
42
|
-
sqlAdapter: () => sqlAdapter
|
|
43
|
-
});
|
|
44
|
-
module.exports = __toCommonJS(utils_exports);
|
|
45
|
-
var import_lodash = __toESM(require("lodash"));
|
|
46
|
-
var import_fs = __toESM(require("fs"));
|
|
47
|
-
var import_readline = __toESM(require("readline"));
|
|
48
|
-
const DUMPED_EXTENSION = "nbdump";
|
|
49
|
-
function sqlAdapter(database, sql) {
|
|
50
|
-
if (database.isMySQLCompatibleDialect()) {
|
|
51
|
-
return import_lodash.default.replace(sql, /"/g, "`");
|
|
52
|
-
}
|
|
53
|
-
return sql;
|
|
54
|
-
}
|
|
55
|
-
async function readLines(filePath) {
|
|
56
|
-
const results = [];
|
|
57
|
-
const fileStream = import_fs.default.createReadStream(filePath);
|
|
58
|
-
const rl = import_readline.default.createInterface({
|
|
59
|
-
input: fileStream,
|
|
60
|
-
crlfDelay: Infinity
|
|
61
|
-
});
|
|
62
|
-
for await (const line of rl) {
|
|
63
|
-
results.push(line);
|
|
64
|
-
}
|
|
65
|
-
return results;
|
|
66
|
-
}
|
|
67
|
-
function humanFileSize(bytes, si = false, dp = 1) {
|
|
68
|
-
const thresh = si ? 1e3 : 1024;
|
|
69
|
-
if (Math.abs(bytes) < thresh) {
|
|
70
|
-
return bytes + " B";
|
|
71
|
-
}
|
|
72
|
-
const units = si ? ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] : ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
|
73
|
-
let u = -1;
|
|
74
|
-
const r = 10 ** dp;
|
|
75
|
-
do {
|
|
76
|
-
bytes /= thresh;
|
|
77
|
-
++u;
|
|
78
|
-
} while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
|
|
79
|
-
return bytes.toFixed(dp) + " " + units[u];
|
|
80
|
-
}
|
|
81
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
-
0 && (module.exports = {
|
|
83
|
-
DUMPED_EXTENSION,
|
|
84
|
-
humanFileSize,
|
|
85
|
-
readLines,
|
|
86
|
-
sqlAdapter
|
|
87
|
-
});
|