修正了初始化数据过程
This commit is contained in:
parent
bd62c3ce23
commit
5e8954012e
|
|
@ -168,7 +168,6 @@ class AppLoader extends types_1.AppLoader {
|
||||||
await this.dbStore.initialize(dropIfExists);
|
await this.dbStore.initialize(dropIfExists);
|
||||||
const data = this.requireSth('lib/data/index');
|
const data = this.requireSth('lib/data/index');
|
||||||
const context = await this.contextBuilder()(this.dbStore);
|
const context = await this.contextBuilder()(this.dbStore);
|
||||||
await context.begin();
|
|
||||||
for (const entity in data) {
|
for (const entity in data) {
|
||||||
let rows = data[entity];
|
let rows = data[entity];
|
||||||
if (entity === 'area') {
|
if (entity === 'area') {
|
||||||
|
|
@ -176,17 +175,25 @@ class AppLoader extends types_1.AppLoader {
|
||||||
rows = require('./data/area.json');
|
rows = require('./data/area.json');
|
||||||
}
|
}
|
||||||
if (rows.length > 0) {
|
if (rows.length > 0) {
|
||||||
await this.dbStore.operate(entity, {
|
await context.begin();
|
||||||
data: rows,
|
try {
|
||||||
action: 'create',
|
await this.dbStore.operate(entity, {
|
||||||
}, context, {
|
data: rows,
|
||||||
dontCollect: true,
|
action: 'create',
|
||||||
dontCreateOper: true,
|
}, context, {
|
||||||
});
|
dontCollect: true,
|
||||||
console.log(`data in ${entity} initialized!`);
|
dontCreateOper: true,
|
||||||
|
});
|
||||||
|
await context.commit();
|
||||||
|
console.log(`data in ${entity} initialized!`);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
await context.rollback();
|
||||||
|
console.error(`data on ${entity} initilization failed!`);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await context.commit();
|
|
||||||
this.dbStore.disconnect();
|
this.dbStore.disconnect();
|
||||||
}
|
}
|
||||||
getStore() {
|
getStore() {
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,12 @@ class DbStore extends oak_db_1.MysqlStore {
|
||||||
this.relationAuth = new RelationAuth_1.RelationAuth(storageSchema, actionCascadeGraph, relationCascadeGraph, authDeduceRelationMap, selectFreeEntities);
|
this.relationAuth = new RelationAuth_1.RelationAuth(storageSchema, actionCascadeGraph, relationCascadeGraph, authDeduceRelationMap, selectFreeEntities);
|
||||||
}
|
}
|
||||||
async cascadeUpdateAsync(entity, operation, context, option) {
|
async cascadeUpdateAsync(entity, operation, context, option) {
|
||||||
if (!option.blockTrigger) {
|
// 如果是在modi处理过程中,所有的trigger也可以延时到apply时再处理(这时候因为modi中的数据并不实际存在,处理会有问题)
|
||||||
|
if (!option.blockTrigger && !option.modiParentEntity) {
|
||||||
await this.executor.preOperation(entity, operation, context, option);
|
await this.executor.preOperation(entity, operation, context, option);
|
||||||
}
|
}
|
||||||
const result = await super.cascadeUpdateAsync(entity, operation, context, option);
|
const result = await super.cascadeUpdateAsync(entity, operation, context, option);
|
||||||
if (!option.blockTrigger) {
|
if (!option.blockTrigger && !option.modiParentEntity) {
|
||||||
await this.executor.postOperation(entity, operation, context, option);
|
await this.executor.postOperation(entity, operation, context, option);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,6 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Async
|
||||||
|
|
||||||
const data = this.requireSth('lib/data/index');
|
const data = this.requireSth('lib/data/index');
|
||||||
const context = await this.contextBuilder()(this.dbStore);
|
const context = await this.contextBuilder()(this.dbStore);
|
||||||
await context.begin();
|
|
||||||
for (const entity in data) {
|
for (const entity in data) {
|
||||||
let rows = data[entity];
|
let rows = data[entity];
|
||||||
if (entity === 'area') {
|
if (entity === 'area') {
|
||||||
|
|
@ -217,17 +216,25 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Async
|
||||||
rows = require('./data/area.json');
|
rows = require('./data/area.json');
|
||||||
}
|
}
|
||||||
if (rows.length > 0) {
|
if (rows.length > 0) {
|
||||||
await this.dbStore.operate(entity as keyof ED, {
|
await context.begin();
|
||||||
data: rows,
|
try {
|
||||||
action: 'create',
|
await this.dbStore.operate(entity as keyof ED, {
|
||||||
} as any, context, {
|
data: rows,
|
||||||
dontCollect: true,
|
action: 'create',
|
||||||
dontCreateOper: true,
|
} as any, context, {
|
||||||
});
|
dontCollect: true,
|
||||||
console.log(`data in ${entity} initialized!`);
|
dontCreateOper: true,
|
||||||
|
});
|
||||||
|
await context.commit();
|
||||||
|
console.log(`data in ${entity} initialized!`);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
await context.rollback();
|
||||||
|
console.error(`data on ${entity} initilization failed!`);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await context.commit();
|
|
||||||
this.dbStore.disconnect();
|
this.dbStore.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,12 @@ export class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncCo
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async cascadeUpdateAsync<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: AsyncContext<ED>, option: MysqlOperateOption) {
|
protected async cascadeUpdateAsync<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: AsyncContext<ED>, option: MysqlOperateOption) {
|
||||||
if (!option.blockTrigger) {
|
// 如果是在modi处理过程中,所有的trigger也可以延时到apply时再处理(这时候因为modi中的数据并不实际存在,处理会有问题)
|
||||||
|
if (!option.blockTrigger && !option.modiParentEntity) {
|
||||||
await this.executor.preOperation(entity, operation, context, option);
|
await this.executor.preOperation(entity, operation, context, option);
|
||||||
}
|
}
|
||||||
const result = await super.cascadeUpdateAsync(entity, operation, context, option);
|
const result = await super.cascadeUpdateAsync(entity, operation, context, option);
|
||||||
if (!option.blockTrigger) {
|
if (!option.blockTrigger && !option.modiParentEntity) {
|
||||||
await this.executor.postOperation(entity, operation, context, option);
|
await this.executor.postOperation(entity, operation, context, option);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue