Skip to content
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

Incorrect ColumnType Nullable default #158

Open
ChrisPortman opened this issue Jul 5, 2023 · 1 comment
Open

Incorrect ColumnType Nullable default #158

ChrisPortman opened this issue Jul 5, 2023 · 1 comment
Assignees

Comments

@ChrisPortman
Copy link
Contributor

ChrisPortman commented Jul 5, 2023

Description

Sqlite coumns that are neither NOT NULL or NULL are nullable by default. However, .Nullable() defaults to false and is only set true if the CREATE TABLE sql explicitly denotes the column as NULL

columnType := migrator.ColumnType{

columnType := migrator.ColumnType{
    <snip>
    NullableValue:     sql.NullBool{Valid: true},    //<--- .Bool implicitly false, i.e. NOT NULL 
    <snip>
}

matchUpper := strings.ToUpper(matches[3])
if strings.Contains(matchUpper, " NOT NULL") {
	columnType.NullableValue = sql.NullBool{Bool: false, Valid: true}
} else if strings.Contains(matchUpper, " NULL") {
	columnType.NullableValue = sql.NullBool{Bool: true, Valid: true}
}
...
@ChrisPortman
Copy link
Contributor Author

I think this is also raised by #107

ChrisPortman pushed a commit to ChrisPortman/sqlite that referenced this issue Jul 5, 2023
This change sets the default value of ColumnType.Nullable() to true.  If
the column is explicitly `MOT NULL` then it will be set false.

This is consistent with the SQLite documentation:
https://www.sqlitetutorial.net/sqlite-not-null-constraint/
jinzhu pushed a commit that referenced this issue Oct 8, 2023
This change sets the default value of ColumnType.Nullable() to true.  If
the column is explicitly `MOT NULL` then it will be set false.

This is consistent with the SQLite documentation:
https://www.sqlitetutorial.net/sqlite-not-null-constraint/

Co-authored-by: Chris Carter <chris.carter@spinlocksecurity.com>
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

No branches or pull requests

2 participants