Drizzle seed stuck and no info displayed

Hi all, im experimenting with using drizzle-seed to seed my db instead of using raw sqls I have a script that is basically a slight modification of the tutorial from the docs, but it seems to hand/gets stuck when I run it. Any ideas why and what I could do? There's no debug messages either so its not very helpful.
No description
6 Replies
Mario564
Mario5642mo ago
CC: @OleksiiKH
scape
scape2mo ago
Had exact same issue. You probably don't expose all relevant schema tables for drizzle seed. Make sure you provide tables that bloodPressure has fk's on. Should've created an issue. My bad. Will try to replicate rereproduce
Zefty
ZeftyOP2mo ago
Ahh will try that. But yes that table has dependencies on another table I have a dependency on the user table. Is it possible to generate seed data with a hardcoded userid
OleksiiKH
OleksiiKH2mo ago
Hi, I fixed the bug locally. It will be included in the next release. (PR -> https://github.com/drizzle-team/drizzle-orm/pull/3808) Yes, you can generate a hardcoded userId, as shown in the example below.
const users = pgTable("users", {
id: serial("id").primaryKey(),
});

const bloodPressure = pgTable("bloodPressure", {
bloodPressureId: serial().primaryKey(),
pressure: doublePrecision(),
userId: integer().references(() => users.id),
})

await seed(db, { bloodPressure }, {count: 10}).refine((funcs) => ({
bloodPressure: {
columns: {
userId: funcs.valuesFromArray({values: [1, 2]})
}
}
}))
const users = pgTable("users", {
id: serial("id").primaryKey(),
});

const bloodPressure = pgTable("bloodPressure", {
bloodPressureId: serial().primaryKey(),
pressure: doublePrecision(),
userId: integer().references(() => users.id),
})

await seed(db, { bloodPressure }, {count: 10}).refine((funcs) => ({
bloodPressure: {
columns: {
userId: funcs.valuesFromArray({values: [1, 2]})
}
}
}))
However, you need to ensure that the users table already contains the IDs you are providing to the valuesFromArray generator in refine.
Zefty
ZeftyOP2mo ago
Hey thanks for the code there. The above seems to work only if we provide both the users table and bloodPressure into the seed schema. I was wondering if we can seed a table with preexisting users data Do you know if that is possible?
OleksiiKH
OleksiiKH2mo ago
Hi, the code above works in the latest version of drizzle-seed (0.2.1, the one without the bug) without requiring the users table to be included in the seed schema.

Did you find this page helpful?