Drizzle create an pg enum with an object as const, should return an error ?

According to the docs I usually create an enum with values like this:
export const COMMON_AREA_TYPE_VALUES = [
'public',
'private',
] as const;


export const commonAreaTypesEnum2 = pgEnum(
'common_area_types',
COMMON_AREA_TYPE_VALUES,
);
export const COMMON_AREA_TYPE_VALUES = [
'public',
'private',
] as const;


export const commonAreaTypesEnum2 = pgEnum(
'common_area_types',
COMMON_AREA_TYPE_VALUES,
);
But I was making some tests and migrations and when I pass this the entire object I didn't get an error, so I want to know if it's something related to the types and once I run the migration it's going to explote or not. The code is the following:
export const COMMON_AREA_TYPES = {
PUBLIC: 'public',
PRIVATE: 'private',
} as const;

export const COMMON_AREA_TYPE_VALUES = [
COMMON_AREA_TYPES.PUBLIC,
COMMON_AREA_TYPES.PRIVATE,
] as const;


export const commonAreaTypesEnum1 = pgEnum(
'common_area_types',
COMMON_AREA_TYPES,
);
export const COMMON_AREA_TYPES = {
PUBLIC: 'public',
PRIVATE: 'private',
} as const;

export const COMMON_AREA_TYPE_VALUES = [
COMMON_AREA_TYPES.PUBLIC,
COMMON_AREA_TYPES.PRIVATE,
] as const;


export const commonAreaTypesEnum1 = pgEnum(
'common_area_types',
COMMON_AREA_TYPES,
);
The details of my migraiton it was to use an object as const instead of an enum.
No description
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?