-
-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CreateTableQuery: use correct VARCHAR length #738
Conversation
The snapshot diff will show difference in case (got VARCHAR(255), want varchar(10)). That's not the bug and only done because CreateTableQuery.appendSQLType currently appends lowercase "varchar".
f8e4404
to
327f8de
Compare
…pe definition + use strings.EqualFold() for case-insensitive string comparison (SQL is case-insensitive) + Dialect interface now requires `DefaultVarcharLen()` + CreateTableQuery uses the length set in .Varchar() also for `bun:",type:varchar"`
+ Return early to improve readability
327f8de
to
6003beb
Compare
@bevzzz looks good, thanks. Could you clarify what happens when a dialect returns
Let's not break the existing API. Instead, let's return an error like you suggested or just Also, |
We initialize Yes, there's a test case for that: func(db *bun.DB) schema.QueryAppender {
return db.NewCreateTable().Model(new(Model))
} It's one of the older ones (no regressions ✌️ ), and for PG, which has default 0, it generates this query:
Agreed. Good point about |
a287d98
to
3335e0b
Compare
Thanks 👍 |
This PR fixes the handling of VARCHAR length in
CREATE TABLE
, see #736.Changes:
Dialect
implementations now need to haveDefaultVarcharLen() uint
, so that we wouldn't need to hardcode the default lengths in the dialect-specific typesCreateAlterTable.appendSQLType
SinceVARCHAR
can only have positive length, the signature ofCreateAlterTable.Varchar
is changed toVarchar(n uint)
.This commit , therefore, has a BREAKING CHANGE ❗, as this would no longer compile:
Edit: breaking changes were reverted, see this commit instead.
This change is not necessary for the fix, I only propose this for the sake of additional "type safety" in the queries. It feels more transparent than something like
n = max(0, n)
. However, if such API change is not acceptable, we could also return an error forq.varchar <= 0
or just revert this commit entirely.