Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: migrate removeIndexQuery to TypeScript (#15406)
* fix(mssql): updated quoting methods * meta: add remove index query options type * feat: migrate removeIndexQuery to typescript * feat: unify and fix removeIndexQuery tests * fix(postgres): indexes can be schema qualified * fix: remove blank lines in test Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com> * fix: remove unneeded test * fix(mariadb): migrate function to typescript * fix: remove unneeded type argument * fix(postgres): cannot have casecade & concurrently * fix(snowflake): remove unneeded joinSQLFragments Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com> * fix(snowflake): remove unused import * fix(ibmi): use quoteIdentifier for if check Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com> * fix: should return string Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com> * fix(snowflake): indexes are not supported * fix: only retrieve table details when required * fix(postgres): remove check since all supported * fix: use keyof for key checking * fix: use REMOVE_INDEX_QUERY_SUPPORTED_OPTIONS * fix(ibmi): update test for quoteIdentifier * fix: declare supported options outside of class * fix: options should be optional in queries * fix(postgres): always include schema in query * fix(types): move removeIndex options to interface * fix(types): update type to object * fix(types): change options to interface Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com>
- Loading branch information
Showing
26 changed files
with
421 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { rejectInvalidOptions } from '../../utils/check'; | ||
import { joinSQLFragments } from '../../utils/join-sql-fragments'; | ||
import { generateIndexName } from '../../utils/string'; | ||
import { REMOVE_INDEX_QUERY_SUPPORTABLE_OPTIONS } from '../abstract/query-generator-typescript'; | ||
import type { RemoveIndexQueryOptions, TableNameOrModel } from '../abstract/query-generator-typescript'; | ||
import { MySqlQueryGenerator } from '../mysql/query-generator.js'; | ||
|
||
const REMOVE_INDEX_QUERY_SUPPORTED_OPTIONS = new Set<keyof RemoveIndexQueryOptions>(['ifExists']); | ||
|
||
/** | ||
* Temporary class to ease the TypeScript migration | ||
*/ | ||
export class MariaDbQueryGeneratorTypeScript extends MySqlQueryGenerator { | ||
removeIndexQuery( | ||
tableName: TableNameOrModel, | ||
indexNameOrAttributes: string | string[], | ||
options?: RemoveIndexQueryOptions, | ||
) { | ||
if (options) { | ||
rejectInvalidOptions( | ||
'removeIndexQuery', | ||
this.dialect.name, | ||
REMOVE_INDEX_QUERY_SUPPORTABLE_OPTIONS, | ||
REMOVE_INDEX_QUERY_SUPPORTED_OPTIONS, | ||
options, | ||
); | ||
} | ||
|
||
let indexName; | ||
if (Array.isArray(indexNameOrAttributes)) { | ||
const table = this.extractTableDetails(tableName); | ||
indexName = generateIndexName(table, { fields: indexNameOrAttributes }); | ||
} else { | ||
indexName = indexNameOrAttributes; | ||
} | ||
|
||
return joinSQLFragments([ | ||
'DROP INDEX', | ||
options?.ifExists ? 'IF EXISTS' : '', | ||
this.quoteIdentifier(indexName), | ||
'ON', | ||
this.quoteTable(tableName), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.