Skip to content

Commit

Permalink
fix(migrations): ensure executedAt is a Date when listing executed …
Browse files Browse the repository at this point in the history
…migrations

This fixes usage of `migration:list` in SQLite.

Closes #2817
  • Loading branch information
B4nan committed Feb 25, 2022
1 parent f2b09f5 commit c8753ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/migrations/src/MigrationStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ export class MigrationStorage implements UmzugStorage {
qb.transacting(this.masterTransaction);
}

return this.connection.execute<MigrationRow[]>(qb);
const res = await this.connection.execute<MigrationRow[]>(qb);

return res.map(row => {
if (typeof row.executed_at === 'string') {
row.executed_at = new Date(row.executed_at);
}

return row;
});
}

async ensureTable(): Promise<void> {
Expand Down
4 changes: 3 additions & 1 deletion tests/features/migrations/Migrator.sqlite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ describe('Migrator (sqlite)', () => {

await storage.ensureTable(); // creates the table
await storage.logMigration({ name: 'test', context: null });
await expect(storage.getExecutedMigrations()).resolves.toMatchObject([{ name: 'test' }]);
const executed = await storage.getExecutedMigrations();
expect(executed).toMatchObject([{ name: 'test' }]);
expect(executed[0].executed_at).toBeInstanceOf(Date);
await expect(storage.executed()).resolves.toEqual(['test']);

await storage.ensureTable(); // table exists, no-op
Expand Down

0 comments on commit c8753ee

Please sign in to comment.