vona-module-a-version 5.0.10 → 5.0.11
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/dist/index.js +508 -2
- package/package.json +2 -2
- package/dist/.metadata/index.js +0 -61
- package/dist/.metadata/this.js +0 -2
- package/dist/bean/event.versionDone.js +0 -13
- package/dist/bean/meta.version.js +0 -47
- package/dist/bean/startup.databaseInit.js +0 -17
- package/dist/bean/startup.databaseName.js +0 -17
- package/dist/bean/startup.instanceInit.js +0 -18
- package/dist/config/errors.js +0 -4
- package/dist/config/locale/en-us.js +0 -3
- package/dist/config/locale/zh-cn.js +0 -3
- package/dist/entity/version.js +0 -16
- package/dist/entity/versionInit.js +0 -17
- package/dist/entity/viewRecord.js +0 -16
- package/dist/model/viewRecord.js +0 -14
- package/dist/service/database.js +0 -101
- package/dist/service/version.js +0 -239
- package/dist/types/index.js +0 -1
- package/dist/types/version.js +0 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,508 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { BeanInfo, BeanBase, ClassMapped, BeanScopeBase } from 'vona';
|
|
2
|
+
import { Scope } from 'vona-module-a-bean';
|
|
3
|
+
import { Event, BeanEventBase } from 'vona-module-a-event';
|
|
4
|
+
import fse from 'fs-extra';
|
|
5
|
+
import { Meta } from 'vona-module-a-meta';
|
|
6
|
+
import { Startup } from 'vona-module-a-startup';
|
|
7
|
+
import { Entity, EntityBaseSimple, Model, BeanModelBase } from 'vona-module-a-database';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
import moment from 'moment';
|
|
10
|
+
import { Service } from 'vona-module-a-web';
|
|
11
|
+
|
|
12
|
+
var locale_en_us = {
|
|
13
|
+
ModuleOld: 'Module %s is Old'
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
var locale_zh_cn = {
|
|
17
|
+
ModuleOld: '模块 %s 过旧'
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
var _dec$b, _dec2$b, _class$b;
|
|
21
|
+
let EventVersionDone = (_dec$b = Event(), _dec2$b = BeanInfo({
|
|
22
|
+
module: "a-version"
|
|
23
|
+
}), _dec$b(_class$b = _dec2$b(_class$b = class EventVersionDone extends BeanEventBase {}) || _class$b) || _class$b);
|
|
24
|
+
|
|
25
|
+
var _dec$a, _dec2$a, _class$a;
|
|
26
|
+
let MetaVersion = (_dec$a = Meta(), _dec2$a = BeanInfo({
|
|
27
|
+
module: "a-version"
|
|
28
|
+
}), _dec$a(_class$a = _dec2$a(_class$a = class MetaVersion extends BeanBase {
|
|
29
|
+
async update(options) {
|
|
30
|
+
if (options.version === 1) {
|
|
31
|
+
const entity = this.scope.entity.versionInit;
|
|
32
|
+
await this.bean.model.createTable(entity.$table, table => {
|
|
33
|
+
table.basicFieldsSimple({
|
|
34
|
+
deleted: false,
|
|
35
|
+
iid: false
|
|
36
|
+
});
|
|
37
|
+
table.string(entity.$column('instanceName'), 255);
|
|
38
|
+
table.string(entity.$column('module'), 255);
|
|
39
|
+
table.integer(entity.$column('version'));
|
|
40
|
+
});
|
|
41
|
+
const entity2 = this.scope.entity.viewRecord;
|
|
42
|
+
await this.bean.model.createTable(entity2.$table, table => {
|
|
43
|
+
table.basicFieldsSimple({
|
|
44
|
+
deleted: true,
|
|
45
|
+
iid: false
|
|
46
|
+
});
|
|
47
|
+
table.string(entity2.$column('viewName'), 255);
|
|
48
|
+
table.text(entity2.$column('viewSql'));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async init(options) {
|
|
53
|
+
if (options.version === 1) {
|
|
54
|
+
// remove publicDir
|
|
55
|
+
await this._removePublicDir();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async _removePublicDir() {
|
|
59
|
+
// only for test/local env
|
|
60
|
+
if (this.app.meta.isProd) return;
|
|
61
|
+
// path
|
|
62
|
+
const publicPath = await this.app.util.getPublicPathPhysical();
|
|
63
|
+
// remove
|
|
64
|
+
await fse.remove(publicPath);
|
|
65
|
+
}
|
|
66
|
+
}) || _class$a) || _class$a);
|
|
67
|
+
|
|
68
|
+
var _dec$9, _dec2$9, _class$9;
|
|
69
|
+
let StartupDatabaseInit = (_dec$9 = Startup({
|
|
70
|
+
debounce: true
|
|
71
|
+
}), _dec2$9 = BeanInfo({
|
|
72
|
+
module: "a-version"
|
|
73
|
+
}), _dec$9(_class$9 = _dec2$9(_class$9 = class StartupDatabaseInit extends BeanBase {
|
|
74
|
+
async execute() {
|
|
75
|
+
return await this.scope.service.database.databaseInitStartup();
|
|
76
|
+
}
|
|
77
|
+
}) || _class$9) || _class$9);
|
|
78
|
+
|
|
79
|
+
var _dec$8, _dec2$8, _class$8;
|
|
80
|
+
let StartupDatabaseName = (_dec$8 = Startup({
|
|
81
|
+
dependencies: 'a-version:databaseInit'
|
|
82
|
+
}), _dec2$8 = BeanInfo({
|
|
83
|
+
module: "a-version"
|
|
84
|
+
}), _dec$8(_class$8 = _dec2$8(_class$8 = class StartupDatabaseName extends BeanBase {
|
|
85
|
+
async execute() {
|
|
86
|
+
return await this.scope.service.database.databaseNameStartup();
|
|
87
|
+
}
|
|
88
|
+
}) || _class$8) || _class$8);
|
|
89
|
+
|
|
90
|
+
var _dec$7, _dec2$7, _class$7;
|
|
91
|
+
let StartupInstanceInit = (_dec$7 = Startup({
|
|
92
|
+
instance: true,
|
|
93
|
+
debounce: true
|
|
94
|
+
}), _dec2$7 = BeanInfo({
|
|
95
|
+
module: "a-version"
|
|
96
|
+
}), _dec$7(_class$7 = _dec2$7(_class$7 = class StartupInstanceInit extends BeanBase {
|
|
97
|
+
async execute(options) {
|
|
98
|
+
const beanVersion = this.scope.service.version;
|
|
99
|
+
return await beanVersion.instanceInitStartup(options);
|
|
100
|
+
}
|
|
101
|
+
}) || _class$7) || _class$7);
|
|
102
|
+
|
|
103
|
+
let Errors = /*#__PURE__*/function (Errors) {
|
|
104
|
+
Errors[Errors["ModuleOld"] = 1001] = "ModuleOld";
|
|
105
|
+
return Errors;
|
|
106
|
+
}({});
|
|
107
|
+
|
|
108
|
+
var _dec$6, _dec2$6, _class$6;
|
|
109
|
+
let EntityVersion = (_dec$6 = Entity('aVersion'), _dec2$6 = BeanInfo({
|
|
110
|
+
module: "a-version"
|
|
111
|
+
}), _dec$6(_class$6 = _dec2$6(_class$6 = class EntityVersion extends ClassMapped.omit(EntityBaseSimple, ['iid', 'deleted']) {
|
|
112
|
+
constructor(...args) {
|
|
113
|
+
super(...args);
|
|
114
|
+
this.module = void 0;
|
|
115
|
+
this.version = void 0;
|
|
116
|
+
}
|
|
117
|
+
}) || _class$6) || _class$6);
|
|
118
|
+
|
|
119
|
+
var _dec$5, _dec2$5, _class$5;
|
|
120
|
+
let EntityVersionInit = (_dec$5 = Entity('aVersionInit'), _dec2$5 = BeanInfo({
|
|
121
|
+
module: "a-version"
|
|
122
|
+
}), _dec$5(_class$5 = _dec2$5(_class$5 = class EntityVersionInit extends ClassMapped.omit(EntityBaseSimple, ['iid', 'deleted']) {
|
|
123
|
+
constructor(...args) {
|
|
124
|
+
super(...args);
|
|
125
|
+
this.instanceName = void 0;
|
|
126
|
+
this.module = void 0;
|
|
127
|
+
this.version = void 0;
|
|
128
|
+
}
|
|
129
|
+
}) || _class$5) || _class$5);
|
|
130
|
+
|
|
131
|
+
var _dec$4, _dec2$4, _class$4;
|
|
132
|
+
let EntityViewRecord = (_dec$4 = Entity('aViewRecord'), _dec2$4 = BeanInfo({
|
|
133
|
+
module: "a-version"
|
|
134
|
+
}), _dec$4(_class$4 = _dec2$4(_class$4 = class EntityViewRecord extends ClassMapped.omit(EntityBaseSimple, ['iid']) {
|
|
135
|
+
constructor(...args) {
|
|
136
|
+
super(...args);
|
|
137
|
+
this.viewName = void 0;
|
|
138
|
+
this.viewSql = void 0;
|
|
139
|
+
}
|
|
140
|
+
}) || _class$4) || _class$4);
|
|
141
|
+
|
|
142
|
+
var _dec$3, _dec2$3, _class$3;
|
|
143
|
+
let ModelViewRecord = (_dec$3 = Model({
|
|
144
|
+
entity: EntityViewRecord,
|
|
145
|
+
disableDeleted: false,
|
|
146
|
+
disableInstance: true
|
|
147
|
+
}), _dec2$3 = BeanInfo({
|
|
148
|
+
module: "a-version"
|
|
149
|
+
}), _dec$3(_class$3 = _dec2$3(_class$3 = class ModelViewRecord extends BeanModelBase {}) || _class$3) || _class$3);
|
|
150
|
+
|
|
151
|
+
var _dec$2, _dec2$2, _class$2;
|
|
152
|
+
const __separator = '-';
|
|
153
|
+
const __timeFormat = `YYYYMMDD${__separator}HHmmss`;
|
|
154
|
+
let ServiceDatabase = (_dec$2 = Service(), _dec2$2 = BeanInfo({
|
|
155
|
+
module: "a-version"
|
|
156
|
+
}), _dec$2(_class$2 = _dec2$2(_class$2 = class ServiceDatabase extends BeanBase {
|
|
157
|
+
get configDatabase() {
|
|
158
|
+
return this.app.config.database;
|
|
159
|
+
}
|
|
160
|
+
get databasePrefix() {
|
|
161
|
+
return `cabloy${__separator}test${__separator}${this.app.name}${__separator}`;
|
|
162
|
+
}
|
|
163
|
+
async databaseInitStartup() {
|
|
164
|
+
// database
|
|
165
|
+
await this.__database();
|
|
166
|
+
// version start
|
|
167
|
+
await this.scope.service.version.__start();
|
|
168
|
+
}
|
|
169
|
+
async databaseNameStartup() {
|
|
170
|
+
// database
|
|
171
|
+
await this.__database();
|
|
172
|
+
}
|
|
173
|
+
async __fetchDatabases(client) {
|
|
174
|
+
// dbs
|
|
175
|
+
let dbs = await client.connection.schema.fetchDatabases(this.databasePrefix);
|
|
176
|
+
// filter
|
|
177
|
+
dbs = dbs.filter(db => {
|
|
178
|
+
const _time = db.name.substring(this.databasePrefix.length);
|
|
179
|
+
return _time.length === __timeFormat.length;
|
|
180
|
+
});
|
|
181
|
+
// ok
|
|
182
|
+
return dbs;
|
|
183
|
+
}
|
|
184
|
+
async __createDatabase(client) {
|
|
185
|
+
// create
|
|
186
|
+
const databaseName = `${this.databasePrefix}${moment().format(__timeFormat)}`;
|
|
187
|
+
await client.connection.schema.createDatabase(databaseName);
|
|
188
|
+
return databaseName;
|
|
189
|
+
}
|
|
190
|
+
async __database() {
|
|
191
|
+
if (this.app.meta.isProd) {
|
|
192
|
+
// donothing
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
// client
|
|
196
|
+
const client = this.bean.database.current.client;
|
|
197
|
+
// get current database name
|
|
198
|
+
let databaseName = client.getDatabaseName();
|
|
199
|
+
const isTestDatabase = databaseName.indexOf(this.databasePrefix) === 0;
|
|
200
|
+
// dev/debug db
|
|
201
|
+
if (this.app.meta.isLocal) {
|
|
202
|
+
// if enable testDatabase
|
|
203
|
+
const enableTestDatabase = this.configDatabase.testDatabase;
|
|
204
|
+
// check
|
|
205
|
+
if (!enableTestDatabase || isTestDatabase) {
|
|
206
|
+
// donothing
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const dbs = await this.__fetchDatabases(client);
|
|
210
|
+
if (dbs.length === 0) {
|
|
211
|
+
databaseName = await this.__createDatabase(client);
|
|
212
|
+
} else {
|
|
213
|
+
databaseName = dbs[0].name;
|
|
214
|
+
}
|
|
215
|
+
// set config and reload client
|
|
216
|
+
await client.changeConfigAndReload(databaseName);
|
|
217
|
+
this.$logger.silly(chalk.cyan(`database: ${databaseName}, pid: ${process.pid}`));
|
|
218
|
+
}
|
|
219
|
+
// test db
|
|
220
|
+
if (this.app.meta.isTest) {
|
|
221
|
+
// check
|
|
222
|
+
if (isTestDatabase) {
|
|
223
|
+
// donothing
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
// drop old databases
|
|
227
|
+
const dbs = await this.__fetchDatabases(client);
|
|
228
|
+
for (const db of dbs) {
|
|
229
|
+
await client.connection.schema.dropDatabase(db.name);
|
|
230
|
+
}
|
|
231
|
+
// create database
|
|
232
|
+
const databaseName = await this.__createDatabase(client);
|
|
233
|
+
// set config and reload client
|
|
234
|
+
await client.changeConfigAndReload(databaseName);
|
|
235
|
+
// database ready
|
|
236
|
+
this.$logger.silly(chalk.cyan(`database: ${databaseName}, pid: ${process.pid}`));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}) || _class$2) || _class$2);
|
|
240
|
+
|
|
241
|
+
var _dec$1, _dec2$1, _class$1;
|
|
242
|
+
let ServiceVersion = (_dec$1 = Service(), _dec2$1 = BeanInfo({
|
|
243
|
+
module: "a-version"
|
|
244
|
+
}), _dec$1(_class$1 = _dec2$1(_class$1 = class ServiceVersion extends BeanBase {
|
|
245
|
+
async instanceInitStartup(options) {
|
|
246
|
+
const instanceBase = options?.configInstanceBase;
|
|
247
|
+
await this.__instanceInit(this.ctx.instanceName, instanceBase);
|
|
248
|
+
}
|
|
249
|
+
async __start() {
|
|
250
|
+
// update all modules
|
|
251
|
+
try {
|
|
252
|
+
const result = await this.__check({
|
|
253
|
+
scene: 'update'
|
|
254
|
+
});
|
|
255
|
+
// clear columns cache
|
|
256
|
+
this.bean.database.current.columns.columnsClear();
|
|
257
|
+
// log
|
|
258
|
+
if (Object.keys(result).length > 0) {
|
|
259
|
+
this.$logger.info(JSON.stringify(result, null, 2));
|
|
260
|
+
}
|
|
261
|
+
this.$logger.silly(chalk.cyan('All modules are checked successfully!'));
|
|
262
|
+
} catch (err) {
|
|
263
|
+
this.$logger.silly(chalk.cyan('Modules are checked failed!'));
|
|
264
|
+
throw err;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
async __instanceInit(instanceName, instanceBase) {
|
|
268
|
+
if (instanceName === undefined || instanceName === null) {
|
|
269
|
+
throw new Error('instance name is not valid');
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
const optionsInit = Object.assign({}, instanceBase, {
|
|
273
|
+
scene: 'init',
|
|
274
|
+
instanceName
|
|
275
|
+
});
|
|
276
|
+
await this.__check(optionsInit);
|
|
277
|
+
this.$logger.silly(chalk.cyan(`The instance is initialized successfully: ${instanceName || 'default'}`));
|
|
278
|
+
} catch (err) {
|
|
279
|
+
this.$logger.silly(chalk.cyan(`The instance is initialized failed: ${instanceName || 'default'}`));
|
|
280
|
+
throw err;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
async __instanceTest(instanceName) {
|
|
284
|
+
await this.__check({
|
|
285
|
+
scene: 'test',
|
|
286
|
+
instanceName
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// scene: null/init/test
|
|
291
|
+
async __check(options) {
|
|
292
|
+
options.result = {};
|
|
293
|
+
if (options.scene === 'update') {
|
|
294
|
+
// confirm table aVersion exists
|
|
295
|
+
const entity = this.scope.entity.version;
|
|
296
|
+
const hasTableVersion = await this.bean.model.schema.hasTable(entity.$table);
|
|
297
|
+
if (!hasTableVersion) {
|
|
298
|
+
await this.bean.model.createTable(entity.$table, table => {
|
|
299
|
+
table.basicFieldsSimple({
|
|
300
|
+
deleted: false,
|
|
301
|
+
iid: false
|
|
302
|
+
});
|
|
303
|
+
table.string(entity.$column('module'), 255);
|
|
304
|
+
table.integer(entity.$column('version'));
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// check all modules
|
|
310
|
+
for (const module of this.app.meta.modulesArray) {
|
|
311
|
+
this.$loggerChild('version').debug('check module: %s, scene:%s', module.info.relativeName, options.scene);
|
|
312
|
+
await this.__checkModule(module.info.relativeName, options);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// version done
|
|
316
|
+
await this.bean.executor.newCtx(async () => {
|
|
317
|
+
await this.__done(options);
|
|
318
|
+
}, {
|
|
319
|
+
instanceName: options.instanceName
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// ok
|
|
323
|
+
return options.result;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// check module
|
|
327
|
+
async __checkModule(moduleName, options) {
|
|
328
|
+
// module
|
|
329
|
+
const module = this.__getModule(moduleName);
|
|
330
|
+
|
|
331
|
+
// fileVersionNew
|
|
332
|
+
let fileVersionNew = 0;
|
|
333
|
+
if (module.package.vonaModule && module.package.vonaModule.fileVersion) {
|
|
334
|
+
fileVersionNew = module.package.vonaModule.fileVersion;
|
|
335
|
+
}
|
|
336
|
+
if (fileVersionNew && ['update', 'init'].includes(options.scene)) {
|
|
337
|
+
// update module or init module
|
|
338
|
+
|
|
339
|
+
// -1: always
|
|
340
|
+
if (fileVersionNew === -1) {
|
|
341
|
+
await this.__updateModule(options, module, -1, -1);
|
|
342
|
+
} else {
|
|
343
|
+
// fileVersionOld
|
|
344
|
+
let fileVersionOld = 0; // default
|
|
345
|
+
if (options.scene === 'update') {
|
|
346
|
+
const res = await this.bean.model.builder('aVersion').select('*').where('module', moduleName).orderBy('version', 'desc').first();
|
|
347
|
+
if (res) {
|
|
348
|
+
fileVersionOld = res.version;
|
|
349
|
+
}
|
|
350
|
+
} else {
|
|
351
|
+
const res = await this.bean.model.builder('aVersionInit').select('*').where({
|
|
352
|
+
instanceName: options.instanceName,
|
|
353
|
+
module: moduleName
|
|
354
|
+
}).orderBy('version', 'desc').first();
|
|
355
|
+
if (res) {
|
|
356
|
+
fileVersionOld = res.version;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// check if need update
|
|
361
|
+
if (fileVersionOld > fileVersionNew) {
|
|
362
|
+
this.scope.error.ModuleOld.throw(moduleName);
|
|
363
|
+
} else {
|
|
364
|
+
// not check if (fileVersionOld < fileVersionNew)
|
|
365
|
+
await this.__updateModule(options, module, fileVersionOld, fileVersionNew);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if (options.scene === 'test') {
|
|
370
|
+
// test module
|
|
371
|
+
await this.bean.executor.newCtx(async () => {
|
|
372
|
+
await this.__testModuleTransaction(module, fileVersionNew, options);
|
|
373
|
+
}, {
|
|
374
|
+
instanceName: options.instanceName,
|
|
375
|
+
transaction: true
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// update module or init module
|
|
381
|
+
async __updateModule(options, module, fileVersionOld, fileVersionNew) {
|
|
382
|
+
if (fileVersionNew === -1) {
|
|
383
|
+
// always
|
|
384
|
+
await this.__updateModule2(options, module, -1);
|
|
385
|
+
} else {
|
|
386
|
+
// versions
|
|
387
|
+
// always version:0
|
|
388
|
+
const versions = [0];
|
|
389
|
+
for (let version = fileVersionOld + 1; version <= fileVersionNew; version++) {
|
|
390
|
+
versions.push(version);
|
|
391
|
+
}
|
|
392
|
+
// loop
|
|
393
|
+
for (const version of versions) {
|
|
394
|
+
this.$loggerChild('version').debug('update module: %s, version: %d, scene:%s', module.info.relativeName, version, options.scene);
|
|
395
|
+
await this.__updateModule2(options, module, version);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// log
|
|
400
|
+
if (fileVersionOld !== fileVersionNew) {
|
|
401
|
+
options.result[module.info.relativeName] = {
|
|
402
|
+
fileVersionOld,
|
|
403
|
+
fileVersionNew
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
async __updateModule2(options, module, version) {
|
|
408
|
+
// perform action
|
|
409
|
+
if (options.scene === 'update') {
|
|
410
|
+
// update
|
|
411
|
+
await this.bean.executor.newCtx(async () => {
|
|
412
|
+
await this.__updateModuleTransaction(module, version);
|
|
413
|
+
}, {
|
|
414
|
+
transaction: module.name !== 'a-index'
|
|
415
|
+
});
|
|
416
|
+
} else {
|
|
417
|
+
// init
|
|
418
|
+
await this.bean.executor.newCtx(async () => {
|
|
419
|
+
await this.__initModuleTransaction(module, version, options);
|
|
420
|
+
}, {
|
|
421
|
+
instanceName: options.instanceName,
|
|
422
|
+
transaction: true
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
async __updateModuleTransaction(module, version) {
|
|
427
|
+
// bean
|
|
428
|
+
const beanVersion = this.__getBeanVersion(module.info.relativeName, true);
|
|
429
|
+
if (!beanVersion.update) throw new Error(`meta.version.update not exists for ${module.info.relativeName}`);
|
|
430
|
+
// clear columns cache
|
|
431
|
+
this.bean.database.current.columns.columnsClear();
|
|
432
|
+
// execute
|
|
433
|
+
await beanVersion.update({
|
|
434
|
+
version
|
|
435
|
+
});
|
|
436
|
+
// insert record
|
|
437
|
+
if (version > 0) {
|
|
438
|
+
await this.bean.model.builder('aVersion').insert({
|
|
439
|
+
module: module.info.relativeName,
|
|
440
|
+
version
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
async __initModuleTransaction(module, version, options) {
|
|
445
|
+
// bean
|
|
446
|
+
const beanVersion = this.__getBeanVersion(module.info.relativeName, true);
|
|
447
|
+
// execute
|
|
448
|
+
if (beanVersion.init) {
|
|
449
|
+
await beanVersion.init({
|
|
450
|
+
...options,
|
|
451
|
+
version
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
// insert record
|
|
455
|
+
if (version > 0) {
|
|
456
|
+
await this.bean.model.insert('aVersionInit', {
|
|
457
|
+
instanceName: options.instanceName,
|
|
458
|
+
module: module.info.relativeName,
|
|
459
|
+
version
|
|
460
|
+
}, {
|
|
461
|
+
disableInstance: true,
|
|
462
|
+
disableDeleted: true
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// test module
|
|
468
|
+
async __testModuleTransaction(module, version, options) {
|
|
469
|
+
// bean
|
|
470
|
+
const beanVersion = this.__getBeanVersion(module.info.relativeName, false);
|
|
471
|
+
// execute
|
|
472
|
+
if (beanVersion && beanVersion.test) {
|
|
473
|
+
await beanVersion.test({
|
|
474
|
+
...options,
|
|
475
|
+
version
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
async __done(options) {
|
|
480
|
+
await this.scope.event.versionDone.emit(options);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// get module
|
|
484
|
+
__getModule(moduleName) {
|
|
485
|
+
return this.app.meta.modules[moduleName];
|
|
486
|
+
}
|
|
487
|
+
__getBeanVersion(moduleName, throwErrorIfEmpty) {
|
|
488
|
+
// bean
|
|
489
|
+
const beanVersion = this.bean._getBean(`${moduleName}.meta.version`);
|
|
490
|
+
if (!beanVersion && throwErrorIfEmpty) throw new Error(`meta.version not exists for ${moduleName}`);
|
|
491
|
+
return beanVersion;
|
|
492
|
+
}
|
|
493
|
+
}) || _class$1) || _class$1);
|
|
494
|
+
|
|
495
|
+
var _dec, _dec2, _class;
|
|
496
|
+
const locales = {
|
|
497
|
+
'en-us': locale_en_us,
|
|
498
|
+
'zh-cn': locale_zh_cn
|
|
499
|
+
};
|
|
500
|
+
let ScopeModuleAVersion = (_dec = Scope(), _dec2 = BeanInfo({
|
|
501
|
+
module: "a-version"
|
|
502
|
+
}), _dec(_class = _dec2(_class = class ScopeModuleAVersion extends BeanScopeBase {}) || _class) || _class);
|
|
503
|
+
function $locale(key) {
|
|
504
|
+
return `a-version::${key}`;
|
|
505
|
+
}
|
|
506
|
+
/** scope: end */
|
|
507
|
+
|
|
508
|
+
export { $locale, EntityVersion, EntityVersionInit, EntityViewRecord, Errors, EventVersionDone, MetaVersion, ModelViewRecord, ScopeModuleAVersion, ServiceDatabase, ServiceVersion, StartupDatabaseInit, StartupDatabaseName, StartupInstanceInit, locales };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vona-module-a-version",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.11",
|
|
5
5
|
"vonaModule": {
|
|
6
6
|
"fileVersion": 1,
|
|
7
7
|
"dependencies": {},
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
|
|
41
|
-
"tsc:publish": "npm run clean && tsc -p tsconfig.build.json"
|
|
41
|
+
"tsc:publish": "npm run clean && vona :bin:buildModule && tsc -p tsconfig.build.json"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/dist/.metadata/index.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
/** error: end */
|
|
8
|
-
/** scope: begin */
|
|
9
|
-
import { BeanScopeBase } from 'vona';
|
|
10
|
-
import { Scope } from 'vona-module-a-bean';
|
|
11
|
-
/** service: end */
|
|
12
|
-
/** locale: begin */
|
|
13
|
-
import locale_en_us from "../config/locale/en-us.js";
|
|
14
|
-
/** service: end */
|
|
15
|
-
/** service: begin */
|
|
16
|
-
import locale_zh_cn from "../config/locale/zh-cn.js";
|
|
17
|
-
import 'vona';
|
|
18
|
-
import 'vona';
|
|
19
|
-
import 'vona';
|
|
20
|
-
import 'vona';
|
|
21
|
-
import 'vona';
|
|
22
|
-
import 'vona';
|
|
23
|
-
/** model: end */
|
|
24
|
-
/** event: begin */
|
|
25
|
-
export * from "../bean/event.versionDone.js";
|
|
26
|
-
/** event: end */
|
|
27
|
-
/** meta: begin */
|
|
28
|
-
export * from "../bean/meta.version.js";
|
|
29
|
-
/** meta: end */
|
|
30
|
-
/** startup: begin */
|
|
31
|
-
export * from "../bean/startup.databaseInit.js";
|
|
32
|
-
export * from "../bean/startup.databaseName.js";
|
|
33
|
-
export * from "../bean/startup.instanceInit.js";
|
|
34
|
-
/** locale: end */
|
|
35
|
-
/** error: begin */
|
|
36
|
-
export * from "../config/errors.js";
|
|
37
|
-
/** entity: begin */
|
|
38
|
-
export * from "../entity/version.js";
|
|
39
|
-
export * from "../entity/versionInit.js";
|
|
40
|
-
export * from "../entity/viewRecord.js";
|
|
41
|
-
/** entity: end */
|
|
42
|
-
/** model: begin */
|
|
43
|
-
export * from "../model/viewRecord.js";
|
|
44
|
-
/** startup: end */
|
|
45
|
-
/** service: begin */
|
|
46
|
-
export * from "../service/database.js";
|
|
47
|
-
export const locales = {
|
|
48
|
-
'en-us': locale_en_us,
|
|
49
|
-
'zh-cn': locale_zh_cn,
|
|
50
|
-
};
|
|
51
|
-
export * from "../service/version.js";
|
|
52
|
-
let ScopeModuleAVersion = class ScopeModuleAVersion extends BeanScopeBase {
|
|
53
|
-
};
|
|
54
|
-
ScopeModuleAVersion = __decorate([
|
|
55
|
-
Scope()
|
|
56
|
-
], ScopeModuleAVersion);
|
|
57
|
-
export { ScopeModuleAVersion };
|
|
58
|
-
export function $locale(key) {
|
|
59
|
-
return `a-version::${key}`;
|
|
60
|
-
}
|
|
61
|
-
/** scope: end */
|
package/dist/.metadata/this.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { BeanEventBase, Event } from 'vona-module-a-event';
|
|
8
|
-
let EventVersionDone = class EventVersionDone extends BeanEventBase {
|
|
9
|
-
};
|
|
10
|
-
EventVersionDone = __decorate([
|
|
11
|
-
Event()
|
|
12
|
-
], EventVersionDone);
|
|
13
|
-
export { EventVersionDone };
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import fse from 'fs-extra';
|
|
8
|
-
import { BeanBase } from 'vona';
|
|
9
|
-
import { Meta } from 'vona-module-a-meta';
|
|
10
|
-
let MetaVersion = class MetaVersion extends BeanBase {
|
|
11
|
-
async update(options) {
|
|
12
|
-
if (options.version === 1) {
|
|
13
|
-
const entity = this.scope.entity.versionInit;
|
|
14
|
-
await this.bean.model.createTable(entity.$table, table => {
|
|
15
|
-
table.basicFieldsSimple({ deleted: false, iid: false });
|
|
16
|
-
table.string(entity.$column('instanceName'), 255);
|
|
17
|
-
table.string(entity.$column('module'), 255);
|
|
18
|
-
table.integer(entity.$column('version'));
|
|
19
|
-
});
|
|
20
|
-
const entity2 = this.scope.entity.viewRecord;
|
|
21
|
-
await this.bean.model.createTable(entity2.$table, table => {
|
|
22
|
-
table.basicFieldsSimple({ deleted: true, iid: false });
|
|
23
|
-
table.string(entity2.$column('viewName'), 255);
|
|
24
|
-
table.text(entity2.$column('viewSql'));
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
async init(options) {
|
|
29
|
-
if (options.version === 1) {
|
|
30
|
-
// remove publicDir
|
|
31
|
-
await this._removePublicDir();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
async _removePublicDir() {
|
|
35
|
-
// only for test/local env
|
|
36
|
-
if (this.app.meta.isProd)
|
|
37
|
-
return;
|
|
38
|
-
// path
|
|
39
|
-
const publicPath = await this.app.util.getPublicPathPhysical();
|
|
40
|
-
// remove
|
|
41
|
-
await fse.remove(publicPath);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
MetaVersion = __decorate([
|
|
45
|
-
Meta()
|
|
46
|
-
], MetaVersion);
|
|
47
|
-
export { MetaVersion };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { BeanBase } from 'vona';
|
|
8
|
-
import { Startup } from 'vona-module-a-startup';
|
|
9
|
-
let StartupDatabaseInit = class StartupDatabaseInit extends BeanBase {
|
|
10
|
-
async execute() {
|
|
11
|
-
return await this.scope.service.database.databaseInitStartup();
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
StartupDatabaseInit = __decorate([
|
|
15
|
-
Startup({ debounce: true })
|
|
16
|
-
], StartupDatabaseInit);
|
|
17
|
-
export { StartupDatabaseInit };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { BeanBase } from 'vona';
|
|
8
|
-
import { Startup } from 'vona-module-a-startup';
|
|
9
|
-
let StartupDatabaseName = class StartupDatabaseName extends BeanBase {
|
|
10
|
-
async execute() {
|
|
11
|
-
return await this.scope.service.database.databaseNameStartup();
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
StartupDatabaseName = __decorate([
|
|
15
|
-
Startup({ dependencies: 'a-version:databaseInit' })
|
|
16
|
-
], StartupDatabaseName);
|
|
17
|
-
export { StartupDatabaseName };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { BeanBase } from 'vona';
|
|
8
|
-
import { Startup } from 'vona-module-a-startup';
|
|
9
|
-
let StartupInstanceInit = class StartupInstanceInit extends BeanBase {
|
|
10
|
-
async execute(options) {
|
|
11
|
-
const beanVersion = this.scope.service.version;
|
|
12
|
-
return await beanVersion.instanceInitStartup(options);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
StartupInstanceInit = __decorate([
|
|
16
|
-
Startup({ instance: true, debounce: true })
|
|
17
|
-
], StartupInstanceInit);
|
|
18
|
-
export { StartupInstanceInit };
|
package/dist/config/errors.js
DELETED
package/dist/entity/version.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { ClassMapped } from 'vona';
|
|
8
|
-
import { Entity, EntityBaseSimple } from 'vona-module-a-database';
|
|
9
|
-
let EntityVersion = class EntityVersion extends ClassMapped.omit(EntityBaseSimple, ['iid', 'deleted']) {
|
|
10
|
-
module;
|
|
11
|
-
version;
|
|
12
|
-
};
|
|
13
|
-
EntityVersion = __decorate([
|
|
14
|
-
Entity('aVersion')
|
|
15
|
-
], EntityVersion);
|
|
16
|
-
export { EntityVersion };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { ClassMapped } from 'vona';
|
|
8
|
-
import { Entity, EntityBaseSimple } from 'vona-module-a-database';
|
|
9
|
-
let EntityVersionInit = class EntityVersionInit extends ClassMapped.omit(EntityBaseSimple, ['iid', 'deleted']) {
|
|
10
|
-
instanceName;
|
|
11
|
-
module;
|
|
12
|
-
version;
|
|
13
|
-
};
|
|
14
|
-
EntityVersionInit = __decorate([
|
|
15
|
-
Entity('aVersionInit')
|
|
16
|
-
], EntityVersionInit);
|
|
17
|
-
export { EntityVersionInit };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { ClassMapped } from 'vona';
|
|
8
|
-
import { Entity, EntityBaseSimple } from 'vona-module-a-database';
|
|
9
|
-
let EntityViewRecord = class EntityViewRecord extends ClassMapped.omit(EntityBaseSimple, ['iid']) {
|
|
10
|
-
viewName;
|
|
11
|
-
viewSql;
|
|
12
|
-
};
|
|
13
|
-
EntityViewRecord = __decorate([
|
|
14
|
-
Entity('aViewRecord')
|
|
15
|
-
], EntityViewRecord);
|
|
16
|
-
export { EntityViewRecord };
|
package/dist/model/viewRecord.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { BeanModelBase, Model } from 'vona-module-a-database';
|
|
8
|
-
import { EntityViewRecord } from "../entity/viewRecord.js";
|
|
9
|
-
let ModelViewRecord = class ModelViewRecord extends BeanModelBase {
|
|
10
|
-
};
|
|
11
|
-
ModelViewRecord = __decorate([
|
|
12
|
-
Model({ entity: EntityViewRecord, disableDeleted: false, disableInstance: true })
|
|
13
|
-
], ModelViewRecord);
|
|
14
|
-
export { ModelViewRecord };
|
package/dist/service/database.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import chalk from 'chalk';
|
|
8
|
-
import moment from 'moment';
|
|
9
|
-
import { BeanBase } from 'vona';
|
|
10
|
-
import { Service } from 'vona-module-a-web';
|
|
11
|
-
const __separator = '-';
|
|
12
|
-
const __timeFormat = `YYYYMMDD${__separator}HHmmss`;
|
|
13
|
-
let ServiceDatabase = class ServiceDatabase extends BeanBase {
|
|
14
|
-
get configDatabase() {
|
|
15
|
-
return this.app.config.database;
|
|
16
|
-
}
|
|
17
|
-
get databasePrefix() {
|
|
18
|
-
return `cabloy${__separator}test${__separator}${this.app.name}${__separator}`;
|
|
19
|
-
}
|
|
20
|
-
async databaseInitStartup() {
|
|
21
|
-
// database
|
|
22
|
-
await this.__database();
|
|
23
|
-
// version start
|
|
24
|
-
await this.scope.service.version.__start();
|
|
25
|
-
}
|
|
26
|
-
async databaseNameStartup() {
|
|
27
|
-
// database
|
|
28
|
-
await this.__database();
|
|
29
|
-
}
|
|
30
|
-
async __fetchDatabases(client) {
|
|
31
|
-
// dbs
|
|
32
|
-
let dbs = await client.connection.schema.fetchDatabases(this.databasePrefix);
|
|
33
|
-
// filter
|
|
34
|
-
dbs = dbs.filter(db => {
|
|
35
|
-
const _time = db.name.substring(this.databasePrefix.length);
|
|
36
|
-
return _time.length === __timeFormat.length;
|
|
37
|
-
});
|
|
38
|
-
// ok
|
|
39
|
-
return dbs;
|
|
40
|
-
}
|
|
41
|
-
async __createDatabase(client) {
|
|
42
|
-
// create
|
|
43
|
-
const databaseName = `${this.databasePrefix}${moment().format(__timeFormat)}`;
|
|
44
|
-
await client.connection.schema.createDatabase(databaseName);
|
|
45
|
-
return databaseName;
|
|
46
|
-
}
|
|
47
|
-
async __database() {
|
|
48
|
-
if (this.app.meta.isProd) {
|
|
49
|
-
// donothing
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
// client
|
|
53
|
-
const client = this.bean.database.current.client;
|
|
54
|
-
// get current database name
|
|
55
|
-
let databaseName = client.getDatabaseName();
|
|
56
|
-
const isTestDatabase = databaseName.indexOf(this.databasePrefix) === 0;
|
|
57
|
-
// dev/debug db
|
|
58
|
-
if (this.app.meta.isLocal) {
|
|
59
|
-
// if enable testDatabase
|
|
60
|
-
const enableTestDatabase = this.configDatabase.testDatabase;
|
|
61
|
-
// check
|
|
62
|
-
if (!enableTestDatabase || isTestDatabase) {
|
|
63
|
-
// donothing
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const dbs = await this.__fetchDatabases(client);
|
|
67
|
-
if (dbs.length === 0) {
|
|
68
|
-
databaseName = await this.__createDatabase(client);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
databaseName = dbs[0].name;
|
|
72
|
-
}
|
|
73
|
-
// set config and reload client
|
|
74
|
-
await client.changeConfigAndReload(databaseName);
|
|
75
|
-
this.$logger.silly(chalk.cyan(`database: ${databaseName}, pid: ${process.pid}`));
|
|
76
|
-
}
|
|
77
|
-
// test db
|
|
78
|
-
if (this.app.meta.isTest) {
|
|
79
|
-
// check
|
|
80
|
-
if (isTestDatabase) {
|
|
81
|
-
// donothing
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
// drop old databases
|
|
85
|
-
const dbs = await this.__fetchDatabases(client);
|
|
86
|
-
for (const db of dbs) {
|
|
87
|
-
await client.connection.schema.dropDatabase(db.name);
|
|
88
|
-
}
|
|
89
|
-
// create database
|
|
90
|
-
const databaseName = await this.__createDatabase(client);
|
|
91
|
-
// set config and reload client
|
|
92
|
-
await client.changeConfigAndReload(databaseName);
|
|
93
|
-
// database ready
|
|
94
|
-
this.$logger.silly(chalk.cyan(`database: ${databaseName}, pid: ${process.pid}`));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
ServiceDatabase = __decorate([
|
|
99
|
-
Service()
|
|
100
|
-
], ServiceDatabase);
|
|
101
|
-
export { ServiceDatabase };
|
package/dist/service/version.js
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import chalk from 'chalk';
|
|
8
|
-
import { BeanBase } from 'vona';
|
|
9
|
-
import { Service } from 'vona-module-a-web';
|
|
10
|
-
let ServiceVersion = class ServiceVersion extends BeanBase {
|
|
11
|
-
async instanceInitStartup(options) {
|
|
12
|
-
const instanceBase = options?.configInstanceBase;
|
|
13
|
-
await this.__instanceInit(this.ctx.instanceName, instanceBase);
|
|
14
|
-
}
|
|
15
|
-
async __start() {
|
|
16
|
-
// update all modules
|
|
17
|
-
try {
|
|
18
|
-
const result = await this.__check({ scene: 'update' });
|
|
19
|
-
// clear columns cache
|
|
20
|
-
this.bean.database.current.columns.columnsClear();
|
|
21
|
-
// log
|
|
22
|
-
if (Object.keys(result).length > 0) {
|
|
23
|
-
this.$logger.info(JSON.stringify(result, null, 2));
|
|
24
|
-
}
|
|
25
|
-
this.$logger.silly(chalk.cyan('All modules are checked successfully!'));
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
this.$logger.silly(chalk.cyan('Modules are checked failed!'));
|
|
29
|
-
throw err;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
async __instanceInit(instanceName, instanceBase) {
|
|
33
|
-
if (instanceName === undefined || instanceName === null) {
|
|
34
|
-
throw new Error('instance name is not valid');
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
const optionsInit = Object.assign({}, instanceBase, { scene: 'init', instanceName });
|
|
38
|
-
await this.__check(optionsInit);
|
|
39
|
-
this.$logger.silly(chalk.cyan(`The instance is initialized successfully: ${instanceName || 'default'}`));
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
this.$logger.silly(chalk.cyan(`The instance is initialized failed: ${instanceName || 'default'}`));
|
|
43
|
-
throw err;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
async __instanceTest(instanceName) {
|
|
47
|
-
await this.__check({ scene: 'test', instanceName });
|
|
48
|
-
}
|
|
49
|
-
// scene: null/init/test
|
|
50
|
-
async __check(options) {
|
|
51
|
-
options.result = {};
|
|
52
|
-
if (options.scene === 'update') {
|
|
53
|
-
// confirm table aVersion exists
|
|
54
|
-
const entity = this.scope.entity.version;
|
|
55
|
-
const hasTableVersion = await this.bean.model.schema.hasTable(entity.$table);
|
|
56
|
-
if (!hasTableVersion) {
|
|
57
|
-
await this.bean.model.createTable(entity.$table, table => {
|
|
58
|
-
table.basicFieldsSimple({ deleted: false, iid: false });
|
|
59
|
-
table.string(entity.$column('module'), 255);
|
|
60
|
-
table.integer(entity.$column('version'));
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// check all modules
|
|
65
|
-
for (const module of this.app.meta.modulesArray) {
|
|
66
|
-
this.$loggerChild('version').debug('check module: %s, scene:%s', module.info.relativeName, options.scene);
|
|
67
|
-
await this.__checkModule(module.info.relativeName, options);
|
|
68
|
-
}
|
|
69
|
-
// version done
|
|
70
|
-
await this.bean.executor.newCtx(async () => {
|
|
71
|
-
await this.__done(options);
|
|
72
|
-
}, {
|
|
73
|
-
instanceName: options.instanceName,
|
|
74
|
-
});
|
|
75
|
-
// ok
|
|
76
|
-
return options.result;
|
|
77
|
-
}
|
|
78
|
-
// check module
|
|
79
|
-
async __checkModule(moduleName, options) {
|
|
80
|
-
// module
|
|
81
|
-
const module = this.__getModule(moduleName);
|
|
82
|
-
// fileVersionNew
|
|
83
|
-
let fileVersionNew = 0;
|
|
84
|
-
if (module.package.vonaModule && module.package.vonaModule.fileVersion) {
|
|
85
|
-
fileVersionNew = module.package.vonaModule.fileVersion;
|
|
86
|
-
}
|
|
87
|
-
if (fileVersionNew && ['update', 'init'].includes(options.scene)) {
|
|
88
|
-
// update module or init module
|
|
89
|
-
// -1: always
|
|
90
|
-
if (fileVersionNew === -1) {
|
|
91
|
-
await this.__updateModule(options, module, -1, -1);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
// fileVersionOld
|
|
95
|
-
let fileVersionOld = 0; // default
|
|
96
|
-
if (options.scene === 'update') {
|
|
97
|
-
const res = await this.bean.model
|
|
98
|
-
.builder('aVersion')
|
|
99
|
-
.select('*')
|
|
100
|
-
.where('module', moduleName)
|
|
101
|
-
.orderBy('version', 'desc')
|
|
102
|
-
.first();
|
|
103
|
-
if (res) {
|
|
104
|
-
fileVersionOld = res.version;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
const res = await this.bean.model
|
|
109
|
-
.builder('aVersionInit')
|
|
110
|
-
.select('*')
|
|
111
|
-
.where({ instanceName: options.instanceName, module: moduleName })
|
|
112
|
-
.orderBy('version', 'desc')
|
|
113
|
-
.first();
|
|
114
|
-
if (res) {
|
|
115
|
-
fileVersionOld = res.version;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
// check if need update
|
|
119
|
-
if (fileVersionOld > fileVersionNew) {
|
|
120
|
-
this.scope.error.ModuleOld.throw(moduleName);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
// not check if (fileVersionOld < fileVersionNew)
|
|
124
|
-
await this.__updateModule(options, module, fileVersionOld, fileVersionNew);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (options.scene === 'test') {
|
|
129
|
-
// test module
|
|
130
|
-
await this.bean.executor.newCtx(async () => {
|
|
131
|
-
await this.__testModuleTransaction(module, fileVersionNew, options);
|
|
132
|
-
}, {
|
|
133
|
-
instanceName: options.instanceName,
|
|
134
|
-
transaction: true,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
// update module or init module
|
|
139
|
-
async __updateModule(options, module, fileVersionOld, fileVersionNew) {
|
|
140
|
-
if (fileVersionNew === -1) {
|
|
141
|
-
// always
|
|
142
|
-
await this.__updateModule2(options, module, -1);
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
// versions
|
|
146
|
-
// always version:0
|
|
147
|
-
const versions = [0];
|
|
148
|
-
for (let version = fileVersionOld + 1; version <= fileVersionNew; version++) {
|
|
149
|
-
versions.push(version);
|
|
150
|
-
}
|
|
151
|
-
// loop
|
|
152
|
-
for (const version of versions) {
|
|
153
|
-
this.$loggerChild('version').debug('update module: %s, version: %d, scene:%s', module.info.relativeName, version, options.scene);
|
|
154
|
-
await this.__updateModule2(options, module, version);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
// log
|
|
158
|
-
if (fileVersionOld !== fileVersionNew) {
|
|
159
|
-
options.result[module.info.relativeName] = { fileVersionOld, fileVersionNew };
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async __updateModule2(options, module, version) {
|
|
163
|
-
// perform action
|
|
164
|
-
if (options.scene === 'update') {
|
|
165
|
-
// update
|
|
166
|
-
await this.bean.executor.newCtx(async () => {
|
|
167
|
-
await this.__updateModuleTransaction(module, version);
|
|
168
|
-
}, {
|
|
169
|
-
transaction: module.name !== 'a-index',
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
// init
|
|
174
|
-
await this.bean.executor.newCtx(async () => {
|
|
175
|
-
await this.__initModuleTransaction(module, version, options);
|
|
176
|
-
}, {
|
|
177
|
-
instanceName: options.instanceName,
|
|
178
|
-
transaction: true,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
async __updateModuleTransaction(module, version) {
|
|
183
|
-
// bean
|
|
184
|
-
const beanVersion = this.__getBeanVersion(module.info.relativeName, true);
|
|
185
|
-
if (!beanVersion.update)
|
|
186
|
-
throw new Error(`meta.version.update not exists for ${module.info.relativeName}`);
|
|
187
|
-
// clear columns cache
|
|
188
|
-
this.bean.database.current.columns.columnsClear();
|
|
189
|
-
// execute
|
|
190
|
-
await beanVersion.update({ version });
|
|
191
|
-
// insert record
|
|
192
|
-
if (version > 0) {
|
|
193
|
-
await this.bean.model.builder('aVersion').insert({ module: module.info.relativeName, version });
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
async __initModuleTransaction(module, version, options) {
|
|
197
|
-
// bean
|
|
198
|
-
const beanVersion = this.__getBeanVersion(module.info.relativeName, true);
|
|
199
|
-
// execute
|
|
200
|
-
if (beanVersion.init) {
|
|
201
|
-
await beanVersion.init({ ...options, version });
|
|
202
|
-
}
|
|
203
|
-
// insert record
|
|
204
|
-
if (version > 0) {
|
|
205
|
-
await this.bean.model.insert('aVersionInit', {
|
|
206
|
-
instanceName: options.instanceName,
|
|
207
|
-
module: module.info.relativeName,
|
|
208
|
-
version,
|
|
209
|
-
}, { disableInstance: true, disableDeleted: true });
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
// test module
|
|
213
|
-
async __testModuleTransaction(module, version, options) {
|
|
214
|
-
// bean
|
|
215
|
-
const beanVersion = this.__getBeanVersion(module.info.relativeName, false);
|
|
216
|
-
// execute
|
|
217
|
-
if (beanVersion && beanVersion.test) {
|
|
218
|
-
await beanVersion.test({ ...options, version });
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
async __done(options) {
|
|
222
|
-
await this.scope.event.versionDone.emit(options);
|
|
223
|
-
}
|
|
224
|
-
// get module
|
|
225
|
-
__getModule(moduleName) {
|
|
226
|
-
return this.app.meta.modules[moduleName];
|
|
227
|
-
}
|
|
228
|
-
__getBeanVersion(moduleName, throwErrorIfEmpty) {
|
|
229
|
-
// bean
|
|
230
|
-
const beanVersion = this.bean._getBean(`${moduleName}.meta.version`);
|
|
231
|
-
if (!beanVersion && throwErrorIfEmpty)
|
|
232
|
-
throw new Error(`meta.version not exists for ${moduleName}`);
|
|
233
|
-
return beanVersion;
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
ServiceVersion = __decorate([
|
|
237
|
-
Service()
|
|
238
|
-
], ServiceVersion);
|
|
239
|
-
export { ServiceVersion };
|
package/dist/types/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./version.js";
|
package/dist/types/version.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|