Skip to content

Commit

Permalink
fix: seeds without timestamp should be considered older
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Jul 15, 2023
1 parent 5f6d98f commit f511978
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/seeder/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export class SeederExecutor {
...(seedName ? { seedName } : {}),
});

const timestampFallback = Date.now();
let timestampCounter = 0;
const entities = seeds.map((element) => {
const {
Expand All @@ -138,7 +137,7 @@ export class SeederExecutor {

const entity = new SeederEntity({
fileName,
timestamp: timestamp || timestampFallback + timestampCounter,
timestamp: timestamp || timestampCounter,
name: className,
constructor: seed,
});
Expand All @@ -150,7 +149,7 @@ export class SeederExecutor {

this.checkForDuplicateMigrations(entities);

// sort them by timestamp
// sort them by file name than by timestamp
return entities.sort((a, b) => {
if (
typeof a.fileName !== 'undefined' &&
Expand All @@ -159,14 +158,7 @@ export class SeederExecutor {
return a.name > b.name ? 1 : -1;
}

if (
typeof a.timestamp !== 'undefined' &&
typeof b.timestamp !== 'undefined'
) {
return a.timestamp - b.timestamp;
}

return 1;
return a.timestamp - b.timestamp;
});
}

Expand Down

0 comments on commit f511978

Please sign in to comment.