Update the Seed Script
Right now the seed script inserts projects without owners and issues without creators.
Update convex/seed.ts:
import { v } from "convex/values";
import { internalMutation } from "./_generated/server";
export const insertSeedData = internalMutation({
args: {
projects: v.array(
v.object({
name: v.string(),
description: v.optional(v.string()),
issues: v.array(
v.object({
title: v.string(),
description: v.string(),
status: v.union(
v.literal("todo"),
v.literal("in-progress"),
v.literal("done"),
),
}),
),
}),
),
},
handler: async (ctx, args) => {
// Seeded data needs an owner. We use the first user in the `users`
// table — typically whoever signed in first during development. If the
// table is empty, the seed refuses to run and tells you what to do.
const owner = await ctx.db.query("users").first();
if (owner === null) {
throw new Error(
"No users found. Sign in with GitHub in the app at least once before running the seed script.",
);
}
for (const project of args.projects) {
const projectId = await ctx.db.insert("projects", {
name: project.name,
description: project.description,
ownerId: owner._id,
});
for (const issue of project.issues) {
await ctx.db.insert("issues", {
projectId,
creatorId: owner._id,
title: issue.title,
description: issue.description,
status: issue.status,
});
}
}
},
});
The seed now does not run until you have signed in at least once, because signing in is what creates a row in the users table. After you have signed in, pnpm run seed creates fifty projects and assigns them, and all of their issues, to you as owner and creator.
A more sophisticated script would create synthetic users and spread ownership across them, so you could test multi-user scenarios. For this project, single-user ownership is fine. It fills the local database with enough data to demo, and it avoids the extra work of creating headless user records.
Try It Out
- Run
pnpm devto start the app - Sign in with GitHub if you have not already.
- Then run
pnpm run seedto populate the database with projects and issues owned by your user account.
Checkpoint: Commit your progress.
git add .
git commit -m "tracker-07: Update seed script to assign ownership to first user"
git push