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 {
|
import {
|
||||||
FALLBACK_STANDARDS_CONFIG,
|
StandardsConfigSchema,
|
||||||
StandardsDataSchema,
|
|
||||||
StandardsParamsSchema,
|
|
||||||
} from "@blade-and-brawn/calculator";
|
} from "@blade-and-brawn/calculator";
|
||||||
import { Value } from "@sinclair/typebox/value";
|
import { Value } from "@sinclair/typebox/value";
|
||||||
import { db } from "./db";
|
import { db } from "./db";
|
||||||
import { env, log } from "../util";
|
import { env, log } from "../util";
|
||||||
|
import standardsConfig from "./seed-data/standards-config.json" with {type: "json"};
|
||||||
|
|
||||||
const DEFAULT_NAME = "Default";
|
const DEFAULT_NAME = "Default";
|
||||||
|
|
||||||
|
Value.Assert(StandardsConfigSchema, standardsConfig);
|
||||||
|
|
||||||
async function seedStandardsDataset(): Promise<string> {
|
async function seedStandardsDataset(): Promise<string> {
|
||||||
const existing = await db.selectFrom("standards_datasets")
|
const existing = await db.selectFrom("standards_datasets")
|
||||||
.select(["id"])
|
.select(["id"])
|
||||||
@@ -19,9 +20,8 @@ async function seedStandardsDataset(): Promise<string> {
|
|||||||
return existing.id;
|
return existing.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value.Assert(StandardsDataSchema, FALLBACK_STANDARDS_CONFIG.data);
|
|
||||||
const result = await db.insertInto("standards_datasets")
|
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")
|
.returning("id")
|
||||||
.executeTakeFirstOrThrow();
|
.executeTakeFirstOrThrow();
|
||||||
log.info({ id: result.id }, "seeded default standards dataset");
|
log.info({ id: result.id }, "seeded default standards dataset");
|
||||||
@@ -43,12 +43,11 @@ async function seedStandardsConfig(datasetId: string): Promise<void> {
|
|||||||
.where("is_selected", "=", true)
|
.where("is_selected", "=", true)
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
Value.Assert(StandardsParamsSchema, FALLBACK_STANDARDS_CONFIG.params);
|
|
||||||
const result = await db.insertInto("standards_configs")
|
const result = await db.insertInto("standards_configs")
|
||||||
.values({
|
.values({
|
||||||
name: DEFAULT_NAME,
|
name: DEFAULT_NAME,
|
||||||
dataset_id: datasetId,
|
dataset_id: datasetId,
|
||||||
params: FALLBACK_STANDARDS_CONFIG.params,
|
params: standardsConfig.params,
|
||||||
is_selected: !hasSelected,
|
is_selected: !hasSelected,
|
||||||
})
|
})
|
||||||
.returning("id")
|
.returning("id")
|
||||||
|
|||||||
Reference in New Issue
Block a user