@mostajs/orm-cli 0.5.3 → 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 +63 -8
  2. package/package.json +1 -1
package/bin/mostajs.sh CHANGED
@@ -1933,18 +1933,48 @@ action_rep_scaffold_services() {
1933
1933
  }
1934
1934
 
1935
1935
  action_rep_add_replica() {
1936
+ echo
1937
+ dim " A project is a logical group of replicas (e.g. 'fitzone', 'secuaccess')."
1938
+ dim " Use a SHORT IDENTIFIER here (NOT a database URI — the URI comes later)."
1939
+ echo
1936
1940
  local project name role dialect uri lag
1937
- project=$(ask "Project name" "default")
1938
- name=$(ask "Replica name" "master")
1941
+ # Use the smart project picker (lists known projects, suggests first)
1942
+ project=$(_pick_project)
1943
+ # Basic validation : reject URIs or paths
1944
+ if [[ "$project" == *"://"* || "$project" == *"/"* ]]; then
1945
+ err " Project name looks like a URI or path. Use a short identifier (e.g. 'fitzone')."
1946
+ pause; return
1947
+ fi
1948
+
1949
+ echo
1950
+ dim " Replica name is a label inside the project (e.g. 'master-oracle', 'slave-pg')."
1951
+ name=$(ask "Replica name (label, e.g. 'master-oracle')" "master")
1952
+ if [[ "$name" == *"://"* ]]; then
1953
+ err " Replica name looks like a URI. Use a short label."
1954
+ pause; return
1955
+ fi
1956
+
1939
1957
  role=$(ask "Role (master|slave)" "master")
1940
- dialect=$(ask "Dialect" "${DB_DIALECT:-postgres}")
1941
- uri=$(ask "URI" "${SGBD_URI:-postgres://user:pass@localhost:5432/db}")
1958
+ dialect=$(ask "Dialect (sqlite|postgres|mysql|mongodb|oracle|mssql|mariadb|cockroachdb|db2|hana|hsqldb|spanner|sybase)" "${DB_DIALECT:-postgres}")
1959
+ uri=$(ask "Connection URI" "${SGBD_URI:-postgres://user:pass@localhost:5432/db}")
1942
1960
  if [[ "$role" == "slave" ]]; then
1943
1961
  lag=$(ask "Lag tolerance (ms)" "5000")
1944
1962
  else
1945
1963
  lag="0"
1946
1964
  fi
1947
1965
  _replicator_run "
1966
+ // Auto-register the project in ProjectManager if it's not already there —
1967
+ // addReplica() requires the project to exist. We use the replica's own
1968
+ // dialect/uri as the project config (it's typically the master).
1969
+ const existing = typeof pm.listProjects === 'function' ? pm.listProjects() : [];
1970
+ const known = Array.isArray(existing) && existing.some(p => (p.name ?? p) === '$project');
1971
+ if (!known) {
1972
+ const method = ['addProject','createProject','registerProject'].find(m => typeof pm[m] === 'function');
1973
+ if (method) {
1974
+ await pm[method]({ name: '$project', dialect: '$dialect', uri: '$uri', schemas: [] });
1975
+ console.log(' ✓ project \\'$project\\' registered in ProjectManager');
1976
+ }
1977
+ }
1948
1978
  await rm.addReplica('$project', {
1949
1979
  name: '$name', role: '$role', dialect: '$dialect', uri: '$uri',
1950
1980
  lagTolerance: $lag,
@@ -1955,9 +1985,34 @@ action_rep_add_replica() {
1955
1985
  pause
1956
1986
  }
1957
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
+
1958
2013
  action_rep_list_replicas() {
1959
2014
  local project
1960
- project=$(ask "Project name" "default")
2015
+ project=$(_pick_project)
1961
2016
  _replicator_run "
1962
2017
  const status = rm.getReplicaStatus('$project');
1963
2018
  if (!status || status.length === 0) {
@@ -1973,7 +2028,7 @@ action_rep_list_replicas() {
1973
2028
 
1974
2029
  action_rep_promote() {
1975
2030
  local project name
1976
- project=$(ask "Project name" "default")
2031
+ project=$(_pick_project)
1977
2032
  name=$(ask "Slave to promote" "slave-1")
1978
2033
  if ! confirm "Promote '$name' to master on project '$project'?"; then return; fi
1979
2034
  _replicator_run "
@@ -1986,7 +2041,7 @@ action_rep_promote() {
1986
2041
 
1987
2042
  action_rep_remove_replica() {
1988
2043
  local project name
1989
- project=$(ask "Project name" "default")
2044
+ project=$(_pick_project)
1990
2045
  name=$(ask "Replica name" "slave-1")
1991
2046
  if ! confirm "Remove replica '$name' from project '$project'?"; then return; fi
1992
2047
  _replicator_run "
@@ -1999,7 +2054,7 @@ action_rep_remove_replica() {
1999
2054
 
2000
2055
  action_rep_set_routing() {
2001
2056
  local project strategy
2002
- project=$(ask "Project name" "default")
2057
+ project=$(_pick_project)
2003
2058
  strategy=$(ask "Strategy (round-robin | least-lag | random)" "least-lag")
2004
2059
  _replicator_run "
2005
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.3",
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",