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'] ?
6 Replies
rphlmr ⚡
rphlmr ⚡2y ago
I would try to surround the array with quotes (a string), because it is a text type in the end. “['registered']”
Dan
Dan2y ago
What the problem is exactly? It should be able to accept the regular array values as defaults.
Mario564
Mario5642y ago
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:
export const dbPurchase = pgTable('purchases', {
// Other fields...
services: dbTournamentService('services').array(5).notNull().default([])
});
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
);
-- 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
);
Andrii Sherman
On me Will fix it If I won’t till the end of this week please ping me here
Mario564
Mario5642y ago
alright @Andrew Sherman forgot to ping earlier
nanberg
nanberg12mo ago
was this ever fixed? I'm currently seeing the same issue on the latest release @Andrew Sherman
Want results from more Discord servers?
Add your server