Add default account to seed script
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
StandardsConfigSchema,
|
||||
} from "@blade-and-brawn/calculator";
|
||||
import { Gender } from "@blade-and-brawn/domain";
|
||||
import { Value } from "@sinclair/typebox/value";
|
||||
import { db } from "./db";
|
||||
import { DEFAULT_NAME, env, log } from "../util";
|
||||
@@ -68,6 +69,44 @@ async function seedCalculator(standardsConfigId: string): Promise<void> {
|
||||
log.info({ id: result.id }, "seeded default calculator");
|
||||
}
|
||||
|
||||
async function seedAccounts(): Promise<void> {
|
||||
const existing = await db.selectFrom("accounts")
|
||||
.select(["id"])
|
||||
.where("name", "=", DEFAULT_NAME)
|
||||
.executeTakeFirst();
|
||||
if (existing) {
|
||||
log.info({ id: existing.id }, "default account already seeded, skipping");
|
||||
return;
|
||||
}
|
||||
|
||||
const account = await db.insertInto("accounts")
|
||||
.values({
|
||||
name: DEFAULT_NAME,
|
||||
discord_id: "1521640671721685157",
|
||||
email: "outgrow_document040@simplelogin.com"
|
||||
})
|
||||
.returning("id")
|
||||
.executeTakeFirstOrThrow();
|
||||
log.info({ id: account.id }, "seeded default account");
|
||||
|
||||
await db.insertInto("assessments")
|
||||
.values({
|
||||
account_id: account.id,
|
||||
name: DEFAULT_NAME,
|
||||
gender: Gender.Male,
|
||||
age: 25,
|
||||
weight: 80,
|
||||
perf_back_squat: 72.57472,
|
||||
perf_deadlift: 127.00576,
|
||||
perf_bench_press: 102.0582,
|
||||
perf_run: 446000,
|
||||
perf_broad_jump: 185.42000000000002,
|
||||
perf_cone_drill: 9870,
|
||||
})
|
||||
.execute();
|
||||
log.info({ accountId: account.id }, "seeded placeholder assessment");
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const answer = prompt(`Seed the database (${env.DATABASE_URL}) with default standards data? (y/N)`);
|
||||
if (answer?.trim().toLowerCase() !== "y") {
|
||||
@@ -80,6 +119,7 @@ async function seedCalculator(standardsConfigId: string): Promise<void> {
|
||||
const datasetId = await seedStandardsDataset();
|
||||
const standardsConfigId = await seedStandardsConfig(datasetId);
|
||||
await seedCalculator(standardsConfigId);
|
||||
await seedAccounts();
|
||||
log.info("seed finished");
|
||||
}
|
||||
catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user