diff --git a/config/config.json b/config/config.json index b653bd7..000a33a 100644 --- a/config/config.json +++ b/config/config.json @@ -81,6 +81,12 @@ ], "exclude_tables": [], + "include_tables_description": [ + "List (Array) of tables, that will not be migrated.", + "By default, nmig will migrate all tables." + ], + "include_tables": [], + "migrate_only_data_description" : [ "In order to skip schema migration, and just migrate data into a preset tables", "fill following array with preset table names.", diff --git a/src/Conversion.ts b/src/Conversion.ts index 3878b22..0487132 100644 --- a/src/Conversion.ts +++ b/src/Conversion.ts @@ -106,10 +106,15 @@ export default class Conversion { public readonly _noVacuum: string[]; /** - * List of tables, that will not be migrated.List (Array) of tables, that will not be migrated. + * List of tables, that will not be migrated. */ public readonly _excludeTables: string[]; + /** + * List of tables, that will be migrated. + */ + public readonly _includeTables: string[]; + /** * The timestamp, at which the migration began. */ @@ -209,6 +214,7 @@ export default class Conversion { this._notCreatedViewsPath = path.join(this._logsDirPath, 'not_created_views'); this._noVacuum = this._config.no_vacuum === undefined ? [] : this._config.no_vacuum; this._excludeTables = this._config.exclude_tables === undefined ? [] : this._config.exclude_tables; + this._includeTables = this._config.include_tables === undefined ? [] : this._config.include_tables; this._timeBegin = new Date(); this._encoding = this._config.encoding === undefined ? 'utf8' : this._config.encoding; this._dataChunkSize = this._config.data_chunk_size === undefined ? 1 : +this._config.data_chunk_size; diff --git a/src/StructureLoader.ts b/src/StructureLoader.ts index 4ad7100..d89f06f 100644 --- a/src/StructureLoader.ts +++ b/src/StructureLoader.ts @@ -62,7 +62,17 @@ export default async (conversion: Conversion): Promise => { await getMySqlVersion(conversion); const dbAccess: DBAccess = new DBAccess(conversion); const haveTablesLoaded: boolean = await migrationStateManager.get(conversion, 'tables_loaded'); - const sql: string = `SHOW FULL TABLES IN \`${ conversion._mySqlDbName }\`;`; + let sql: string = `SHOW FULL TABLES IN \`${ conversion._mySqlDbName }\` WHERE 1 = 1`; + + if (conversion._includeTables.length !== 0) { + sql += ` AND Tables_in_${ conversion._mySqlDbName } IN(${ conversion._includeTables.map((table: string) => `"${table}"`).join(',') })`; + } + + if (conversion._excludeTables.length !== 0) { + sql += ` AND Tables_in_${ conversion._mySqlDbName } NOT IN(${ conversion._excludeTables.map((table: string) => `"${table}"`).join(',') })`; + } + + sql += ';'; const result: DBAccessQueryResult = await dbAccess.query('StructureLoader::default', sql, DBVendors.MYSQL, true, false); let tablesCnt: number = 0; let viewsCnt: number = 0;