Update column ONLY enabled when column is set as NOT NULL #3666
Replies: 2 comments
-
Plus to that, when we use a // log schema
...
historyDate: timestamp('history_date', { mode: 'string' })
// .default(sql`CURRENT_TIMESTAMP`) <-- HERE, this exists in db but I can't set the exact schema here
// so it's not reflecting my db in the schema at all
.notNull(), I understand that when we have this default value it always will add the current_timestamp or whatever we put inside the default method. But when we pass something, it should be able to use what I used to pass to that field/column. In this case, I inject the exact timestamp from another table that are acting in transaction. After that it works as intended, but it seems to not reflect my db constraints at all... Because when I instrospect it reflect the schema with the correct constraints, now I have to overwrite, remove or something else to be able to work as expected inside my codebase. |
Beta Was this translation helpful? Give feedback.
-
Another problem is the GENERATE command, in created sql file as I said before not reflect my db because the CONSTRAINT should exist only in backend/codebase for practical purposes(access field inside query), but in db that CONSTRAINT should not exist! CREATE TABLE IF NOT EXISTS "users" (
...
# wrong
"last_login_at" timestamp NOT NULL,
# correct
"last_login_at" timestamp
...
); |
Beta Was this translation helpful? Give feedback.
-
This behavior is expected?
Because, I'm only enable to set some field like
lastLoginAt
when.notNull()
is setted in schema, but in my case the column should be able to:NULL
: when we insert NEW users.NOT NULL
: when we update EXISTENT(obviously) users.Is there some strategy to that, something that I missed?
The code below works because of
.notNull
onlastLoginAt
When we remove
.notNull
, now I'm not able to update the respective column aboveNow I'm just able to change username or password, proof by intellisense:
Version:
Beta Was this translation helpful? Give feedback.
All reactions