"count.map is not a function" when attempting to seed database

Hello, I have set up the below seed.ts file in attempt to seed my database by adding fictitious users and scores for a web game I have created (code attached below). However, upon running the script I get the following error:
TypeError: count.map is not a function
    at GenerateWeightedCount.init (/Users/myname/Documents/GitHub/game-racer/node_modules/src/services/Generators.ts:143:52)
    at SeedService.getWeightedWithCount (/Users/myname/Documents/GitHub/game-racer/node_modules/src/services/SeedService.ts:493:7)
    at SeedService.generatePossibleGenerators (/Users/myname/Documents/GitHub/game-racer/node_modules/src/services/SeedService.ts:144:34)
    at seedPostgres (/Users/myname/Documents/GitHub/game-racer/node_modules/src/index.ts:539:48)
    at seedFunc (/Users/myname/Documents/GitHub/game-racer/node_modules/src/index.ts:387:9)
    at SeedPromise.refine (/Users/myname/Documents/GitHub/game-racer/node_modules/src/index.ts:204:9)
    at main (/Users/myname/Documents/GitHub/game-racer/src/db/drizzle/seed/seed.ts:16:26)
    at dotenv (/Users/myname/Documents/GitHub/game-racer/src/db/drizzle/seed/seed.ts:63:1)
    at Object.<anonymous> (/Users/myname/Documents/GitHub/game-racer/src/db/drizzle/seed/seed.ts:63:27)
    at Module._compile (node:internal/modules/cjs/loader:1554:14)
TypeError: count.map is not a function
    at GenerateWeightedCount.init (/Users/myname/Documents/GitHub/game-racer/node_modules/src/services/Generators.ts:143:52)
    at SeedService.getWeightedWithCount (/Users/myname/Documents/GitHub/game-racer/node_modules/src/services/SeedService.ts:493:7)
    at SeedService.generatePossibleGenerators (/Users/myname/Documents/GitHub/game-racer/node_modules/src/services/SeedService.ts:144:34)
    at seedPostgres (/Users/myname/Documents/GitHub/game-racer/node_modules/src/index.ts:539:48)
    at seedFunc (/Users/myname/Documents/GitHub/game-racer/node_modules/src/index.ts:387:9)
    at SeedPromise.refine (/Users/myname/Documents/GitHub/game-racer/node_modules/src/index.ts:204:9)
    at main (/Users/myname/Documents/GitHub/game-racer/src/db/drizzle/seed/seed.ts:16:26)
    at dotenv (/Users/myname/Documents/GitHub/game-racer/src/db/drizzle/seed/seed.ts:63:1)
    at Object.<anonymous> (/Users/myname/Documents/GitHub/game-racer/src/db/drizzle/seed/seed.ts:63:27)
    at Module._compile (node:internal/modules/cjs/loader:1554:14)
I don't understand why it's trying to map count? Any advice would be greatly appreciated.
1 Reply
Seb
SebOP6d ago
Here is the code I have written for my seed.ts file:
import dotenv from "dotenv";
dotenv.config({ path: ".env.local" });

import * as schema from "../publicSchema";
import { drizzle } from "drizzle-orm/node-postgres";
import { seed } from "drizzle-seed";
import { faker } from "@faker-js/faker";
import { UUID } from "crypto";

export async function main() {
const url = process.env.DATABASE_URL;

if (!url) throw new Error("DATABASE_URL is not set");
const db = drizzle(url);

await seed(db, schema).refine((f) => ({
profiles: {
columns: {
id: f.uuid(),
full_name: f.fullName(),
username: faker.internet.username(),
avatar_url: faker.image.avatar(),
email: faker.internet.email(),
updated_at: f.date({ minDate: "2025-01-01", maxDate: "2025-05-02" }),
created_at: f.date({ minDate: "2025-01-01", maxDate: "2025-05-02" }),
marketing: "false",
phone: faker.phone.imei(),
role: "basic",
},
count: 100,
with: {
scores: {
columns: {
id: f.uuid(),
user_id: (profile: { id: UUID }) => profile.id,
variant_id: "a4199f83-7a50-4de9-8456-59fad33b7591",
metrics: () => ({
score: f.int({ minValue: 50, maxValue: 250 }),
acc_pct: f.number({
minValue: 0.4,
maxValue: 0.99,
precision: 0.01,
}),
raw_npm: f.int({ minValue: 50, maxValue: 250 }),
adjusted_npm: f.int({ minValue: 50, maxValue: 250 }),
}),
played_at: f.date({ minDate: "2025-01-01", maxDate: "2025-05-02" }),
},
count: 50,
},
},
},
}));

console.log("Seeding complete!");
}

main().catch(console.error);
import dotenv from "dotenv";
dotenv.config({ path: ".env.local" });

import * as schema from "../publicSchema";
import { drizzle } from "drizzle-orm/node-postgres";
import { seed } from "drizzle-seed";
import { faker } from "@faker-js/faker";
import { UUID } from "crypto";

export async function main() {
const url = process.env.DATABASE_URL;

if (!url) throw new Error("DATABASE_URL is not set");
const db = drizzle(url);

await seed(db, schema).refine((f) => ({
profiles: {
columns: {
id: f.uuid(),
full_name: f.fullName(),
username: faker.internet.username(),
avatar_url: faker.image.avatar(),
email: faker.internet.email(),
updated_at: f.date({ minDate: "2025-01-01", maxDate: "2025-05-02" }),
created_at: f.date({ minDate: "2025-01-01", maxDate: "2025-05-02" }),
marketing: "false",
phone: faker.phone.imei(),
role: "basic",
},
count: 100,
with: {
scores: {
columns: {
id: f.uuid(),
user_id: (profile: { id: UUID }) => profile.id,
variant_id: "a4199f83-7a50-4de9-8456-59fad33b7591",
metrics: () => ({
score: f.int({ minValue: 50, maxValue: 250 }),
acc_pct: f.number({
minValue: 0.4,
maxValue: 0.99,
precision: 0.01,
}),
raw_npm: f.int({ minValue: 50, maxValue: 250 }),
adjusted_npm: f.int({ minValue: 50, maxValue: 250 }),
}),
played_at: f.date({ minDate: "2025-01-01", maxDate: "2025-05-02" }),
},
count: 50,
},
},
},
}));

console.log("Seeding complete!");
}

main().catch(console.error);
I'm unsure if it has any baring on the issue, but I am also receiving the following informational messages prior to the error taking place:
You are providing a one-to-many relation between the 'games' and 'gameVariants' tables,
while the 'gameVariants' table object already has foreign key constraint in the schema referencing 'games' table.
In this case, the foreign key constraint will be used.

You are providing a one-to-many relation between the 'profiles' and 'highScores' tables,
while the 'highScores' table object already has foreign key constraint in the schema referencing 'profiles' table.
In this case, the foreign key constraint will be used.

You are providing a one-to-many relation between the 'scores' and 'highScores' tables,
while the 'highScores' table object already has foreign key constraint in the schema referencing 'scores' table.
In this case, the foreign key constraint will be used.

You are providing a one-to-many relation between the 'gameVariants' and 'highScores' tables,
while the 'highScores' table object already has foreign key constraint in the schema referencing 'gameVariants' table.
In this case, the foreign key constraint will be used.

You are providing a one-to-many relation between the 'gameVariants' and 'scores' tables,
while the 'scores' table object already has foreign key constraint in the schema referencing 'gameVariants' table.
In this case, the foreign key constraint will be used.
You are providing a one-to-many relation between the 'games' and 'gameVariants' tables,
while the 'gameVariants' table object already has foreign key constraint in the schema referencing 'games' table.
In this case, the foreign key constraint will be used.

You are providing a one-to-many relation between the 'profiles' and 'highScores' tables,
while the 'highScores' table object already has foreign key constraint in the schema referencing 'profiles' table.
In this case, the foreign key constraint will be used.

You are providing a one-to-many relation between the 'scores' and 'highScores' tables,
while the 'highScores' table object already has foreign key constraint in the schema referencing 'scores' table.
In this case, the foreign key constraint will be used.

You are providing a one-to-many relation between the 'gameVariants' and 'highScores' tables,
while the 'highScores' table object already has foreign key constraint in the schema referencing 'gameVariants' table.
In this case, the foreign key constraint will be used.

You are providing a one-to-many relation between the 'gameVariants' and 'scores' tables,
while the 'scores' table object already has foreign key constraint in the schema referencing 'gameVariants' table.
In this case, the foreign key constraint will be used.

Did you find this page helpful?