@mostajs/orm-cli 0.5.10 → 0.5.11
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.
- package/bin/mostajs.sh +62 -4
- package/package.json +1 -1
package/bin/mostajs.sh
CHANGED
|
@@ -1921,13 +1921,57 @@ action_rep_scaffold_services() {
|
|
|
1921
1921
|
fi
|
|
1922
1922
|
fi
|
|
1923
1923
|
|
|
1924
|
+
# Write env vars to .mostajs/config.env (monitor port, replicator interval)
|
|
1925
|
+
echo
|
|
1926
|
+
echo -e "${CYAN}▶ writing config to .mostajs/config.env${RESET}"
|
|
1927
|
+
local config_env="$PROJECT_ROOT/.mostajs/config.env"
|
|
1928
|
+
mkdir -p "$PROJECT_ROOT/.mostajs"
|
|
1929
|
+
|
|
1930
|
+
# Ask for monitor port
|
|
1931
|
+
local mon_port
|
|
1932
|
+
mon_port=$(ask "Monitor dashboard port" "4477")
|
|
1933
|
+
|
|
1934
|
+
# Ask for replicator sync interval
|
|
1935
|
+
local rep_interval
|
|
1936
|
+
rep_interval=$(ask "Replicator sync interval (ms)" "30000")
|
|
1937
|
+
|
|
1938
|
+
# Write/update config.env — preserve existing values, update only ours
|
|
1939
|
+
touch "$config_env"
|
|
1940
|
+
PROJECT="$PROJECT_ROOT" MON_PORT="$mon_port" REP_INT="$rep_interval" node --input-type=module -e "
|
|
1941
|
+
const fs = await import('node:fs');
|
|
1942
|
+
const path = process.env.PROJECT + '/.mostajs/config.env';
|
|
1943
|
+
let content = '';
|
|
1944
|
+
try { content = fs.readFileSync(path, 'utf8'); } catch {}
|
|
1945
|
+
|
|
1946
|
+
const set = (key, val) => {
|
|
1947
|
+
const re = new RegExp('^' + key + '=.*$', 'm');
|
|
1948
|
+
if (re.test(content)) {
|
|
1949
|
+
content = content.replace(re, key + '=' + val);
|
|
1950
|
+
console.log(' • updated ' + key + '=' + val);
|
|
1951
|
+
} else {
|
|
1952
|
+
content += (content && !content.endsWith('\n') ? '\n' : '') + key + '=' + val + '\n';
|
|
1953
|
+
console.log(' ✓ added ' + key + '=' + val);
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
|
|
1957
|
+
set('MONITOR_PORT', process.env.MON_PORT);
|
|
1958
|
+
set('MONITOR_HOST', '127.0.0.1');
|
|
1959
|
+
set('REPLICATOR_INTERVAL_MS', process.env.REP_INT);
|
|
1960
|
+
|
|
1961
|
+
fs.writeFileSync(path, content);
|
|
1962
|
+
" 2>&1 | sed 's/^/ /'
|
|
1963
|
+
|
|
1924
1964
|
echo
|
|
1925
1965
|
echo -e "${BOLD}${GREEN}✓ Scaffold complete.${RESET}"
|
|
1926
1966
|
echo
|
|
1967
|
+
echo -e " ${BOLD}Config written to :${RESET} .mostajs/config.env"
|
|
1968
|
+
echo -e " MONITOR_PORT=${mon_port} REPLICATOR_INTERVAL_MS=${rep_interval}"
|
|
1969
|
+
echo
|
|
1927
1970
|
echo -e " ${BOLD}Next steps :${RESET}"
|
|
1928
1971
|
echo -e " 1. ${CYAN}mostajs${RESET} → menu r → add replicas + CDC rules (writes replicator-tree.json)"
|
|
1929
1972
|
echo -e " 2. ${CYAN}npm run dev:all${RESET} — starts Next + replicator + monitor in parallel"
|
|
1930
1973
|
echo -e " or individually : ${CYAN}npm run replicator${RESET} / ${CYAN}npm run monitor${RESET}"
|
|
1974
|
+
echo -e " 3. Open ${CYAN}http://localhost:${mon_port}${RESET} for the live dashboard"
|
|
1931
1975
|
echo -e " 3. Open ${CYAN}http://localhost:14499${RESET} for the live dashboard"
|
|
1932
1976
|
pause
|
|
1933
1977
|
}
|
|
@@ -2071,10 +2115,24 @@ action_rep_promote() {
|
|
|
2071
2115
|
project=$(_pick_project)
|
|
2072
2116
|
name=$(ask "Slave to promote" "slave-1")
|
|
2073
2117
|
if ! confirm "Promote '$name' to master on project '$project'?"; then return; fi
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2118
|
+
# Direct tree patch — loadFromFile doesn't reconnect replicas, so the
|
|
2119
|
+
# ReplicationManager in-memory approach fails with "no replicas". Promote
|
|
2120
|
+
# is just a role swap in the JSON — no DB connection needed.
|
|
2121
|
+
_tree_patch "
|
|
2122
|
+
const reps = tree.replicas['$project'];
|
|
2123
|
+
if (!reps) { console.log(' ✗ project \"$project\" not found'); return; }
|
|
2124
|
+
if (!reps['$name']) { console.log(' ✗ replica \"$name\" not found in $project'); return; }
|
|
2125
|
+
if (reps['$name'].role === 'master') { console.log(' • $name is already master'); return; }
|
|
2126
|
+
// Demote current master(s) to slave
|
|
2127
|
+
for (const [n, cfg] of Object.entries(reps)) {
|
|
2128
|
+
if (cfg.role === 'master') {
|
|
2129
|
+
cfg.role = 'slave';
|
|
2130
|
+
console.log(' ↓ ' + n + ' demoted to slave');
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
// Promote target to master
|
|
2134
|
+
reps['$name'].role = 'master';
|
|
2135
|
+
console.log(' ★ $name promoted to master');
|
|
2078
2136
|
"
|
|
2079
2137
|
pause
|
|
2080
2138
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mostajs/orm-cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.11",
|
|
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",
|