Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: drizzle-seed not respecting the count value for all tables #4050

Open
1 task done
nmarch213 opened this issue Jan 31, 2025 · 0 comments
Open
1 task done

[BUG]: drizzle-seed not respecting the count value for all tables #4050

nmarch213 opened this issue Jan 31, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@nmarch213
Copy link

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

drizzle-orm: ^0.38.4

What version of drizzle-kit are you using?

drizzle-kit: ^0.30.2

Other packages

drizzle-seed: ^0.3.1

Describe the Bug

Bug: Count values not respected in drizzle-seed

Description

When using drizzle-seed, the count parameter is being ignored for most tables, defaulting to 10 records regardless of specified count. Only the waitlist table respects the count parameter.

Reproduction

// seed.ts
import "dotenv/config";
import { seed, reset } from "drizzle-seed";
import { db } from "..";
import * as schema from "./schema";

async function main() {
  await reset(db, schema);

  await seed(db, schema).refine((f) => ({
    organizations: {
      count: 5,
      columns: {
        name: f.companyName(),
        slug: f.default({
          defaultValue: (values: any) =>
            values.name.toLowerCase().replace(/[^a-z0-9]+/g, "-"),
        }),
        sport: f.default({ defaultValue: "BASKETBALL" }),
        type: f.valuesFromArray({
          values: [
            { weight: 0.5, values: ["ASSOCIATION"] },
            { weight: 0.3, values: ["CONFERENCE"] },
            { weight: 0.2, values: ["LEAGUE"] },
          ],
        }),
        status: f.valuesFromArray({
          values: [
            { weight: 0.9, values: ["ACTIVE"] },
            { weight: 0.1, values: ["INACTIVE"] },
          ],
        }),
      },
      with: {
        organizationOfficials: [
          { weight: 0.2, count: [50, 75] },
          { weight: 0.5, count: [76, 150] },
          { weight: 0.3, count: [151, 300] },
        ],
      },
    },

    officials: {
      count: 500,
      columns: {
        certificationLevel: f.valuesFromArray({
          values: [
            { weight: 0.4, values: ["1"] },
            { weight: 0.3, values: ["2"] },
            { weight: 0.15, values: ["3"] },
            { weight: 0.1, values: ["4"] },
            { weight: 0.05, values: ["5"] },
          ],
        }),
        yearsOfExperience: f.int({ minValue: 0, maxValue: 30 }),
        status: f.valuesFromArray({
          values: [
            { weight: 0.9, values: ["ACTIVE"] },
            { weight: 0.1, values: ["INACTIVE"] },
          ],
        }),
      },
    },

    games: {
      count: 1000,
      columns: {
        date: f.date({ minDate: "2024-01-01", maxDate: "2024-12-31" }),
        location: f.valuesFromArray({
          values: [
            "Main Gymnasium",
            "Auxiliary Gymnasium",
            "Recreation Center",
            "Field House",
            "Arena",
            "Community Center",
            "Sports Complex",
            "High School Gym",
            "University Arena",
            "Civic Center",
            "Athletic Complex",
            "Memorial Stadium",
            "Youth Center",
            "Regional Sports Facility",
          ],
        }),
        status: f.valuesFromArray({
          values: [
            { weight: 0.5, values: ["SCHEDULED"] },
            { weight: 0.1, values: ["IN_PROGRESS"] },
            { weight: 0.4, values: ["COMPLETED"] },
          ],
        }),
      },
      with: {
        gameOfficials: [2, 3],
        evaluations: [
          { weight: 0.5, count: [0] },
          { weight: 0.3, count: [1] },
          { weight: 0.15, count: [2] },
          { weight: 0.05, count: [3, 4] },
        ],
      },
    },

    gameOfficials: {
      columns: {
        role: f.valuesFromArray({
          values: [
            { weight: 0.34, values: ["CREW_CHIEF"] },
            { weight: 0.33, values: ["REFEREE"] },
            { weight: 0.33, values: ["UMPIRE"] },
          ],
        }),
      },
    },

    organizationOfficials: {
      columns: {
        role: f.valuesFromArray({
          values: [
            { weight: 0.8, values: ["MEMBER"] },
            { weight: 0.15, values: ["ADMIN"] },
            { weight: 0.05, values: ["ASSIGNOR"] },
          ],
        }),
      },
    },

    evaluations: {
      columns: {
        rating: f.valuesFromArray({
          values: [
            { weight: 0.1, values: [5] },
            { weight: 0.3, values: [4] },
            { weight: 0.4, values: [3] },
            { weight: 0.15, values: [2] },
            { weight: 0.05, values: [1] },
          ],
        }),
        notes: f.default({
          defaultValue: () => {
            const templates = [
              "Game management was {quality}. {specific} Mechanics were {mechanic_quality}.",
              "Showed {quality} court presence. {specific} Communication with partners was {communication}.",
              "Foul judgment was {quality}. {specific} Game flow management was {flow}.",
              "Position adjustments were {quality}. {specific} Rules knowledge demonstrated was {rules}.",
              "Game control was {quality}. {specific} Partner collaboration was {collaboration}.",
            ];

            const qualities = [
              "excellent",
              "very good",
              "good",
              "adequate",
              "inconsistent",
              "poor",
            ];
            const specifics = [
              "Made strong calls in crucial moments.",
              "Maintained good positioning throughout.",
              "Could improve consistency on block/charge calls.",
              "Handled coach interactions professionally.",
              "Needs work on rotation mechanics.",
              "Demonstrated excellent rules knowledge.",
              "Showed good judgment on tough plays.",
              "Communication with partners needs improvement.",
              "Managed bench areas effectively.",
              "Game flow control was notable.",
            ];
            const mechanics = [
              "precise",
              "very good",
              "mostly accurate",
              "inconsistent",
              "needs improvement",
            ];
            const communications = [
              "excellent",
              "effective",
              "adequate",
              "inconsistent",
              "needs improvement",
            ];
            const flows = [
              "excellent",
              "smooth",
              "generally good",
              "choppy",
              "needs work",
            ];
            const rules = [
              "excellent",
              "solid",
              "adequate",
              "inconsistent",
              "needs review",
            ];
            const collaboration = [
              "excellent",
              "effective",
              "adequate",
              "needs improvement",
              "poor",
            ];

            const template =
              templates[Math.floor(Math.random() * templates.length)];
            const randomFrom = (arr: string[]): string =>
              arr[Math.floor(Math.random() * arr.length)] ?? "fail";

            return template
              ?.replace("{quality}", randomFrom(qualities))
              ?.replace("{specific}", randomFrom(specifics))
              ?.replace("{mechanic_quality}", randomFrom(mechanics))
              ?.replace("{communication}", randomFrom(communications))
              ?.replace("{flow}", randomFrom(flows))
              ?.replace("{rules}", randomFrom(rules))
              ?.replace("{collaboration}", randomFrom(collaboration));
          },
        }),
        status: f.valuesFromArray({
          values: [
            { weight: 0.15, values: ["DRAFT"] },
            { weight: 0.7, values: ["SUBMITTED"] },
            { weight: 0.15, values: ["APPROVED"] },
          ],
        }),
      },
    },

    users: {
      count: 200,
      columns: {
        email: f.email(),
        name: f.fullName(),
        onboardingComplete: f.valuesFromArray({
          values: [
            { weight: 0.9, values: [true] },
            { weight: 0.1, values: [false] },
          ],
        }),
      },
    },

    waitlist: {
      count: 300,
      columns: {
        email: f.email(),
        status: f.valuesFromArray({
          values: [
            { weight: 0.7, values: ["PENDING"] },
            { weight: 0.2, values: ["APPROVED"] },
            { weight: 0.1, values: ["REJECTED"] },
          ],
        }),
      },
    },
  }));
}

main().catch((e) => {
  console.error(e);
  process.exit(1);
});

Expected Behavior

  • Each table should generate the number of records specified in its count parameter

Actual Behavior

  • All tables except waitlist default to 10 records regardless of count value
  • waitlist table correctly generates specified number of records

Image

Environment

  • Package: drizzle-seed
  • Database: PostgreSQL (neon)
  • Node version: 22.8

Impact

This severely limits the ability to generate realistic test data sets, especially for testing pagination, performance, and data relationships at scale.

@nmarch213 nmarch213 added the bug Something isn't working label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant