DT
Join ServerDrizzle Team
help
define default value for array
I work with a PostgreSQL database.
Here is my Schema:
export const user = pgTable(
'auth_user',
{
id: uuid('id').primaryKey(),
email: text('email').notNull(),
roles: text('roles').array().default(['registered'])
},
(table) => {
return {
email: uniqueIndex('auth_user_email').on(table.email)
};
}
);
I have a problem with this line:
roles: text('roles').array().default(['registered'])
How do I define the default value to be ['registered'] ?
Here is my Schema:
export const user = pgTable(
'auth_user',
{
id: uuid('id').primaryKey(),
email: text('email').notNull(),
roles: text('roles').array().default(['registered'])
},
(table) => {
return {
email: uniqueIndex('auth_user_email').on(table.email)
};
}
);
I have a problem with this line:
roles: text('roles').array().default(['registered'])
How do I define the default value to be ['registered'] ?
I would try to surround the array with quotes (a string), because it is a text type in the end.
“['registered']”
What the problem is exactly? It should be able to accept the regular array values as defaults.
bumping this thread, having the same issue
here's a little bit more details regarding it:
so i have a table where i want to set the default value as an empty array but drizzle generates invalid sql syntax:
so i have a table where i want to set the default value as an empty array but drizzle generates invalid sql syntax:
export const dbPurchase = pgTable('purchases', {
// Other fields...
services: dbTournamentService('services').array(5).notNull().default([])
});
-- Drizzle generate output
CREATE TABLE IF NOT EXISTS "purchases" (
-- Other fields...
"services" tournament_service[5] DEFAULT NOT NULL
);
-- What I want
CREATE TABLE IF NOT EXISTS "purchases" (
-- Other fields...
"services" tournament_service[5] DEFAULT ARRAY[]::tournament_service[] NOT NULL
);
On me
Will fix it
If I won’t till the end of this week please ping me here
alright
@Andrew Sherman forgot to ping earlier