Skip to content

Commit

Permalink
feat: prioritize seeder track property over global option
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Jan 18, 2024
1 parent c9ea8b4 commit b21bb6f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/seeder/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ export class SeederEntity {
this.filePath = ctx.filePath;
}

trackExecution() : boolean {
return !!this.instance &&
typeof this.instance.track === 'boolean' &&
this.instance.track;
get trackExecution() : boolean | undefined {
if (typeof this.instance === 'undefined') {
return undefined;
}

return this.instance.track;
}
}
24 changes: 21 additions & 3 deletions src/seeder/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class SeederExecutor {

let tracking = !!options.seedTracking;
if (!tracking) {
tracking = all.some((seed) => seed.trackExecution());
tracking = all.some((seed) => !!seed.trackExecution);
}

let queryRunner : QueryRunner | undefined;
Expand Down Expand Up @@ -90,7 +90,18 @@ export class SeederExecutor {
(el) => el.name === seed.name,
);

return index === -1 || !seed.trackExecution();
if (index === -1) {
return true;
}

let seedTracking : boolean | undefined;
if (typeof seed.trackExecution !== 'undefined') {
seedTracking = seed.trackExecution;
} else {
seedTracking = options.seedTracking;
}

return !seedTracking;
});

if (pending.length === 0) {
Expand Down Expand Up @@ -121,7 +132,14 @@ export class SeederExecutor {

pending[i].result = await seeder.run(this.dataSource, factoryManager);

if (queryRunner && (options.seedTracking || pending[i].trackExecution())) {
let seedTracking : boolean | undefined;
if (typeof pending[i].trackExecution !== 'undefined') {
seedTracking = pending[i].trackExecution;
} else {
seedTracking = options.seedTracking;
}

if (queryRunner && seedTracking) {
await this.track(queryRunner, pending[i]);
}

Expand Down

0 comments on commit b21bb6f

Please sign in to comment.