better-auth-kit icon indicating copy to clipboard operation
better-auth-kit copied to clipboard

Bug: TypeError when seeding `jobs` table โ€” `modelName` is undefined

Open Pial-Al-Mamun opened this issue 1 year ago โ€ข 0 comments

ERROR Error seeding "jobs" in model jobs: TypeError: Cannot read properties of undefined (reading 'modelName')


โœ… What works

  • The users model seeds successfully.

๐Ÿงช What I tried

  • Verified the jobs table exists in the DB โœ…
  • Checked Drizzle schema for jobs โ€” no issues found โœ…
  • Confirmed that field names in schema and seeding logic match โœ…
  • Also setting at the end of the table the config with js table(foo, {tableName: "jobs"} that didn't work also.
  • Inspected the seeding module โ€” looks like jobs is not registered internally โŒ (there were only table account session user and i think another one that I do not specifically remember and wasn't relevant)

๐Ÿงฉ Possible Cause

It seems the jobs table is not being included in the internal list of tables the module uses. This leads to the seeding library being unable to find modelName when processing the jobs seed.


๐Ÿงพ Schema (jobsTable) using drizzle

export const jobsTable = pgTable("jobs", {
  id: uuid().defaultRandom(),
  userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade", onUpdate: "restrict" }),
  title: text("title").notNull(),
  description: text("description").notNull(),
  client: varchar("client", { length: 100 }).notNull(),
  clientRating: numeric("client_rating").notNull(),
  budget_min: integer("budget_min").notNull(),
  budget_max: integer("budget_max").notNull(),
  timeframe: varchar("timeframe", { length: 50 }).notNull(),
  language: programLang("language").notNull(),
  framework: varchar("framework", { length: 50 }).notNull(),
  difficulty: difficultyEnum("difficulty").notNull(),
  posted: timestamp("posted", { mode: "date" }).defaultNow(),
  applicants: integer("applicants").notNull(),
  skills: text("skills").array().notNull(),
  repository: text("repository").notNull(),
  branch: varchar("branch", { length: 100 }).notNull(),
  urgent: boolean("urgent").notNull(),
  verified: boolean("verified").notNull(),
  requirements: text("requirements").array().notNull(),
  technicalDetails: jsonb("technical_details").notNull(),
});

the seed table logic

export const seed = Seed({
  ...users<{ user: User; session: Session; account: Account }>(
    {
      user: { /* ... */ },
      account: { /* ... */ },
      session: { /* ... */ },
    },
  ),

  jobs: table(
    {
      user_id: $.foreignKey({ field: "id", model: "user" }),
      title: $.jobTitles(),
      description: $.loremIpsum(),
      client: $.first_and_lastname(),
      client_rating: $.randomNumber({ min: 0, max: 50 }),
      budget_min: $.randomNumber({ min: 500, max: 2000 }),
      budget_max: $.randomNumber({ min: 2000, max: 10000 }),
      timeframe: $.randomChoice(
        $.custom(() => "1 week"),
        $.custom(() => "1 month"),
        $.custom(() => "3 months"),
        $.custom(() => "6+ months")
      ),
      language: $.randomChoice(
        $.custom(() => "javascript"),
        $.custom(() => "typescript"),
        $.custom(() => "python"),
        $.custom(() => "java"),
        $.custom(() => "csharp"),
        $.custom(() => "php"),
        $.custom(() => "ruby"),
        $.custom(() => "go"),
        $.custom(() => "rust"),
        $.custom(() => "swift"),
        $.custom(() => "kotlin")
      ),
      framework: $.randomChoice(
        $.custom(() => "react"),
        $.custom(() => "vue"),
        $.custom(() => "angular"),
        $.custom(() => "svelte"),
        $.custom(() => "ember"),
        $.custom(() => "next.js"),
        $.custom(() => "gatsby"),
        $.custom(() => "wordpress"),
        $.custom(() => "laravel"),
        $.custom(() => "django"),
        $.custom(() => "nodejs"),
        $.custom(() => "python"),
        $.custom(() => "java"),
        $.custom(() => "csharp"),
        $.custom(() => "php"),
        $.custom(() => "ruby"),
        $.custom(() => "go"),
        $.custom(() => "rust"),
        $.custom(() => "swift"),
        $.custom(() => "kotlin")
      ),
      difficulty: $.randomChoice(
        $.custom(() => "easy"),
        $.custom(() => "medium"),
        $.custom(() => "hard")
      ),
      posted: $.randomDate("any"),
      applicants: $.randomNumber({ min: 0, max: 50 }),
      skills: $.custom(() => ["react", "typescript", "drizzle", "bun"]),
      repository: $.custom(() => "https://github.com/example/repo"),
      branch: $.custom(() => "main"),
      urgent: $.randomBoolean(),
      verified: $.randomBoolean(),
      requirements: $.custom(() => ["unit tests", "CI setup", "responsive UI"]),
      technical_details: $.custom(() => ({
        db: "PostgreSQL",
        orm: "Drizzle",
        infra: "Vercel",
      })),
    },
  ),
});

Pial-Al-Mamun avatar Jul 25 '25 15:07 Pial-Al-Mamun