Overwriting Schema Defaults

await database.insert(users).values([
{
name: ADMIN_NAME!,
slug: ADMIN_SLUG!,
email: ADMIN_EMAIL!,
password: ADMIN_PASSWORD!,
role: 'ADMIN',
active: true
}
])
await database.insert(users).values([
{
name: ADMIN_NAME!,
slug: ADMIN_SLUG!,
email: ADMIN_EMAIL!,
password: ADMIN_PASSWORD!,
role: 'ADMIN',
active: true
}
])
the values function is marked with an error, because I set role and active, which already have a value due to their default value in the schema. What can I do about that?
export const users = pgTable('users', {
id: uuid('id').primaryKey().defaultRandom(),
name: varchar('name', { length: 256 }).notNull(),
slug: varchar('slug', { length: 256 }).notNull().unique(),
biography: text('biography'),
email: varchar('email', { length: 256 }).notNull(),
password: varchar('password', { length: 256 }).notNull(),
role: role('role').notNull().default('STANDARD'),
active: boolean('active').notNull().default(false),
createdAt: timestamp('created_at').notNull().defaultNow(),
updatedAt: timestamp('updated_at').notNull().defaultNow()
})
export const users = pgTable('users', {
id: uuid('id').primaryKey().defaultRandom(),
name: varchar('name', { length: 256 }).notNull(),
slug: varchar('slug', { length: 256 }).notNull().unique(),
biography: text('biography'),
email: varchar('email', { length: 256 }).notNull(),
password: varchar('password', { length: 256 }).notNull(),
role: role('role').notNull().default('STANDARD'),
active: boolean('active').notNull().default(false),
createdAt: timestamp('created_at').notNull().defaultNow(),
updatedAt: timestamp('updated_at').notNull().defaultNow()
})
Thank you. Timo
2 Replies
tzezar
tzezar6mo ago
are you sure error comes from setting values that have defauls? can you show ts error?
rphlmr ⚡
rphlmr ⚡6mo ago
Not sure what is role here? A custom type?
Want results from more Discord servers?
Add your server