Skip to content

apolocine/mosta-orm-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@mostajs/orm-cli

Automated migration from Prisma to @mostajs/orm.

npx @mostajs/orm-cli bootstrap scans your Prisma project, rewrites every new PrismaClient(...) site to use the @mostajs/orm-bridge (backing up the originals), installs the runtime, converts your schema, and applies DDL — in one command.

npm version License: AGPL-3.0-or-later

Zero-touch migration

cd my-existing-prisma-app
npx @mostajs/orm-cli bootstrap
npm run dev
# db.User.findMany(...) now runs on any of 13 databases. Zero code change.

That single command does :

  1. Codemod — scans the repo for new PrismaClient(...), detects each export name (prisma, db, client, default), and rewrites each site to createPrismaLikeDb() from @mostajs/orm-bridge. Originals backed up as *.prisma.bak.
  2. Install@mostajs/orm + @mostajs/orm-bridge + @mostajs/orm-adapter + server-only.
  3. Convertprisma/schema.prisma.mostajs/generated/entities.json.
  4. DDL — writes .mostajs/config.env (SQLite defaults) and creates tables.

Every step stops on error (v0.4.1+) so you never see a lying success banner.

To undo :

npx @mostajs/orm-cli install-bridge --restore --apply

Install

Zero-install (recommended)

npx @mostajs/orm-cli bootstrap

Global

npm install -g @mostajs/orm-cli
cd your/project
mostajs bootstrap

Subcommands

Command What it does
mostajs bootstrap Full migration : codemod + install + convert + DDL
mostajs install-bridge Run the codemod (dry-run by default)
mostajs install-bridge --apply Write the codemod changes
mostajs install-bridge --file <path> Restrict to one file
mostajs install-bridge --restore --apply Revert .prisma.bak backups
mostajs convert Auto-detect schema (Prisma / OpenAPI / JSONSchema) and convert
mostajs detect Print what's detected in the project
mostajs health Verify Node / pnpm / schemas / entities.json state
mostajs hash <password> [cost] Bcrypt a password (for seed data)
mostajs verify <password> <hash> Check a password/hash pair
mostajs diagnose [email] [password] Walk through login diagnostics
mostajs help Usage
mostajs version Print version

Interactive menu

cd your/project
mostajs

Detected schemas are listed. Pick :

1) Convert schema → EntitySchema[]
2) Configure database URIs
3) Initialize dialects (connect + create tables)
4) Tests menu (human / mobile / AI agent / curl / playwright)
5) Start services
6) Metrics & status
7) View logs
8) Health checks
9) Generate boilerplate (src/db.ts / .env.example)
s) Seeding (upload / validate / hash / apply)
b) Bootstrap — one-shot Prisma migration
i) Install bridge (codemod)
0) About / Help
q) Quit

The codemod, in detail

mostajs install-bridge is safe by default — dry-run reports what it would change, without touching files :

$ mostajs install-bridge
▶ mostajs install-bridge — scanning /home/me/my-app

Found 3 PrismaClient instantiation site(s):
  → src/lib/db.ts         (const db)
  → src/server/prisma.ts  (const prisma)
  → scripts/seed.ts       (const prisma)

Dry-run — no files written. Re-run with --apply to execute.

Detection rules :

  • Must contain import ... from '@prisma/client' AND new PrismaClient(
  • Files that already use @mostajs/orm-bridge/prisma-client are skipped (idempotent re-runs)
  • Export shape is preserved : const db, const prisma, let client, export default, and const x = ...; export { x }

Replacement format :

// Auto-generated by `mostajs install-bridge` on 2026-04-14T02:03:38Z
// Original file backed up as <this-file>.prisma.bak
// Every db/prisma/client call is now routed to @mostajs/orm (13 dialects).
import { createPrismaLikeDb } from '@mostajs/orm-bridge/prisma-client'

export const db = createPrismaLikeDb()

Supported schemas at input

The CLI auto-detects :

  • Prismaprisma/schema.prisma
  • OpenAPIopenapi.yaml, openapi.json, api.yaml, spec/openapi.yaml, …
  • JSON Schemaschemas/*.json

Conversion goes through @mostajs/orm-adapter (4 adapters).

Supported databases (13)

SQLite · PostgreSQL · MySQL · MariaDB · MongoDB · Oracle · SQL Server · CockroachDB · DB2 · SAP HANA · HSQLDB · Spanner · Sybase

Switch database by editing .mostajs/config.env (or .env) :

DB_DIALECT=postgres
SGBD_URI=postgres://user:pass@host:5432/mydb

Then re-run mostajs → menu 3 (init DDL) → menu S → 4 (apply seeds). Same code.

Project layout

your-project/
├── prisma/schema.prisma            # unchanged
├── src/lib/db.ts                   # 3 lines now (createPrismaLikeDb)
├── src/lib/db.ts.prisma.bak        # original, in case you want to revert
└── .mostajs/
    ├── config.env                  # DB_DIALECT, SGBD_URI, DB_SCHEMA_STRATEGY
    ├── generated/entities.json     # converted schema (13-DB-ready)
    ├── seeds/*.json                # one per entity, hashed by menu S → h
    └── logs/                       # convert / init / seed / dev

Example — FitZoneGym

FitZoneGym (production-grade Next.js 15 + Prisma, 40 models, 67 files importing Prisma) was migrated end-to-end with :

cd FitZoneGym
npx @mostajs/orm-cli bootstrap        # 15 PrismaClient sites rewritten, schema converted, DDL applied
# manually : add seeds to .mostajs/seeds/User.json
# manually : mostajs — menu S → h → 4
npm run dev                           # login alice@example.com / alice123  → 302 + session

Files modified by the user : 0 (codemod owned them all). Login, dashboard, API routes all work on SQLite instead of MongoDB.

License

AGPL-3.0-or-later + commercial license available.

For closed-source commercial use : drmdh@msn.com

Ecosystem

Author

Dr Hamid MADANI drmdh@msn.com

About

Universal CLI for @mostajs/orm — auto-detects Prisma/OpenAPI/JSON Schema, converts to EntitySchema, tests with humans/mobiles/AI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors