Make seed.ts pull from seed-data folder
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user