From 4a8250c31e1a2d3101527ef8d1d0e9090ef65b38 Mon Sep 17 00:00:00 2001 From: Umed Khudoiberdiev Date: Sat, 10 Dec 2016 16:25:16 +0500 Subject: [PATCH] added migration interface --- src/driver/mysql/MysqlQueryRunner.ts | 4 ++-- src/migration/MigrationInterface.ts | 16 ++++++++++++++++ src/query-runner/QueryRunner.ts | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/migration/MigrationInterface.ts diff --git a/src/driver/mysql/MysqlQueryRunner.ts b/src/driver/mysql/MysqlQueryRunner.ts index 983701083..3f9615bfe 100644 --- a/src/driver/mysql/MysqlQueryRunner.ts +++ b/src/driver/mysql/MysqlQueryRunner.ts @@ -336,8 +336,8 @@ export class MysqlQueryRunner implements QueryRunner { /** * Checks if table with the given name exist in the database. */ - async hasTable(table: TableSchema): Promise { - const sql = `SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '${this.dbName}' AND TABLE_NAME = '${table.name}'`; + async hasTable(tableName: string): Promise { + const sql = `SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '${this.dbName}' AND TABLE_NAME = '${tableName}'`; const result = await this.query(sql); return result.length ? true : false; } diff --git a/src/migration/MigrationInterface.ts b/src/migration/MigrationInterface.ts new file mode 100644 index 000000000..cff6acde2 --- /dev/null +++ b/src/migration/MigrationInterface.ts @@ -0,0 +1,16 @@ +import {Connection} from "../connection/Connection"; +import {QueryRunner} from "../query-runner/QueryRunner"; + +export interface MigrationInterface { + + /** + * Run the migrations. + */ + up(queryRunner: QueryRunner, connection: Connection): Promise; + + /** + * Reverse the migrations. + */ + down(queryRunner: QueryRunner, connection: Connection): Promise; + +} \ No newline at end of file diff --git a/src/query-runner/QueryRunner.ts b/src/query-runner/QueryRunner.ts index 3efc233d4..5fd6e72da 100644 --- a/src/query-runner/QueryRunner.ts +++ b/src/query-runner/QueryRunner.ts @@ -92,7 +92,7 @@ export interface QueryRunner { /** * Checks if table with the given name exist in the database. */ - hasTable(table: TableSchema): Promise; + hasTable(tableName: string): Promise; /** * Creates a new table from the given table metadata and column metadatas.