added migration interface

This commit is contained in:
Umed Khudoiberdiev 2016-12-10 16:25:16 +05:00
parent c55094810d
commit 4a8250c31e
3 changed files with 19 additions and 3 deletions

View File

@ -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<boolean> {
const sql = `SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '${this.dbName}' AND TABLE_NAME = '${table.name}'`;
async hasTable(tableName: string): Promise<boolean> {
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;
}

View File

@ -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<any>;
/**
* Reverse the migrations.
*/
down(queryRunner: QueryRunner, connection: Connection): Promise<any>;
}

View File

@ -92,7 +92,7 @@ export interface QueryRunner {
/**
* Checks if table with the given name exist in the database.
*/
hasTable(table: TableSchema): Promise<boolean>;
hasTable(tableName: string): Promise<boolean>;
/**
* Creates a new table from the given table metadata and column metadatas.