Zod validated config for security and ease of getting started

This commit is contained in:
Kalle
2026-06-15 14:12:15 +03:00
parent 215243e071
commit 75179e5077
46 changed files with 386 additions and 275 deletions

View File

@@ -1,25 +1,12 @@
import fs from "node:fs";
import { seed } from "~/db/seed";
import { db } from "~/db/sql";
import { logger } from "~/utils/logger";
import { seedImages } from "./seed-images";
async function main() {
// Step 1: Create .env if it doesn't exist
if (!fs.existsSync(".env")) {
logger.info("📄 .env not found. Creating from .env.example...");
const envContent = fs.readFileSync(".env.example", "utf-8");
const filteredEnv = envContent
.split("\n")
.filter((line) => !line.trim().startsWith("//")) // remove comments to prevent issues with Docker
.join("\n");
fs.writeFileSync(".env", filteredEnv);
logger.info(".env created with default values");
}
const dbEmpty = !(await db.selectFrom("User").selectAll().executeTakeFirst());
// Step 2: Run migration and seed if db.sqlite3 doesn't exist
// Run migration and seed if db.sqlite3 doesn't exist
if (dbEmpty) {
logger.info("🌱 Seeding database...");
try {
@@ -34,7 +21,7 @@ async function main() {
}
}
// Step 3: Seed images to Minio
// Seed images to Minio
logger.info("🖼️ Seeding images to Minio...");
try {
await seedImages();