This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
|
||||
// `pnpm seed`: the demo data (seed.ts) written into the database a development run uses. It runs as
|
||||
// the runtime role, like the web shell, through the same use cases, so the schema must be migrated
|
||||
// first (`pnpm migrate`; `pnpm dev` does both). It refuses a production run: demo people with known
|
||||
// addresses in a real deployment's database is a mistake no flag should make easy.
|
||||
|
||||
import { loadAppEnv, PlatformEnvError, quietObservability } from "@app/config"
|
||||
import { buildWorkerRuntime } from "./runtime.js"
|
||||
import { DEMO_PEOPLE, seedDemo } from "./seed.js"
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const env = loadAppEnv("worker")
|
||||
if (env.production) {
|
||||
throw new PlatformEnvError(
|
||||
"NODE_ENV",
|
||||
"the demo data is for development: it is refused in a production run (NODE_ENV is neither development nor test)",
|
||||
)
|
||||
}
|
||||
const runtime = buildWorkerRuntime(env, quietObservability(env))
|
||||
try {
|
||||
const summary = await seedDemo({ data: runtime.data, registry: runtime.registry, container: runtime.container })
|
||||
const base = env.deployment.CONUSAI_PUBLIC_URL ?? "http://127.0.0.1:3000"
|
||||
console.info(
|
||||
summary.created.length === 0
|
||||
? "seed: the demo data was already there"
|
||||
: `seed: created ${summary.created.join("; ")}`,
|
||||
)
|
||||
for (const person of DEMO_PEOPLE) {
|
||||
console.info(`seed: ${person.name}: ${base}/auth/dev-login?email=${person.email}`)
|
||||
}
|
||||
} finally {
|
||||
await runtime.close()
|
||||
}
|
||||
}
|
||||
|
||||
main().then(
|
||||
() => process.exit(0),
|
||||
(error: unknown) => {
|
||||
console.error(`seed: ${error instanceof Error ? error.message : String(error)}`)
|
||||
process.exit(1)
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user