#!/bin/sh # Seeds the bundled map geometry into MongoDB. # # scripts/seed_mongodb.js only touches a database that has no collections and # refuses a second run, so this wrapper checks first and skips the import on an # already seeded volume. set -eu cd /app : "${MONGODB_URI:?MONGODB_URI is not set}" DB_NAME="${MONGODB_NAME:-adventureland}" existing=$(node -e ' const { MongoClient } = require("mongodb"); const uri = process.env.MONGODB_URI; const name = process.env.MONGODB_NAME || "adventureland"; (async () => { const client = new MongoClient(uri, { serverSelectionTimeoutMS: 15000 }); await client.connect(); const collections = await client.db(name).listCollections({}, { nameOnly: true }).toArray(); await client.close(); process.stdout.write(String(collections.length)); })().catch((error) => { console.error("MongoDB check failed:", error.message); process.exit(1); }); ') if [ "${existing}" -gt 0 ]; then echo "Database '${DB_NAME}' already has ${existing} collection(s) - skipping seed." exit 0 fi echo "Database '${DB_NAME}' is empty - importing map data ..." exec node scripts/seed_mongodb.js --confirm "${DB_NAME}"