Repository navigation
Conversation
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (11)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughChangesDefault generation
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Sep 18, 2026
WikiRik
marked this pull request as ready for review
September 19, 2026 06:37
WikiRik
approved these changes
Sep 19, 2026
Every dialect that refuses a DEFAULT for certain column types was checking conditions that can never be true on v7 data types: - `attribute.type._binary` was a v6 property of STRING/CHAR set by `.BINARY`. It does not exist in v7, so the check was always a no-op. It is now `attribute.type.options?.binary`, which is where that flag lives today. - db2, mssql and oracle compared `attribute.type !== 'TEXT'`, comparing a DataType instance against a string, so it never matched. - mariadb, mysql, snowflake and ibmi looked up the rendered SQL string in a set of type names. That only matched the default length variant, and never matched at all on ibmi, whose BLOB renders as `BLOB(1M)`. The lookups now use `attributeTypeToDataTypeId`, added to the core data type utilities, which returns the dialect-independent identity of a type. Each dialect keeps exactly the list of types it already named. As a result db2, mssql and oracle stop emitting a DEFAULT for BLOB and TEXT columns, and ibmi stops emitting one for BLOB. A raw `'BLOB'` string type with a default no longer throws while trying to escape the value. Co-Authored-By: Claude Opus 5 <[email protected]>
Follow-up to the previous commit, which restored guards that turned out to be
describing restrictions that do not exist. Verified against db2 12.1.4, SQL
Server 2025, Oracle 23.26, MySQL 8.4 and MariaDB 11.6:
- db2, mssql and oracle accept a DEFAULT on their LOB types. `CLOB DEFAULT
'abc'`, `NVARCHAR(MAX) DEFAULT N'abc'` and `BLOB DEFAULT BLOB('abc')` all
work. The SQL Server folklore appears to come from CREATE TABLE's rule that
CHECK constraints cannot be defined on text/ntext/image, which is a different
clause. Those three lists are removed.
- `.BINARY` on a string type is a collation, not a storage class, and every
server tested accepts a default on such a column. That guard is removed
everywhere rather than repaired.
mariadb, mysql, snowflake and ibmi keep the lists they already had, now matched
by data type identity rather than by rendered SQL string.
Without this, a `defaultValue` the user asked for would silently vanish.
Co-Authored-By: Claude Opus 5 <[email protected]>
… columns Both dialects emitted no DEFAULT at all for these four types. MySQL accepts one as long as it is written as an expression, i.e. wrapped in parentheses, since 8.0.13 — and the minimum supported version is 8.0.20. The drop is now a parenthesisation, so the value reaches the server instead of silently vanishing. Verified on MySQL 8.4. MariaDB has accepted defaults on them since 10.2.1 and the minimum supported version is 10.4.30, so the list is removed outright. mariadb also emitted expression defaults unparenthesised, which MariaDB rejects for anything that is not a bare function call, so those are now parenthesised as they already were on mysql. Verified on MariaDB 11.6. Co-Authored-By: Claude Opus 5 <[email protected]>
Both are verbatim copies of mysql's, made in the commits that introduced each dialect, and neither has ever fired: they matched on the rendered SQL string, which is `BLOB(1M)` on ibmi and never the bare `BLOB` the set contained. ibmi's list is removed. Db2 for i documents a closed list of types that cannot take a DEFAULT — ROWID, identity, row change timestamp, row-begin, row-end, transaction-start-ID and generated expression columns — and LOBs are not in it. It goes further and names BLOB and CLOB among the types that may use the cast-function default form, which is exactly what `escapeBuffer` already produces. The data type is now passed to `escape`, without which a Buffer default throws, and that in turn makes the manual true/false to 1/0 coercion unnecessary: the BOOLEAN type serializes itself once it is known. snowflake keeps only BLOB, and for a different reason than the old comment gave. TEXT is a documented synonym of VARCHAR and Snowflake's DEFAULT grammar has no type predicate, so dropping a default there was plain data loss. JSON is not a Snowflake type name at all. BLOB stays because Snowflake has no BLOB type either — its binary types are BINARY and VARBINARY, and binary literals are written TO_BINARY(..., 'HEX') rather than X'...' — so that column cannot be created regardless of its default. That needs its own fix, noted with a TODO. Both conclusions are documentation-based. Neither dialect can be tested here. Co-Authored-By: Claude Opus 5 <[email protected]>
`escape` guesses the data type from the value when it is not told one. An array default on a JSON column is guessed as ARRAY, which none of these three dialects support, so generating the column threw. This was latent until the default started being emitted at all: mariadb and mysql used to drop defaults on JSON columns, so `escape` was never reached. oracle was not failing but had the same hole, and every other dialect already passed the type. Caught by the DataTypes.JSON integration test on mariadb and mysql. Co-Authored-By: Claude Opus 5 <[email protected]>
WikiRik
force-pushed
the
wikirik-agent/attributes-to-sql-defaults
branch
from
September 19, 2026 07:49
fbd4998 to
fe5fff4
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Changes
Second of the stack re-implementing #17121, stacked on #18399.
#18399 pinned current behaviour exactly. This is the first of three PRs that change it. Every expectation that moves in
attribute-to-sql.test.tsis a behaviour delta, so the test diff is the review surface.Seven of the nine dialects carried a list of types that "cannot have a default", or an equivalent inline guard. None of them worked. Once they were made to work it turned out most were describing a restriction the server does not have, so the net effect of this PR is that a
defaultValuethe user asked for is no longer silently discarded.fix: make the "this type cannot have a default" guards work againEvery such guard was checking a condition that can never be true on v7 data types:
attribute.type._binarywas a v6 property ofSTRING/CHARset by.BINARY. It does not exist in v7 — I checked the v6 source in git history to confirm what it meant. It is nowattribute.type.options?.binary.attribute.type !== 'TEXT', i.e. aDataTypeinstance against a string.DataTypes.TEXT('tiny')→TINYTEXTmissed, and ibmi never matched at all since its BLOB renders asBLOB(1M).Lookups now use a new
attributeTypeToDataTypeIdcore utility built on the existinggetDataTypeId(), which returns a type's dialect-independent identity. Each dialect keeps exactly the list of types it already named — this commit does not re-decide which types reject defaults. The next four do.fix: stop dropping defaults on LOB and binary string columnsVerified against Db2 LUW 12.1.4, SQL Server 2025, Oracle 23.26 Free, MySQL 8.4 and MariaDB 11.6:
DEFAULTon their LOB types.CLOB DEFAULT 'abc',NVARCHAR(MAX) DEFAULT N'abc'andBLOB DEFAULT BLOB('abc')all work, and the value round-trips. The SQL Server folklore appears to come fromCREATE TABLE's rule that CHECK constraints cannot be defined ontext/ntext/image— a different clause. Those three lists are removed..BINARYon a string type is a collation, not a storage class, and every server tested accepts a default on such a column. That guard is removed everywhere rather than repaired.fix(mariadb,mysql): keep the DEFAULT on BLOB, TEXT, GEOMETRY and JSON columnsMySQL accepts a default on those types as long as it is written as an expression, i.e. wrapped in parentheses, since 8.0.13. The minimum supported version is 8.0.20, so every supported server can take one. The drop becomes a parenthesisation:
Worth noting the guard sat before the existing
BaseSqlExpressionparenthesisation, so the MySQL 8.0.13 expression-default support already in the codebase was unreachable for exactly the types that needed it.MariaDB has accepted defaults on BLOB/TEXT since 10.2.1 (MDEV-10134) and the minimum supported version is 10.4.30, so its list is removed outright. mariadb also emitted expression defaults unparenthesised, which MariaDB rejects for anything that is not a bare function call —
DEFAULT 1+1fails,DEFAULT (1+1)works. Those are now parenthesised as they already were on mysql, which is why threecreate-tableexpectations change.Verified end to end on MySQL 8.4 and MariaDB 11.6: the columns are created and the values round-trip.
fix(ibmi,snowflake): remove the last two typeWithoutDefault listsBoth are verbatim copies of mysql's, made in the commits that introduced each dialect, and neither has ever fired.
ibmi's list is removed. Db2 for i documents a closed list of types that cannot take a
DEFAULT— ROWID, identity, row change timestamp, row-begin, row-end, transaction-start-ID and generated expression columns — and LOBs are not in it. It goes further and names BLOB and CLOB among the types that may use the cast-function default form, which is exactly whatescapeBufferalready produces. The data type is now passed toescape, without which aBufferdefault throws, and that in turn makes the manualtrue/false→1/0coercion unnecessary: the BOOLEAN type serialises itself once it is known.snowflake keeps only BLOB, for a different reason than the old comment gave. TEXT is a documented synonym of VARCHAR and Snowflake's
DEFAULTgrammar has no type predicate, so dropping a default there was plain data loss. JSON is not a Snowflake type name at all. BLOB stays because Snowflake has no BLOB type either — its binary types are BINARY and VARBINARY, and binary literals are writtenTO_BINARY(..., 'HEX')rather thanX'...'— so that column cannot be created regardless of its default. That needs its own fix, noted with a TODO.Both of these conclusions are documentation-based. There is no Snowflake account and no Db2 for i server available here.
fix(mariadb,mysql,oracle): tell escape what type the default belongs toescapeguesses the data type from the value when it is not told one. An array default on a JSON column is guessed asARRAY, which none of these three support, so generating the column threw. This was latent until the default started being emitted at all — mariadb and mysql used to drop defaults on JSON columns, soescapewas never reached. Caught by theDataTypes.JSONintegration test on mariadb and mysql.Verification
All nine dialect unit suites pass at every commit in this PR, with clean
eslint, cleanprettier, and cleantscon both--noEmitandtest/tsconfig.json. Integration suites for the stack as a whole run against real servers: mssql 411 passing, oracle 388 passing (needsTZ=UTC), db2 19 passing on the query-interface suite. ibmi and snowflake remain unverified — neither can be run locally.List of Breaking Changes
Seven dialects now emit a
DEFAULTclause for column types where they previously emitted none. A model that declared adefaultValueon aTEXT/BLOB/JSON/GEOMETRYcolumn silently got no default before and will now get the one it asked for.🤖 Generated with Claude Code
Summary by CodeRabbit