unoverse 0.1.88 → 0.1.89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -260,28 +260,68 @@ _ensure_ground_config() {
260
260
  fi
261
261
  fi
262
262
 
263
- # POSTGRES: ASK, DO NOT ASSUME. The ground discovers an existing cluster and writes
264
- # it as a COMMENTED line, so the default silently provisions a SECOND database next
265
- # to one the account already pays for. A choice with a monthly bill attached is a
266
- # question, not a line to notice in a file.
263
+ # PRODUCTION'S DATABASE IS NOT THE ONE IN .env, AND THE QUESTION MUST SAY SO.
264
+ #
265
+ # `.env` holds the DEVELOPMENT database what `npm run dev` talks to on the laptop. The
266
+ # deployed universe gets its own, so a developer cannot break production by experimenting
267
+ # locally. That separation is right and is the default.
268
+ #
269
+ # What was wrong was the words. This asked "You already have a database — use it?", where
270
+ # "it" meant the CLUSTER and "use" meant "create a new database inside it". A developer
271
+ # who had typed a DATABASE_URL during setup read that as "use the database I gave you",
272
+ # answered yes, and got an empty one — then could not find their 21 workflows and
273
+ # reasonably concluded the deploy had lost them. Nothing was lost; the sentence was.
274
+ #
275
+ # So: name the cluster, say a NEW database goes in it, and say what happens to the one in
276
+ # .env. Anyone wanting production to share the development database sets byo_postgres_url
277
+ # deliberately, which is a different and much louder act.
267
278
  if [ "$cloud" = "digitalocean" ] \
268
- && grep -q '^#[[:space:]]*existing_pg_cluster_name' "$tfv" 2>/dev/null \
269
279
  && ! grep -q '^existing_pg_cluster_name' "$tfv" 2>/dev/null \
270
280
  && ! grep -q '^byo_postgres_url' "$tfv" 2>/dev/null; then
271
- local found
272
- found=$(grep '^#[[:space:]]*existing_pg_cluster_name' "$tfv" | sed -E 's/.*"([^"]+)".*/\1/')
273
- if [ -n "$found" ]; then
274
- echo ""
275
- echo -e " ${CYAN}${BOLD}You already have a database.${NC} ${DIM}$found${NC}"
276
- echo ""
277
- pick_option "Use it" "Create a new one ~\$15/month"
278
- if [ "$PICKED" = "0" ]; then
279
- node -e 'const fs=require("fs");const[f,c]=process.argv.slice(1);let s=fs.readFileSync(f,"utf8");s=s.replace(/^#\s*(existing_pg_cluster_name\s*=.*)$/m,"$1");fs.writeFileSync(f,s)' "$tfv" "$found"
280
- ok "Reusing $found"
281
- else
282
- ok "A new database will be created"
283
- fi
281
+ local found env_db db_name
282
+ found=$(grep '^#[[:space:]]*existing_pg_cluster_name' "$tfv" 2>/dev/null | sed -E 's/.*"([^"]+)".*/\1/')
283
+ env_db=$(grep -E '^DATABASE_URL=' "$ROOT/.env" 2>/dev/null | head -1 | cut -d= -f2-)
284
+ db_name=$(echo "$env_db" | sed -E 's|.*/([^/?]+)(\?.*)?$|\1|')
285
+
286
+ echo ""
287
+ echo -e " ${CYAN}${BOLD}Which database should the DEPLOYED universe use?${NC}"
288
+ echo ""
289
+ echo -e " ${DIM}Your .env is your local development database and does not change.${NC}"
290
+ echo ""
291
+ local opt_new_db="" opt_share=""
292
+ [ -n "$found" ] && opt_new_db="Its own new database on ${found} free"
293
+ [ -n "$db_name" ] && opt_share="The same one you develop against ${db_name}"
294
+
295
+ # Order is the recommendation. Its own database first: production and development stay
296
+ # independent, which is what almost everyone wants and what nobody regrets.
297
+ if [ -n "$opt_new_db" ] && [ -n "$opt_share" ]; then
298
+ pick_option "$opt_new_db" "$opt_share" "A new cluster of its own ~\$15/month"
299
+ elif [ -n "$opt_new_db" ]; then
300
+ pick_option "$opt_new_db" "A new cluster of its own ~\$15/month"
301
+ elif [ -n "$opt_share" ]; then
302
+ pick_option "$opt_share" "A new cluster of its own ~\$15/month"
303
+ else
304
+ PICKED=99 # nothing to reuse: the ground provisions a cluster, no question worth asking
284
305
  fi
306
+
307
+ local choice=""
308
+ case "$PICKED" in
309
+ 0) [ -n "$opt_new_db" ] && choice="own" || choice="share" ;;
310
+ 1) [ -n "$opt_new_db" ] && [ -n "$opt_share" ] && choice="share" || choice="fresh" ;;
311
+ *) choice="fresh" ;;
312
+ esac
313
+
314
+ case "$choice" in
315
+ own)
316
+ node -e 'const fs=require("fs");const[f]=process.argv.slice(1);let s=fs.readFileSync(f,"utf8");s=s.replace(/^#\s*(existing_pg_cluster_name\s*=.*)$/m,"$1");fs.writeFileSync(f,s)' "$tfv"
317
+ ok "Production gets its own database on $found ${DIM}(your development data is untouched)${NC}"
318
+ ;;
319
+ share)
320
+ node -e 'const fs=require("fs");const[f,v]=process.argv.slice(1);let s=fs.readFileSync(f,"utf8");s=s.replace(/^#?\s*byo_postgres_url\s*=.*$/m,"byo_postgres_url = "+JSON.stringify(v));fs.writeFileSync(f,s)' "$tfv" "$env_db"
321
+ ok "Production reads ${BOLD}$db_name${NC} ${DIM}(the same database you develop against — local changes are live)${NC}"
322
+ ;;
323
+ *) ok "A new cluster will be created for production" ;;
324
+ esac
285
325
  fi
286
326
 
287
327
  _tf_fill docr_token DOCR_TOKEN "Registry access token (from your Unoverse admin)"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unoverse",
3
- "version": "0.1.88",
3
+ "version": "0.1.89",
4
4
  "description": "The Unoverse front door — create a Studio project, a universe, or a client app, and launch Studio.",
5
5
  "license": "SEE LICENSE IN README.md",
6
6
  "type": "module",