@mostajs/orm-cli 0.5.4 → 0.5.5

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 +31 -5
  2. package/package.json +1 -1
package/bin/mostajs.sh CHANGED
@@ -1938,7 +1938,8 @@ action_rep_add_replica() {
1938
1938
  dim " Use a SHORT IDENTIFIER here (NOT a database URI — the URI comes later)."
1939
1939
  echo
1940
1940
  local project name role dialect uri lag
1941
- project=$(ask "Project name (short id, e.g. 'fitzone')" "fitzone")
1941
+ # Use the smart project picker (lists known projects, suggests first)
1942
+ project=$(_pick_project)
1942
1943
  # Basic validation : reject URIs or paths
1943
1944
  if [[ "$project" == *"://"* || "$project" == *"/"* ]]; then
1944
1945
  err " Project name looks like a URI or path. Use a short identifier (e.g. 'fitzone')."
@@ -1984,9 +1985,34 @@ action_rep_add_replica() {
1984
1985
  pause
1985
1986
  }
1986
1987
 
1988
+ # List known projects from the replicator-tree.json — if any — and propose
1989
+ # the first one as default. Echoes the chosen project name to stdout.
1990
+ # Returns 1 if user cancelled.
1991
+ _pick_project() {
1992
+ local tree_file
1993
+ tree_file=$(_replicator_tree_file)
1994
+ local projects=()
1995
+ if [[ -f "$tree_file" ]]; then
1996
+ while IFS= read -r p; do projects+=("$p"); done < <(
1997
+ node -e "try{const t=JSON.parse(require('fs').readFileSync('$tree_file','utf8'));for(const k of Object.keys(t.replicas||{}))console.log(k)}catch{}" 2>/dev/null
1998
+ )
1999
+ fi
2000
+ local default_project="fitzone"
2001
+ if [[ ${#projects[@]} -gt 0 ]]; then
2002
+ default_project="${projects[0]}"
2003
+ if [[ ${#projects[@]} -gt 1 ]]; then
2004
+ echo >&2
2005
+ dim " Known projects : ${projects[*]}" >&2
2006
+ fi
2007
+ fi
2008
+ local picked
2009
+ picked=$(ask "Project name" "$default_project")
2010
+ echo "$picked"
2011
+ }
2012
+
1987
2013
  action_rep_list_replicas() {
1988
2014
  local project
1989
- project=$(ask "Project name" "default")
2015
+ project=$(_pick_project)
1990
2016
  _replicator_run "
1991
2017
  const status = rm.getReplicaStatus('$project');
1992
2018
  if (!status || status.length === 0) {
@@ -2002,7 +2028,7 @@ action_rep_list_replicas() {
2002
2028
 
2003
2029
  action_rep_promote() {
2004
2030
  local project name
2005
- project=$(ask "Project name" "default")
2031
+ project=$(_pick_project)
2006
2032
  name=$(ask "Slave to promote" "slave-1")
2007
2033
  if ! confirm "Promote '$name' to master on project '$project'?"; then return; fi
2008
2034
  _replicator_run "
@@ -2015,7 +2041,7 @@ action_rep_promote() {
2015
2041
 
2016
2042
  action_rep_remove_replica() {
2017
2043
  local project name
2018
- project=$(ask "Project name" "default")
2044
+ project=$(_pick_project)
2019
2045
  name=$(ask "Replica name" "slave-1")
2020
2046
  if ! confirm "Remove replica '$name' from project '$project'?"; then return; fi
2021
2047
  _replicator_run "
@@ -2028,7 +2054,7 @@ action_rep_remove_replica() {
2028
2054
 
2029
2055
  action_rep_set_routing() {
2030
2056
  local project strategy
2031
- project=$(ask "Project name" "default")
2057
+ project=$(_pick_project)
2032
2058
  strategy=$(ask "Strategy (round-robin | least-lag | random)" "least-lag")
2033
2059
  _replicator_run "
2034
2060
  rm.setReadRouting('$project', '$strategy');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mostajs/orm-cli",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
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",