sqlacodegen icon indicating copy to clipboard operation
sqlacodegen copied to clipboard

Allow for variable whitespace in “CHECK” enum constraints

Open Dsolnik opened this issue 1 year ago • 12 comments

allow for multiple spaces before the check keyword and any amount of white space (including 0) after the check keyword but before the in keyword:

For example, if your constraints was CHECK IN('a', 'b', 'c'), this would not be recognized.

Dsolnik avatar Sep 28 '23 22:09 Dsolnik

Coverage Status

coverage: 97.639%. remained the same when pulling c07f3a076b31906237af0a681096f0ad1aff5bc6 on Dsolnik:patch-1 into c68d2a8a0ec3511afb96983bdce6e2498aaa72b3 on agronholm:master.

coveralls avatar Sep 28 '23 22:09 coveralls

I don't think the changes you made do what you think they do.

agronholm avatar Sep 28 '23 22:09 agronholm

Basically all your changes do is allow any amount of whitespace before and after the IN.

agronholm avatar Sep 28 '23 22:09 agronholm

Tired Thursday apologies.

Yes, this PR allows for multiple spaces before the check keyword and any amount of white space (including 0) after the check keyword but before the in keyword.

Dsolnik avatar Sep 28 '23 23:09 Dsolnik

Just what kind of CHECK constraint did you have a problem with that wouldn't work with the existing code? I have a hard time understanding.

agronholm avatar Sep 28 '23 23:09 agronholm

My constraint was “CHECK IN('a', 'b', 'c')”, notice the lack of spaces after the IN

Dsolnik avatar Sep 28 '23 23:09 Dsolnik

I thought the RDBMS would normalize these. What RDBMS was this on?

agronholm avatar Sep 28 '23 23:09 agronholm

Admittedly, this was an oversight when I uploaded the schema but it was recognized as valid sql (and worked as a constraint) in SQLite and SQL Server.

On Thu, Sep 28, 2023 at 7:05 PM Alex Grönholm @.***> wrote:

Just what kind of CHECK constraint did you have a problem with that wouldn't work with the existing code? I have a hard time understanding.

— Reply to this email directly, view it on GitHub https://github.com/agronholm/sqlacodegen/pull/289#issuecomment-1740106817, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD64FZXYZTSDAKUSVINLJ5TX4X7DRANCNFSM6AAAAAA5LUC6DY . You are receiving this because you authored the thread.Message ID: @.***>

Dsolnik avatar Sep 28 '23 23:09 Dsolnik

Ah, that answers my question. I guess it's only PostgreSQL that normalizes those then.

agronholm avatar Sep 28 '23 23:09 agronholm

I will need an accompanying test to ensure that the PR fixes what it says it fixes (and won't break in the future). Meanwhile I'll experiment with sqlite (I don't know how to operate SQL Server).

agronholm avatar Sep 28 '23 23:09 agronholm

Yea, not only that but SQLite returns back the comment associated with the constraint (rip).

I didn’t check if this was the case for sql server.

On Thu, Sep 28, 2023 at 7:14 PM Alex Grönholm @.***> wrote:

Ah, that answers my question. I guess it's only PostgreSQL that normalizes those then.

— Reply to this email directly, view it on GitHub https://github.com/agronholm/sqlacodegen/pull/289#issuecomment-1740112707, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD64FZRLMFKW6LU5BDXQLZ3X4YAGFANCNFSM6AAAAAA5LUC6DY . You are receiving this because you authored the thread.Message ID: @.***>

Dsolnik avatar Sep 28 '23 23:09 Dsolnik

@Dsolnik would you also be able to add a fix for https://github.com/agronholm/sqlacodegen/issues/291? In this instance the spaces were are the start and end of the constraint eg " CAP_RESTRICT_LEVEL IN ('NONE', 'WARN', 'RESTRICT') ". I was in the process of creating a pr but looks like you are already making changes ;)

cameronclaero avatar Oct 03 '23 04:10 cameronclaero