trouble creating Enum

Hi everyone, here's my code:
import { paymentPlansNames } from 'misc/payment-plans';
import { pgTable, pgEnum, json, varchar } from 'drizzle-orm/pg-core';
import { bigint, bigserial } from 'drizzle-orm/pg-core';
import { relations } from 'drizzle-orm';

console.log(paymentPlansNames); // [ "Subscription Starter", "Subscription Pro" ]

const subscriptionPlanEnum = pgEnum('subscription_name', paymentPlansNames);
const frequencyEnum = pgEnum('frequency', ['monthly', 'yearly']);

export const Subscriptions = pgTable('subscriptions', {
id: bigserial('id', { mode: 'number' }).primaryKey(),
companyId: bigint('company_id', { mode: 'number' }),
customerId: bigint('customer_id', { mode: 'number' }),
subscriptionId: varchar('subscription_id', { length: 256 }),
subscriptionName: subscriptionPlanEnum('subscription_name'),
frequency: frequencyEnum('frequency'),
// trialStart: bigint('trial_start', { mode: 'number' }),
// trialEnd: bigint('trial_end', { mode: 'number' }),
currentPeriodStart: bigint('current_period_start', { mode: 'number' }),
currentPeriodEnd: bigint('current_period_end', { mode: 'number' }),
canceledAt: bigint('canceled_at', { mode: 'number' }),
// canceledAtPeriodEnd: bigint('canceled_at_period_end', { mode: 'number' }),
// createdAt: bigint('created_at', { mode: 'number' }),
// updatedAt: bigint('updated_at', { mode: 'number' }),
});
import { paymentPlansNames } from 'misc/payment-plans';
import { pgTable, pgEnum, json, varchar } from 'drizzle-orm/pg-core';
import { bigint, bigserial } from 'drizzle-orm/pg-core';
import { relations } from 'drizzle-orm';

console.log(paymentPlansNames); // [ "Subscription Starter", "Subscription Pro" ]

const subscriptionPlanEnum = pgEnum('subscription_name', paymentPlansNames);
const frequencyEnum = pgEnum('frequency', ['monthly', 'yearly']);

export const Subscriptions = pgTable('subscriptions', {
id: bigserial('id', { mode: 'number' }).primaryKey(),
companyId: bigint('company_id', { mode: 'number' }),
customerId: bigint('customer_id', { mode: 'number' }),
subscriptionId: varchar('subscription_id', { length: 256 }),
subscriptionName: subscriptionPlanEnum('subscription_name'),
frequency: frequencyEnum('frequency'),
// trialStart: bigint('trial_start', { mode: 'number' }),
// trialEnd: bigint('trial_end', { mode: 'number' }),
currentPeriodStart: bigint('current_period_start', { mode: 'number' }),
currentPeriodEnd: bigint('current_period_end', { mode: 'number' }),
canceledAt: bigint('canceled_at', { mode: 'number' }),
// canceledAtPeriodEnd: bigint('canceled_at_period_end', { mode: 'number' }),
// createdAt: bigint('created_at', { mode: 'number' }),
// updatedAt: bigint('updated_at', { mode: 'number' }),
});
I'm getting the errors: error: type "frequency" does not exist error: type "subscription_name" does not exist I'm doing exactly the same thing on other tables, not sure what i'm doing wrong here... Thanks for any help
Solution:
export const subscriptionPlanEnum = pgEnum('subscription_name', paymentPlansNames);
export const frequencyEnum = pgEnum('frequency', ['monthly', 'yearly']);
export const subscriptionPlanEnum = pgEnum('subscription_name', paymentPlansNames);
export const frequencyEnum = pgEnum('frequency', ['monthly', 'yearly']);
...
Jump to solution
5 Replies
Mario564
Mario5645mo ago
Hi there. I got a few questions: - I assume these errors appear upon running the migration command, is this correct? - If the answer to the prior is yes, what does that migration look like? (SQL code)
rubberduckies
rubberduckiesOP5mo ago
Thank you for the quick reply, i figured it out though I forgot to export the enums
Solution
rubberduckies
rubberduckies5mo ago
export const subscriptionPlanEnum = pgEnum('subscription_name', paymentPlansNames);
export const frequencyEnum = pgEnum('frequency', ['monthly', 'yearly']);
export const subscriptionPlanEnum = pgEnum('subscription_name', paymentPlansNames);
export const frequencyEnum = pgEnum('frequency', ['monthly', 'yearly']);
rubberduckies
rubberduckiesOP5mo ago
it appeared on migration yes
Mario564
Mario5645mo ago
Oh yeah, didn't notice that lol. Glad you got it solved though
Want results from more Discord servers?
Add your server