Skip to content

Commit

Permalink
refactor: typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaschaaf committed Aug 13, 2020
1 parent 16669d9 commit c380d99
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export {
Constructor, Dictionary, PrimaryKeyType, Primary, IPrimaryKey, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter,
AnyEntity, EntityProperty, EntityMetadata, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection,
GetRepository, EntityRepositoryType, MigrationObject,
GetRepository, EntityRepositoryType, MigrationObject, Migration,
} from './typings';
export * from './enums';
export * from './exceptions';
Expand Down
4 changes: 2 additions & 2 deletions packages/migrations/src/Migration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Configuration } from '@mikro-orm/core';
import { Configuration, Migration as CoreMigration } from '@mikro-orm/core';
import { AbstractSqlDriver } from '@mikro-orm/knex';

export abstract class Migration {
export abstract class Migration implements CoreMigration {

private readonly queries: string[] = [];

Expand Down
8 changes: 3 additions & 5 deletions packages/migrations/src/Migrator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @ts-ignore
import umzug, { Umzug, migrationsList } from 'umzug';
import umzug, { Umzug, migrationsList, MigrationDefinitionWithName, MigrationOptions, Migration as UmzugMigration } from 'umzug';
import { Utils, Constructor, MigrationObject } from '@mikro-orm/core';
import { SchemaGenerator, EntityManager } from '@mikro-orm/knex';
import { Migration } from './Migration';
Expand All @@ -19,7 +18,7 @@ export class Migrator {
private readonly storage = new MigrationStorage(this.driver, this.options);

constructor(private readonly em: EntityManager) {
let migrations = {
let migrations: MigrationOptions | UmzugMigration[] = {
path: Utils.absolutePath(this.options.path!, this.config.get('baseDir')),
pattern: this.options.pattern,
customResolver: (file: string) => this.resolve(file),
Expand All @@ -31,7 +30,7 @@ export class Migrator {
this.initialize(
migration.class as unknown as Constructor<Migration>,
migration.name
)
) as MigrationDefinitionWithName
)
);
}
Expand Down Expand Up @@ -148,7 +147,6 @@ export class Migrator {

}

export type UmzugMigration = { path?: string; file: string };

This comment has been minimized.

Copy link
@B4nan

B4nan Aug 13, 2020

Member

the reason why i defined the type myself was similar issue like the one you were facing, there was some hidden dependency that required something to be installed in the user land.

but thanks, will integrate bits of this to the master too!

export type MigrateOptions = { from?: string | number; to?: string | number; migrations?: string[] };
export type MigrationResult = { fileName: string; code: string; diff: string[] };
export type MigrationRow = { name: string; executed_at: Date };
11 changes: 11 additions & 0 deletions packages/migrations/src/custom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Migration } from 'umzug';

declare module 'umzug' {
interface MigrationDefinitionWithName extends Migration {
name: string;
}

interface UmzugStatic {
migrationsList(migrations: MigrationDefinitionWithName[], parameters?: any[]): Migration[];
}
}

0 comments on commit c380d99

Please sign in to comment.