define default value for array

Ttomspoint5/5/2023
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'] ?
Rrphlmr5/5/2023
I would try to surround the array with quotes (a string), because it is a text type in the end.
“['registered']”
Bbloberenober5/5/2023
What the problem is exactly? It should be able to accept the regular array values as defaults.
MMario5645/24/2023
bumping this thread, having the same issue
MMario5645/24/2023
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:
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
);
ASAndrii Sherman5/24/2023
On me
ASAndrii Sherman5/24/2023
Will fix it
ASAndrii Sherman5/24/2023
If I won’t till the end of this week please ping me here
MMario5645/24/2023
alright
MMario5646/1/2023
@Andrew Sherman forgot to ping earlier