Best practise for null-safety with database model classes

I’m curious on opinions on this. I create a table using SQL and specify NOT NULL columns. Should my model reflect this (not null variables) or should my variables be nullable?

The reason I was thinking they should be nullable is that the database is external, so I can’t know for sure that the column doesn’t contain a null value. Also if somebody changed the sql column it might not match the Kotlin code.

However, if the column is NOT NULL then surely I’m safe to assume it shouldn’t bring back nulls.

Model @Table("USER_MODEL") data class UserModel( @Id var id: UUID? = null, val email: String? // Or should it be of type String? )

Table CREATE TABLE user_model ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, email TEXT NOT NULL)

Should fields such as email be nullable, or is it safe to assume it won’t be null?

submitted by /u/michael2109
[link] [comments]