@mostajs/orm-cli 0.4.2 → 0.4.3

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.
Files changed (2) hide show
  1. package/bin/mostajs.sh +67 -9
  2. package/package.json +1 -1
package/bin/mostajs.sh CHANGED
@@ -2515,14 +2515,69 @@ run_subcommand() {
2515
2515
  fi
2516
2516
 
2517
2517
  mkdir -p "$CONFIG_DIR"
2518
- if [[ ! -f "$CONFIG_DIR/config.env" ]]; then
2518
+ # ── Database choice ──
2519
+ # Resolution order :
2520
+ # 1. existing .mostajs/config.env → honour it (user may have set it with `mostajs` menu 2)
2521
+ # 2. --dialect / --uri / --strategy CLI flags → non-interactive scripting
2522
+ # 3. $DB_DIALECT + $SGBD_URI env vars → non-interactive, no files on disk
2523
+ # 4. interactive prompt (default)
2524
+ if [[ -f "$CONFIG_DIR/config.env" ]]; then
2525
+ load_env
2526
+ info " using existing $CONFIG_DIR/config.env (dialect=$DB_DIALECT uri=$SGBD_URI)"
2527
+ else
2528
+ local bs_dialect="" bs_uri="" bs_strategy="update"
2529
+ for arg in "$@"; do
2530
+ case "$arg" in
2531
+ --dialect=*) bs_dialect="${arg#--dialect=}" ;;
2532
+ --uri=*) bs_uri="${arg#--uri=}" ;;
2533
+ --strategy=*) bs_strategy="${arg#--strategy=}" ;;
2534
+ esac
2535
+ done
2536
+ # Fall back to env vars
2537
+ [[ -z "$bs_dialect" ]] && bs_dialect="${DB_DIALECT:-}"
2538
+ [[ -z "$bs_uri" ]] && bs_uri="${SGBD_URI:-}"
2539
+
2540
+ if [[ -z "$bs_dialect" || -z "$bs_uri" ]]; then
2541
+ echo
2542
+ echo -e "${BOLD}▶ Database choice${RESET} ${DIM}(run \`$CLI_NAME\` then menu 2 beforehand to skip this prompt)${RESET}"
2543
+ echo
2544
+ echo " ${CYAN}1${RESET}) SQLite ${DIM}./data.sqlite (zero setup, recommended for trying out)${RESET}"
2545
+ echo " ${CYAN}2${RESET}) PostgreSQL ${DIM}postgres://user:pass@host:5432/db${RESET}"
2546
+ echo " ${CYAN}3${RESET}) MongoDB ${DIM}mongodb://user:pass@host:27017/db${RESET}"
2547
+ echo " ${CYAN}4${RESET}) MySQL ${DIM}mysql://user:pass@host:3306/db${RESET}"
2548
+ echo " ${CYAN}5${RESET}) MariaDB ${DIM}mariadb://user:pass@host:3306/db${RESET}"
2549
+ echo " ${CYAN}6${RESET}) Oracle ${DIM}oracle://user:pass@host:1521/XE${RESET}"
2550
+ echo " ${CYAN}7${RESET}) SQL Server ${DIM}mssql://user:pass@host:1433/db${RESET}"
2551
+ echo " ${CYAN}8${RESET}) CockroachDB ${DIM}postgresql://user:pass@host:26257/db?sslmode=disable${RESET}"
2552
+ echo " ${CYAN}9${RESET}) DB2 / HANA / HSQLDB / Spanner / Sybase / other (enter manually)"
2553
+ echo
2554
+ local c; c=$(ask "Choice" "1")
2555
+ case "$c" in
2556
+ 1) bs_dialect="sqlite"; bs_uri=$(ask "SQLite path" "./data.sqlite") ;;
2557
+ 2) bs_dialect="postgres"; bs_uri=$(ask "Postgres URI" "postgres://user:pass@localhost:5432/mydb") ;;
2558
+ 3) bs_dialect="mongodb"; bs_uri=$(ask "MongoDB URI" "mongodb://localhost:27017/mydb") ;;
2559
+ 4) bs_dialect="mysql"; bs_uri=$(ask "MySQL URI" "mysql://user:pass@localhost:3306/mydb") ;;
2560
+ 5) bs_dialect="mariadb"; bs_uri=$(ask "MariaDB URI" "mariadb://user:pass@localhost:3306/mydb") ;;
2561
+ 6) bs_dialect="oracle"; bs_uri=$(ask "Oracle URI" "oracle://user:pass@localhost:1521/XE") ;;
2562
+ 7) bs_dialect="mssql"; bs_uri=$(ask "SQL Server URI" "mssql://user:pass@localhost:1433/mydb") ;;
2563
+ 8) bs_dialect="cockroachdb"; bs_uri=$(ask "CockroachDB URI" "postgresql://root@localhost:26257/mydb?sslmode=disable") ;;
2564
+ 9) bs_dialect=$(ask "Dialect (db2|hana|hsqldb|spanner|sybase|other)" "")
2565
+ bs_uri=$(ask "URI" "") ;;
2566
+ *) err "Invalid choice"; exit 1 ;;
2567
+ esac
2568
+ [[ -z "$bs_dialect" || -z "$bs_uri" ]] && { err "dialect and uri are required"; exit 1; }
2569
+
2570
+ local chosen_strategy
2571
+ chosen_strategy=$(ask "Schema strategy (validate|update|create|create-drop|none)" "$bs_strategy")
2572
+ bs_strategy="$chosen_strategy"
2573
+ fi
2574
+
2519
2575
  cat > "$CONFIG_DIR/config.env" <<CFG
2520
- DB_DIALECT=sqlite
2521
- SGBD_URI=./data.sqlite
2522
- DB_SCHEMA_STRATEGY=update
2576
+ DB_DIALECT=$bs_dialect
2577
+ SGBD_URI=$bs_uri
2578
+ DB_SCHEMA_STRATEGY=$bs_strategy
2523
2579
  CFG
2524
- ok " wrote $CONFIG_DIR/config.env (defaults: sqlite ./data.sqlite)"
2525
- # Reload config so action_init_dialects picks up the new values
2580
+ ok " wrote $CONFIG_DIR/config.env (dialect=$bs_dialect)"
2526
2581
  load_env
2527
2582
  fi
2528
2583
 
@@ -2542,7 +2597,7 @@ CFG
2542
2597
 
2543
2598
  ✓ Bridge installed in-place. Original files backed up as *.prisma.bak
2544
2599
  ✓ Schema converted : $GENERATED_DIR/entities.json
2545
- ✓ DDL applied (DB_DIALECT=\$(grep ^DB_DIALECT $CONFIG_DIR/config.env | cut -d= -f2))
2600
+ ✓ DDL applied (DB_DIALECT=$DB_DIALECT SGBD_URI=$SGBD_URI)
2546
2601
 
2547
2602
  Next :
2548
2603
  - Add seeds to $CONFIG_DIR/seeds/*.json (one file per entity)
@@ -2566,8 +2621,11 @@ DONE
2566
2621
  cat <<EOF
2567
2622
  Usage :
2568
2623
  $CLI_NAME Interactive menu
2569
- $CLI_NAME bootstrap One-shot migration : codemod + deps + convert + DDL
2570
- $CLI_NAME install-bridge Codemod only (dry-run ; add --apply to write)
2624
+ $CLI_NAME bootstrap One-shot migration : codemod + deps + convert + DDL
2625
+ (interactive database picker unless config exists)
2626
+ $CLI_NAME bootstrap --dialect=postgres --uri=postgres://... --strategy=update
2627
+ Non-interactive bootstrap (for CI / scripts)
2628
+ $CLI_NAME install-bridge Codemod only (dry-run ; add --apply to write)
2571
2629
  $CLI_NAME install-bridge --apply Rewrite PrismaClient sites to use @mostajs/orm-bridge
2572
2630
  $CLI_NAME install-bridge --restore --apply Undo a prior install-bridge
2573
2631
  $CLI_NAME convert Run conversion (auto-detect schema type)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mostajs/orm-cli",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Universal CLI to integrate @mostajs/orm into any project — one-shot `mostajs bootstrap` migrates a Prisma project (codemod + deps + schema convert + DDL) to 13 databases with zero code change.",
5
5
  "author": "Dr Hamid MADANI <drmdh@msn.com>",
6
6
  "license": "AGPL-3.0-or-later",