Skip to content

meta: unify attributesToSQL test and type attributesToSQL and attributeToSQL - #15533

Closed
WikiRik wants to merge 20 commits into
mainfrom
WikiRik/attributes-to-sql-unit-tests
Closed

WikiRik wants to merge 20 commits into
mainfrom
WikiRik/attributes-to-sql-unit-tests

Conversation

@WikiRik

@WikiRik WikiRik commented Jan 6, 2023

Copy link
Copy Markdown
Member

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description Of Change

Just like #15526 this PR is smaller than the others. I just want to get rid of the dialect specific QueryGenerator unit tests and doing it properly just gets me in a too big of a rabbit hole. Future PRs should migrate attributesToSQL and attributeToSQL and overhaul the test suite.

@WikiRik
WikiRik marked this pull request as ready for review January 9, 2023 08:41
@WikiRik
WikiRik marked this pull request as draft March 12, 2023 10:24
@WikiRik
WikiRik marked this pull request as ready for review March 12, 2023 11:01
@WikiRik
WikiRik requested review from ephys and removed request for ephys March 12, 2023 11:03
});
});

// TODO: check what this test is supposed to do and update the possible defaultValue accordingly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is broken and should be split into multiple tests:

  • One that uses DataTypes.ARRAY (on dialects that support this type) with an empty array: should work
  • One that uses DataTypes.BLOB: should never work, [] is not a valid value on a blob
  • One that uses DataTypes.JSON (on dialects that support this type) : should always work
  • One that uses any string type (like 'JSON' instead DataTypes.JSON): should never work because can't guess the type of an empty array and string types don't give any information

Note that the data type is an actual data type and not a string in the above two tests

});

// TODO: this test is broken for at least DB2. It adds the default value because the data type is a string, which can't have special behaviors.
// change type to an actual Sequelize DataType & re-enable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this instance it's honestly default that's broken. String types don't give any information so the default value should always be added.

If DataTypes.BLOB were used, then the dialect could enforce specific behaviors

});
});

// TODO: check what this test is supposed to do and update the possible defaultValue accordingly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remarks as the above three review notes:

Because the type is a string instead of an instanceof DataType, no special behavior can occur. We use string data types as-is, it's the equivalent of using a literal()
This test should use DataTypes.TEXT instead

An array is also not a good type to use to test that the default value is not added: A string would be a better value

});
});

// TODO: check what this test is supposed to do and update the possible defaultValue accordingly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

});

// TODO: check what this test is supposed to do and update the possible defaultValue accordingly
it(`No Default value for JSON allowed for some dialects`, () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@WikiRik
WikiRik marked this pull request as draft March 12, 2023 13:42
@WikiRik

WikiRik commented Apr 12, 2024

Copy link
Copy Markdown
Member Author

Superseded by and linked in #17121

@WikiRik WikiRik closed this Apr 12, 2024
@WikiRik
WikiRik deleted the WikiRik/attributes-to-sql-unit-tests branch April 12, 2024 06:07
wikirik-agent added a commit to wikirik-agent/sequelize that referenced this pull request Sep 11, 2026
Moves both methods out of every dialect's `query-generator.js` and into its
`query-generator-typescript.internal.ts`, and renames them from `attributeToSQL`
/ `attributesToSQL` to `attributeToSql` / `attributesToSql`.

Closes the last item of sequelize#15533.

The core declaration is now a typed contract every dialect implements, rather
than a `ColumnsDescription` signature that described none of them. The new
`AttributeToSqlColumn` interface documents what the dialects actually read, and
is deliberately wider than `NormalizedAttributeOptions` because these methods
are also called with `describeTable` output, where the type is a raw SQL string.

`isBinaryStringType` joins `attributeTypeToDataTypeId` in the core data type
utilities, replacing the `attribute.type.options?.binary` reach-through.

No SQL changes. The pinned suites produce byte-identical output for all nine
dialects. Typing the tests did surface two things they were getting wrong:
a `deferrable` passed as a raw string rather than the `Deferrable` enum, and a
leftover pre-rename option name.

Three no-op arguments went away because the compiler proved they could not do
anything: `AttributeToSqlOptions` and `EscapeOptions` share no properties, so
mssql and snowflake were handing `escape` an object it could never read, and
several `toSql({ dialect })` calls passed an argument no implementation accepts.

Co-Authored-By: Claude Opus 5 <[email protected]>
wikirik-agent added a commit to wikirik-agent/sequelize that referenced this pull request Sep 12, 2026
Moves both methods out of every dialect's `query-generator.js` and into its
`query-generator-typescript.internal.ts`, and renames them from `attributeToSQL`
/ `attributesToSQL` to `attributeToSql` / `attributesToSql`.

Closes the last item of sequelize#15533.

The core declaration is now a typed contract every dialect implements, rather
than a `ColumnsDescription` signature that described none of them. The new
`AttributeToSqlColumn` interface documents what the dialects actually read, and
is deliberately wider than `NormalizedAttributeOptions` because these methods
are also called with `describeTable` output, where the type is a raw SQL string.

`isBinaryStringType` joins `attributeTypeToDataTypeId` in the core data type
utilities, replacing the `attribute.type.options?.binary` reach-through.

No SQL changes. The pinned suites produce byte-identical output for all nine
dialects. Typing the tests did surface two things they were getting wrong:
a `deferrable` passed as a raw string rather than the `Deferrable` enum, and a
leftover pre-rename option name.

Three no-op arguments went away because the compiler proved they could not do
anything: `AttributeToSqlOptions` and `EscapeOptions` share no properties, so
mssql and snowflake were handing `escape` an object it could never read, and
several `toSql({ dialect })` calls passed an argument no implementation accepts.

Co-Authored-By: Claude Opus 5 <[email protected]>
wikirik-agent added a commit to wikirik-agent/sequelize that referenced this pull request Sep 12, 2026
Moves both methods out of every dialect's `query-generator.js` and into its
`query-generator-typescript.internal.ts`, and renames them from `attributeToSQL`
/ `attributesToSQL` to `attributeToSql` / `attributesToSql`.

Closes the last item of sequelize#15533.

The core declaration is now a typed contract every dialect implements, rather
than a `ColumnsDescription` signature that described none of them. The new
`AttributeToSqlColumn` interface documents what the dialects actually read, and
is deliberately wider than `NormalizedAttributeOptions` because these methods
are also called with `describeTable` output, where the type is a raw SQL string.

`isBinaryStringType` joins `attributeTypeToDataTypeId` in the core data type
utilities, replacing the `attribute.type.options?.binary` reach-through.

No SQL changes. The pinned suites produce byte-identical output for all nine
dialects. Typing the tests did surface two things they were getting wrong:
a `deferrable` passed as a raw string rather than the `Deferrable` enum, and a
leftover pre-rename option name.

Three no-op arguments went away because the compiler proved they could not do
anything: `AttributeToSqlOptions` and `EscapeOptions` share no properties, so
mssql and snowflake were handing `escape` an object it could never read, and
several `toSql({ dialect })` calls passed an argument no implementation accepts.

Co-Authored-By: Claude Opus 5 <[email protected]>
WikiRik pushed a commit that referenced this pull request Sep 18, 2026
Replaces the per-dialect `attributesToSQL` suites with two dialect-agnostic
suites that cover all nine dialects, including ibmi and mssql which had no
coverage at all.

The expectations pin current behaviour exactly, so this commit changes no SQL.
Behaviour that is wrong today is pinned as-is and marked with a TODO.

`sqlite3` gains an `attributeToSQL` method, extracted from `attributesToSQL`
without changing its output, so the shared suite can cover it like every other
dialect.

`inlineErrorCause` now inspects non-error values instead of stringifying them:
mssql and ibmi return null-prototype maps from `attributesToSQL`, which threw
when the assertion message was built.

Closes #15533

Co-Authored-By: Claude Opus 5 <[email protected]>
wikirik-agent added a commit that referenced this pull request Sep 18, 2026
…ToSql

Moves both methods out of every dialect's `query-generator.js` and into its
`query-generator-typescript.internal.ts`, and renames them from `attributeToSQL`
/ `attributesToSQL` to `attributeToSql` / `attributesToSql`.

Closes the last item of #15533.

The core declaration is now a typed contract every dialect implements, rather
than a `ColumnsDescription` signature that described none of them. The new
`AttributeToSqlColumn` interface documents what the dialects actually read, and
is deliberately wider than `NormalizedAttributeOptions` because these methods
are also called with `describeTable` output, where the type is a raw SQL string.

`isBinaryStringType` joins `attributeTypeToDataTypeId` in the core data type
utilities, replacing the `attribute.type.options?.binary` reach-through.

No SQL changes. The pinned suites produce byte-identical output for all nine
dialects. Typing the tests did surface two things they were getting wrong:
a `deferrable` passed as a raw string rather than the `Deferrable` enum, and a
leftover pre-rename option name.

Three no-op arguments went away because the compiler proved they could not do
anything: `AttributeToSqlOptions` and `EscapeOptions` share no properties, so
mssql and snowflake were handing `escape` an object it could never read, and
several `toSql({ dialect })` calls passed an argument no implementation accepts.

Co-Authored-By: Claude Opus 5 <[email protected]>
wikirik-agent added a commit that referenced this pull request Sep 19, 2026
…ToSql

Moves both methods out of every dialect's `query-generator.js` and into its
`query-generator-typescript.internal.ts`, and renames them from `attributeToSQL`
/ `attributesToSQL` to `attributeToSql` / `attributesToSql`.

Closes the last item of #15533.

The core declaration is now a typed contract every dialect implements, rather
than a `ColumnsDescription` signature that described none of them. The new
`AttributeToSqlColumn` interface documents what the dialects actually read, and
is deliberately wider than `NormalizedAttributeOptions` because these methods
are also called with `describeTable` output, where the type is a raw SQL string.
It declares `Model`, which mssql and oracle read to detect a column that
references its own table, and it deliberately has no index signature: one would
turn off excess property checking, which is what let the old option name
mismatches compile, and would also make `NormalizedAttributeOptions` unassignable
to it.

`isBinaryStringType` joins `attributeTypeToDataTypeId` in the core data type
utilities, replacing the `attribute.type.options?.binary` reach-through.

No SQL changes. The pinned suites produce byte-identical output for all nine
dialects. Typing the tests did surface two things they were getting wrong:
a `deferrable` passed as a raw string rather than the `Deferrable` enum, and a
leftover pre-rename option name.

Four no-op arguments went away because the compiler proved they could not do
anything: `AttributeToSqlOptions` and `EscapeOptions` share no properties, so
mssql and snowflake were handing `escape` an object it could never read, several
`toSql({ dialect })` calls passed an argument no implementation accepts, and db2
read a `replacements` option that no caller has ever passed.

Co-Authored-By: Claude Opus 5 <[email protected]>
WikiRik pushed a commit that referenced this pull request Sep 19, 2026
Replaces the per-dialect `attributesToSQL` suites with two dialect-agnostic
suites that cover all nine dialects, including ibmi and mssql which had no
coverage at all.

The expectations pin current behaviour exactly, so this commit changes no SQL.
Behaviour that is wrong today is pinned as-is and marked with a TODO.

`sqlite3` gains an `attributeToSQL` method, extracted from `attributesToSQL`
without changing its output, so the shared suite can cover it like every other
dialect.

`inlineErrorCause` now inspects non-error values instead of stringifying them:
mssql and ibmi return null-prototype maps from `attributesToSQL`, which threw
when the assertion message was built.

Closes #15533

Co-Authored-By: Claude Opus 5 <[email protected]>
WikiRik pushed a commit that referenced this pull request Sep 19, 2026
…ToSql

Moves both methods out of every dialect's `query-generator.js` and into its
`query-generator-typescript.internal.ts`, and renames them from `attributeToSQL`
/ `attributesToSQL` to `attributeToSql` / `attributesToSql`.

Closes the last item of #15533.

The core declaration is now a typed contract every dialect implements, rather
than a `ColumnsDescription` signature that described none of them. The new
`AttributeToSqlColumn` interface documents what the dialects actually read, and
is deliberately wider than `NormalizedAttributeOptions` because these methods
are also called with `describeTable` output, where the type is a raw SQL string.
It declares `Model`, which mssql and oracle read to detect a column that
references its own table, and it deliberately has no index signature: one would
turn off excess property checking, which is what let the old option name
mismatches compile, and would also make `NormalizedAttributeOptions` unassignable
to it.

`isBinaryStringType` joins `attributeTypeToDataTypeId` in the core data type
utilities, replacing the `attribute.type.options?.binary` reach-through.

No SQL changes. The pinned suites produce byte-identical output for all nine
dialects. Typing the tests did surface two things they were getting wrong:
a `deferrable` passed as a raw string rather than the `Deferrable` enum, and a
leftover pre-rename option name.

Four no-op arguments went away because the compiler proved they could not do
anything: `AttributeToSqlOptions` and `EscapeOptions` share no properties, so
mssql and snowflake were handing `escape` an object it could never read, several
`toSql({ dialect })` calls passed an argument no implementation accepts, and db2
read a `replacements` option that no caller has ever passed.

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants