Seb
DTDrizzle Team
•Created by Seb on 5/2/2025 in #help
"count.map is not a function" when attempting to seed database
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.
3 replies
DTDrizzle Team
•Created by Seb on 5/2/2025 in #help
"count.map is not a function" when attempting to seed database
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);
3 replies