Skip to content

Commit

Permalink
fix: deprecate setting quoteIdentifiers to false (#15879)
Browse files Browse the repository at this point in the history
  • Loading branch information
WikiRik committed Apr 1, 2023
1 parent 3cfe672 commit 54e0db4
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/dialects/postgres/query-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -854,12 +854,12 @@ export class PostgresQueryGenerator extends PostgresQueryGeneratorTypeScript {
*/
quoteIdentifier(identifier, force) {
const optForceQuote = force || false;
// TODO: remove "quoteIdentifiers: false" option
// TODO [>7]: remove "quoteIdentifiers: false" option
const optQuoteIdentifiers = this.options.quoteIdentifiers !== false;

if (
optForceQuote === true
// TODO: drop this.options.quoteIdentifiers. Always quote identifiers based on these rules
// TODO [>7]: drop this.options.quoteIdentifiers. Always quote identifiers based on these rules
|| optQuoteIdentifiers !== false
|| identifier.includes('.')
|| identifier.includes('->')
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/dialects/postgres/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export class PostgresQuery extends AbstractQuery {
let result = rows;
// Postgres will treat tables as case-insensitive, so fix the case
// of the returned values to match attributes
// TODO [>7]: remove this.sequelize.options.quoteIdentifiers === false
if (this.options.raw === false && this.sequelize.options.quoteIdentifiers === false) {
const attrsMap = Object.create(null);

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/dialects/snowflake/query-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,12 @@ export class SnowflakeQueryGenerator extends SnowflakeQueryGeneratorTypeScript {
*/
quoteIdentifier(identifier, force) {
const optForceQuote = force || false;
// TODO [>7]: remove "quoteIdentifiers: false" option
const optQuoteIdentifiers = this.options.quoteIdentifiers !== false;

if (
optForceQuote === true
// TODO: drop this.options.quoteIdentifiers. Always quote identifiers.
// TODO [>7]: drop this.options.quoteIdentifiers. Always quote identifiers.
|| optQuoteIdentifiers !== false
|| identifier.includes('.')
|| identifier.includes('->')
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/dialects/snowflake/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export class SnowflakeQuery extends AbstractQuery {
if (this.isSelectQuery()) {
// Snowflake will treat tables as case-insensitive, so fix the case
// of the returned values to match attributes
// TODO [>7]: remove this.sequelize.options.quoteIdentifiers === false
if (this.options.raw === false && this.sequelize.options.quoteIdentifiers === false) {
const attrsMap = Object.create(null);

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/sequelize.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ export interface Options extends Logging {
*/
pool?: PoolOptions;

// TODO [>7]: remove this option
/**
* Set to `false` to make table names and attributes case-insensitive on Postgres and skip double quoting of
* them.
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class Sequelize extends SequelizeTypeScript {
native: false,
replication: false,
ssl: undefined,
// TODO [=7]: print a deprecation warning if quoteIdentifiers is set to false
// TODO [>7]: remove this option
quoteIdentifiers: true,
hooks: {},
retry: {
Expand Down Expand Up @@ -304,6 +304,10 @@ export class Sequelize extends SequelizeTypeScript {
this.options.logging = console.debug;
}

if (this.options.quoteIdentifiers === false) {
deprecations.alwaysQuoteIdentifiers();
}

if (options.hooks) {
this.hooks.addListeners(options.hooks);
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export const noModelTableName = deprecate(noop, 'Model.tableName has been replac
export const noNewModel = deprecate(noop, `Do not use "new YourModel()" to instantiate a model. Use "YourModel.build()" instead. The previous option is being removed to resolve a conflict with class properties. See https://github.com/sequelize/sequelize/issues/14300#issuecomment-1355188077 for more information.`, 'SEQUELIZE0020');
export const noOpCol = deprecate(noop, 'Do not use Op.col, use col(), attribute(), or identifier() instead. Read more about these in the Raw Queries guide in the sequelize docs.', 'SEQUELIZE0021');
export const noSqlJson = deprecate(noop, 'The json() function used to generate JSON queries is deprecated. All of its features are available through where(), attribute() or jsonPath(). Some of its features have been removed but can be replicated using the "sql" tag. See our Sequelize 7 upgrade guide.', 'SEQUELIZE0022');
export const alwaysQuoteIdentifiers = deprecate(noop, 'Setting "quoteIdentifiers" to false is unsafe and it will be removed in v8.', 'SEQUELIZE0023');
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('QueryGenerator#dropDatabaseQuery', () => {
expectsql(() => noQuoteQueryGenerator.dropDatabaseQuery('myDatabase'), {
default: notSupportedError,
'postgres snowflake': 'DROP DATABASE IF EXISTS myDatabase;',
// TODO: mssql does not respect quoteIdentifiers in this method
mssql: `IF EXISTS (SELECT * FROM sys.databases WHERE name = 'myDatabase' ) BEGIN DROP DATABASE [myDatabase] ; END;`,
});
});
Expand Down

0 comments on commit 54e0db4

Please sign in to comment.