mirror of
https://github.com/hex248/sprint.git
synced 2026-02-09 02:33:02 +00:00
added more users (u3-u8)
This commit is contained in:
@@ -66,28 +66,33 @@ const issues = [
|
|||||||
{ title: "Add batch processing", description: "Need to process large datasets efficiently." },
|
{ title: "Add batch processing", description: "Need to process large datasets efficiently." },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const passwordHash = await hashPassword("a");
|
||||||
|
const users = [
|
||||||
|
{ name: "user 1", username: "u1", passwordHash, avatarURL: null },
|
||||||
|
{ name: "user 2", username: "u2", passwordHash, avatarURL: null },
|
||||||
|
// anything past here is just to have more users to assign issues to
|
||||||
|
{ name: "user 3", username: "u3", passwordHash, avatarURL: null },
|
||||||
|
{ name: "user 4", username: "u4", passwordHash, avatarURL: null },
|
||||||
|
{ name: "user 5", username: "u5", passwordHash, avatarURL: null },
|
||||||
|
{ name: "user 6", username: "u6", passwordHash, avatarURL: null },
|
||||||
|
{ name: "user 7", username: "u7", passwordHash, avatarURL: null },
|
||||||
|
{ name: "user 8", username: "u8", passwordHash, avatarURL: null },
|
||||||
|
];
|
||||||
|
|
||||||
async function seed() {
|
async function seed() {
|
||||||
console.log("seeding database with demo data...");
|
console.log("seeding database with demo data...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const passwordHash = await hashPassword("a");
|
|
||||||
|
|
||||||
// create 2 users
|
// create 2 users
|
||||||
console.log("creating users...");
|
console.log("creating users...");
|
||||||
const users = await db
|
const usersDB = await db.insert(User).values(users).returning();
|
||||||
.insert(User)
|
|
||||||
.values([
|
|
||||||
{ name: "user 1", username: "u1", passwordHash, avatarURL: null },
|
|
||||||
{ name: "user 2", username: "u2", passwordHash, avatarURL: null },
|
|
||||||
])
|
|
||||||
.returning();
|
|
||||||
|
|
||||||
if (users.length < 2 || !users[0] || !users[1]) {
|
if (users.length < 2 || !usersDB[0] || !usersDB[1]) {
|
||||||
throw new Error("failed to create users");
|
throw new Error("failed to create users");
|
||||||
}
|
}
|
||||||
const [u1, u2] = users;
|
const [u1, u2] = [usersDB[0], usersDB[1]];
|
||||||
|
|
||||||
console.log(`created ${users.length} users`);
|
console.log(`created ${usersDB.length} users`);
|
||||||
|
|
||||||
// create 2 orgs per user (4 total)
|
// create 2 orgs per user (4 total)
|
||||||
console.log("creating organisations...");
|
console.log("creating organisations...");
|
||||||
@@ -154,8 +159,6 @@ async function seed() {
|
|||||||
if (!creator) {
|
if (!creator) {
|
||||||
throw new Error("failed to select issue creator");
|
throw new Error("failed to select issue creator");
|
||||||
}
|
}
|
||||||
const assignee =
|
|
||||||
Math.random() > 0.25 ? allUsers[Math.floor(Math.random() * allUsers.length)] : null;
|
|
||||||
const issue = issues[issueIndex % issues.length];
|
const issue = issues[issueIndex % issues.length];
|
||||||
if (!issue) {
|
if (!issue) {
|
||||||
throw new Error("failed to select issue");
|
throw new Error("failed to select issue");
|
||||||
@@ -168,7 +171,6 @@ async function seed() {
|
|||||||
title: issue.title,
|
title: issue.title,
|
||||||
description: issue.description,
|
description: issue.description,
|
||||||
creatorId: creator.id,
|
creatorId: creator.id,
|
||||||
assigneeId: assignee?.id ?? null,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user