diff --git a/src/sqlRunner.ts b/src/sqlRunner.ts index 5d9e9e95..ddb49b97 100644 --- a/src/sqlRunner.ts +++ b/src/sqlRunner.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import { reverse } from 'ramda'; +import { reverse, keys } from 'ramda'; import * as fs from './util/fs'; import { dbLogger } from './logger'; @@ -94,7 +94,13 @@ export function extractSqlFileInfo(filePath: string): SqlFileInfo { export function getDropStatement(type: string, fqon: string): string { const dropStatement = dropStatementsMap[type]; - return dropStatement ? `${dropStatement} ${fqon}` : ''; + if (!dropStatement) { + const message = `Naming convention must be one of: ${keys(dropStatementsMap)}.`; + + throw new Error(`No database object type: ${type}. ${message}`); + } + + return `${dropStatement} ${fqon}`; } /** diff --git a/test/sqlRunner.test.ts b/test/sqlRunner.test.ts index 462e30b2..2d267c68 100644 --- a/test/sqlRunner.test.ts +++ b/test/sqlRunner.test.ts @@ -64,5 +64,9 @@ describe('UTIL: sqlRunner', () => { it('should return DROP statement for a view', () => { expect(sqlRunner.getDropStatement('view', 'test.hello_world')).to.equal('DROP VIEW IF EXISTS test.hello_world'); }); + + it('should throw an error if naming convention of the object is wrong', () => { + expect(() => sqlRunner.getDropStatement('views', 'test.hello_world')).to.throw(Error); + }); }); });