@mostajs/orm-cli 0.6.0 → 0.6.1
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 +86 -6
- package/package.json +1 -1
package/bin/mostajs.sh
CHANGED
|
@@ -579,10 +579,10 @@ menu_install_bridge() {
|
|
|
579
579
|
header
|
|
580
580
|
echo -e "${BOLD}${MAGENTA}▶ Install bridge — PrismaClient codemod${RESET}"
|
|
581
581
|
echo
|
|
582
|
-
echo " ${CYAN}1${RESET}) Dry-run : list files that would be rewritten (default)"
|
|
583
|
-
echo " ${CYAN}2${RESET}) Apply : rewrite PrismaClient sites to createPrismaLikeDb()"
|
|
584
|
-
echo " ${CYAN}3${RESET}) Restore : revert .prisma.bak files (dry-run)"
|
|
585
|
-
echo " ${CYAN}4${RESET}) Restore : revert .prisma.bak files (apply)"
|
|
582
|
+
echo -e " ${CYAN}1${RESET}) Dry-run : list files that would be rewritten (default)"
|
|
583
|
+
echo -e " ${CYAN}2${RESET}) Apply : rewrite PrismaClient sites to createPrismaLikeDb()"
|
|
584
|
+
echo -e " ${CYAN}3${RESET}) Restore : revert .prisma.bak files (dry-run)"
|
|
585
|
+
echo -e " ${CYAN}4${RESET}) Restore : revert .prisma.bak files (apply)"
|
|
586
586
|
echo " ${RED}0${RESET}) Back"
|
|
587
587
|
echo
|
|
588
588
|
local cli_dir
|
|
@@ -4075,9 +4075,10 @@ CFG
|
|
|
4075
4075
|
echo -e " How do you want to populate them?"
|
|
4076
4076
|
echo
|
|
4077
4077
|
echo -e " ${CYAN}1${RESET}) Apply seed files ${DIM}(.mostajs/seeds/*.json → mostajs seed)${RESET}"
|
|
4078
|
-
echo -e " ${CYAN}2${RESET}) Replicate from old DB ${DIM}(old Prisma DB = master → new DB = slave)${RESET}"
|
|
4078
|
+
echo -e " ${CYAN}2${RESET}) Replicate from old DB ${DIM}(old Prisma DB = master → new DB = slave, continuous)${RESET}"
|
|
4079
4079
|
echo -e " ${CYAN}3${RESET}) Start with empty tables ${DIM}(app handles its own data)${RESET}"
|
|
4080
|
-
echo -e " ${CYAN}4${RESET}) Auto-replicate old → new ${DIM}(
|
|
4080
|
+
echo -e " ${CYAN}4${RESET}) Auto-replicate old → new ${DIM}(one-shot snapshot + scaffold replicator)${RESET}"
|
|
4081
|
+
echo -e " ${CYAN}5${RESET}) Simple data copy ${DIM}(one-shot copy, no replicator setup)${RESET}"
|
|
4081
4082
|
echo
|
|
4082
4083
|
local dm_choice
|
|
4083
4084
|
dm_choice=$(ask "Choice" "3")
|
|
@@ -4089,6 +4090,85 @@ CFG
|
|
|
4089
4090
|
3)
|
|
4090
4091
|
ok " Empty tables — ready for your app to populate."
|
|
4091
4092
|
;;
|
|
4093
|
+
5)
|
|
4094
|
+
# ─── Simple one-shot data copy (no replicator) ───
|
|
4095
|
+
echo
|
|
4096
|
+
echo -e "${BOLD}▶ Simple data copy : old DB → new DB${RESET}"
|
|
4097
|
+
|
|
4098
|
+
local old_uri_simple=""
|
|
4099
|
+
if [[ -f "$PROJECT_ROOT/.env" ]]; then
|
|
4100
|
+
old_uri_simple=$(grep -E '^DATABASE_URL=' "$PROJECT_ROOT/.env" 2>/dev/null | head -1 | sed 's/^DATABASE_URL=//' | tr -d '"' | tr -d "'")
|
|
4101
|
+
fi
|
|
4102
|
+
if [[ -z "$old_uri_simple" ]]; then
|
|
4103
|
+
old_uri_simple=$(ask "Old DATABASE_URL (source)" "postgresql://user:pass@localhost:5432/olddb")
|
|
4104
|
+
else
|
|
4105
|
+
info " Detected old DATABASE_URL : ${old_uri_simple:0:50}..."
|
|
4106
|
+
if ! confirm "Use this as source?"; then
|
|
4107
|
+
old_uri_simple=$(ask "Old DATABASE_URL" "$old_uri_simple")
|
|
4108
|
+
fi
|
|
4109
|
+
fi
|
|
4110
|
+
|
|
4111
|
+
local old_d_simple="postgres"
|
|
4112
|
+
case "$old_uri_simple" in
|
|
4113
|
+
postgresql://*|postgres://*) old_d_simple="postgres" ;;
|
|
4114
|
+
mysql://*) old_d_simple="mysql" ;;
|
|
4115
|
+
mongodb://*) old_d_simple="mongodb" ;;
|
|
4116
|
+
mariadb://*) old_d_simple="mariadb" ;;
|
|
4117
|
+
oracle://*) old_d_simple="oracle" ;;
|
|
4118
|
+
mssql://*) old_d_simple="mssql" ;;
|
|
4119
|
+
*sqlite*|*.db|*.sqlite) old_d_simple="sqlite" ;;
|
|
4120
|
+
esac
|
|
4121
|
+
|
|
4122
|
+
echo
|
|
4123
|
+
info " Source : $old_d_simple → Target : $DB_DIALECT"
|
|
4124
|
+
info " Copying data (one-shot, no replicator setup)..."
|
|
4125
|
+
|
|
4126
|
+
RUNTIME_ROOT="$PROJECT_ROOT" OLD_URI="$old_uri_simple" OLD_DIALECT="$old_d_simple" \
|
|
4127
|
+
NEW_URI="$SGBD_URI" NEW_DIALECT="$DB_DIALECT" \
|
|
4128
|
+
node --input-type=module -e "
|
|
4129
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
4130
|
+
import { resolve } from 'node:path';
|
|
4131
|
+
|
|
4132
|
+
const orm = await import(resolve(process.env.RUNTIME_ROOT, 'node_modules/@mostajs/orm/dist/index.js'));
|
|
4133
|
+
|
|
4134
|
+
const entPath = resolve(process.env.RUNTIME_ROOT, '.mostajs/generated/entities.json');
|
|
4135
|
+
const schemas = existsSync(entPath) ? JSON.parse(readFileSync(entPath, 'utf8')) : [];
|
|
4136
|
+
orm.registerSchemas(schemas);
|
|
4137
|
+
|
|
4138
|
+
const src = await orm.createIsolatedDialect(
|
|
4139
|
+
{ dialect: process.env.OLD_DIALECT, uri: process.env.OLD_URI, schemaStrategy: 'none' }, schemas);
|
|
4140
|
+
const dst = await orm.createIsolatedDialect(
|
|
4141
|
+
{ dialect: process.env.NEW_DIALECT, uri: process.env.NEW_URI, schemaStrategy: 'update' }, schemas);
|
|
4142
|
+
await dst.initSchema(schemas);
|
|
4143
|
+
|
|
4144
|
+
let totalCopied = 0, totalErrors = 0;
|
|
4145
|
+
for (const schema of schemas) {
|
|
4146
|
+
try {
|
|
4147
|
+
const rows = await src.find(schema, {});
|
|
4148
|
+
let copied = 0, errors = 0;
|
|
4149
|
+
for (const row of rows) {
|
|
4150
|
+
try {
|
|
4151
|
+
const { createdAt, updatedAt, ...data } = row;
|
|
4152
|
+
await dst.create(schema, data);
|
|
4153
|
+
copied++;
|
|
4154
|
+
} catch (e) {
|
|
4155
|
+
errors++;
|
|
4156
|
+
}
|
|
4157
|
+
}
|
|
4158
|
+
console.log(' ' + schema.name + ' : ' + copied + ' copied, ' + errors + ' errors');
|
|
4159
|
+
totalCopied += copied;
|
|
4160
|
+
totalErrors += errors;
|
|
4161
|
+
} catch (e) {
|
|
4162
|
+
console.log(' ' + schema.name + ' : ERROR ' + e.message.slice(0,80));
|
|
4163
|
+
totalErrors++;
|
|
4164
|
+
}
|
|
4165
|
+
}
|
|
4166
|
+
console.log('');
|
|
4167
|
+
console.log(' Total : ' + totalCopied + ' records copied, ' + totalErrors + ' errors');
|
|
4168
|
+
await src.disconnect();
|
|
4169
|
+
await dst.disconnect();
|
|
4170
|
+
" 2>&1 | sed 's/^/ /'
|
|
4171
|
+
;;
|
|
4092
4172
|
2|4)
|
|
4093
4173
|
# ─── Replication from old DB ───
|
|
4094
4174
|
echo
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mostajs/orm-cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
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",
|