Make seed.ts pull from seed-data folder

This commit is contained in:
Dominic Ferrando
2026-07-05 20:13:47 -04:00
parent 338a40d947
commit 49f4f209a6
2 changed files with 5403 additions and 7 deletions
+6 -7
View File
@@ -1,14 +1,15 @@
import {
FALLBACK_STANDARDS_CONFIG,
StandardsDataSchema,
StandardsParamsSchema,
StandardsConfigSchema,
} from "@blade-and-brawn/calculator";
import { Value } from "@sinclair/typebox/value";
import { db } from "./db";
import { env, log } from "../util";
import standardsConfig from "./seed-data/standards-config.json" with {type: "json"};
const DEFAULT_NAME = "Default";
Value.Assert(StandardsConfigSchema, standardsConfig);
async function seedStandardsDataset(): Promise<string> {
const existing = await db.selectFrom("standards_datasets")
.select(["id"])
@@ -19,9 +20,8 @@ async function seedStandardsDataset(): Promise<string> {
return existing.id;
}
Value.Assert(StandardsDataSchema, FALLBACK_STANDARDS_CONFIG.data);
const result = await db.insertInto("standards_datasets")
.values({ name: DEFAULT_NAME, data: FALLBACK_STANDARDS_CONFIG.data })
.values({ name: DEFAULT_NAME, data: standardsConfig.data })
.returning("id")
.executeTakeFirstOrThrow();
log.info({ id: result.id }, "seeded default standards dataset");
@@ -43,12 +43,11 @@ async function seedStandardsConfig(datasetId: string): Promise<void> {
.where("is_selected", "=", true)
.executeTakeFirst();
Value.Assert(StandardsParamsSchema, FALLBACK_STANDARDS_CONFIG.params);
const result = await db.insertInto("standards_configs")
.values({
name: DEFAULT_NAME,
dataset_id: datasetId,
params: FALLBACK_STANDARDS_CONFIG.params,
params: standardsConfig.params,
is_selected: !hasSelected,
})
.returning("id")