Skip to content

Commit

Permalink
TW-683: Assets rework. Migrations made async
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-tsx committed Sep 28, 2023
1 parent b1cb514 commit 515b544
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/lib/local-storage/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { IMigration, IAppliedMigration } from 'lib/migrator';

const STORAGE_KEY = 'MIGRATIONS';

export const migrate = (migrations: IMigration[]) => {
export const migrate = async (migrations: IMigration[]) => {
const appliedMigrations = getAppliedMigrations();

const appliedMigrationsThisTime = Migrator.migrate(migrations, appliedMigrations);
const appliedMigrationsThisTime = await Migrator.migrate(migrations, appliedMigrations);

storeAppliedMigrations(appliedMigrations.concat(appliedMigrationsThisTime));
};
Expand Down
6 changes: 3 additions & 3 deletions src/lib/migrator.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
export interface IMigration {
name: string;
up: () => void;
up: () => void | Promise<void>;
}

export interface IAppliedMigration {
name: string;
dateApplied: Date;
}

export const migrate = (migrations: IMigration[], appliedMigrations: IAppliedMigration[]) => {
export const migrate = async (migrations: IMigration[], appliedMigrations: IAppliedMigration[]) => {
const migrationsToRun = migrations.filter(({ name }) => appliedMigrations.findIndex(m => m.name === name) === -1);

const appliedMigrationsThisTime: IAppliedMigration[] = [];

for (const migration of migrationsToRun) {
migration.up();
await migration.up();
appliedMigrationsThisTime.push({
name: migration.name,
dateApplied: new Date()
Expand Down

0 comments on commit 515b544

Please sign in to comment.