[Solved] drizzle-seed autocomplete not working if there are enums or zod objects

Not sure which tag to use for drizzle-seed . I'm trying to seed my database and I was surprised that I wouldn't get table autocomplete inside the seed function when the schema is in different files. Whenever I import * from "./single-file" everything seems to work. Curiously when I deconstruct the import for a specific table, I lose the autocompelte. The tsconfig is in the comment below. Case 1 (works) - import * as schema from "./schema/contexts"
import { seed } from "drizzle-seed";
import * as schema from "./schema/contexts";
import { linkDatabase } from ".";

const main = async () => {
const { db } = linkDatabase();

await seed(db, schema).refine((f) => ({
// contexts gets suggested
}));
};

main();
import { seed } from "drizzle-seed";
import * as schema from "./schema/contexts";
import { linkDatabase } from ".";

const main = async () => {
const { db } = linkDatabase();

await seed(db, schema).refine((f) => ({
// contexts gets suggested
}));
};

main();
Case 2 (doesn't work when the schema is distributed in different files) - import * as schema from "./schema/"
import { seed } from "drizzle-seed";
import * as schema from "./schema/";
import { linkDatabase } from ".";


const main = async () => {
const { db } = linkDatabase();

await seed(db, schema).refine((f) => ({
// contexts doesn't get autocompleted
}));
};

main();
import { seed } from "drizzle-seed";
import * as schema from "./schema/";
import { linkDatabase } from ".";


const main = async () => {
const { db } = linkDatabase();

await seed(db, schema).refine((f) => ({
// contexts doesn't get autocompleted
}));
};

main();
Case 3 (doesn't work when the import is deconstructed - import { contexts } from "./schema/contexts"
import { seed } from "drizzle-seed";
import { contexts } from "./schema/contexts";
import { linkDatabase } from ".";

const main = async () => {
const { db } = linkDatabase();

await seed(db, contexts).refine((f) => ({ // Note that contexts gets passed here
// contexts doesn't get autocompleted
}));
};

main();
import { seed } from "drizzle-seed";
import { contexts } from "./schema/contexts";
import { linkDatabase } from ".";

const main = async () => {
const { db } = linkDatabase();

await seed(db, contexts).refine((f) => ({ // Note that contexts gets passed here
// contexts doesn't get autocompleted
}));
};

main();
Would appreciate any ideas, thanks!
1 Reply
playsonmac
playsonmacOP4w ago
Here's the tsconfig:
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"moduleDetection": "force",
"useDefineForClassFields": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"strict": true
},
"include": ["**/*.ts", "**/*.js"],
"exclude": ["node_modules"]
}
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"moduleDetection": "force",
"useDefineForClassFields": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"strict": true
},
"include": ["**/*.ts", "**/*.js"],
"exclude": ["node_modules"]
}
Initially I thought its because I had drizzle-zod schemas defined within the same files where the table definitions are but it still doesn't work after I've removed them It's the enums that are breaking it Turns out anything that is not PgTable (in my case) breaks the autocomplete inside the seed function. When I extracted the tables to a new dbSchema object and pass it to the seed function, the autocomplete works.

Did you find this page helpful?