@mazhu/schemagen
v1.0.0
Published
Database migration CLI - generate schemas from JSON/TypeScript
Maintainers
Readme
schemagen
Database migration CLI - generate schemas from JSON/TypeScript
Installation
npm install -g @mazhu/schemagenUsage
Initialize a new migration project
schemagen init -n my-project
cd my-projectGenerate migration from JSON schema
schemagen generate schemas/my-schema.json -d postgresRun pending migrations
schemagen migrate -d postgresRollback last migration
schemagen rollback -d postgresShow migration status
schemagen status -d postgresSchema Format
{
"users": {
"id": { "type": "uuid", "primaryKey": true },
"email": { "type": "varchar", "length": 255, "unique": true, "notNull": true },
"name": { "type": "varchar", "length": 255 },
"created_at": { "type": "timestamp", "default": "now()" }
},
"posts": {
"id": { "type": "uuid", "primaryKey": true },
"user_id": { "type": "uuid", "references": { "table": "users", "column": "id" } },
"title": { "type": "varchar", "length": 500, "notNull": true },
"content": { "type": "text" },
"published": { "type": "boolean", "default": false },
"created_at": { "type": "timestamp", "default": "now()" },
"updated_at": { "type": "timestamp", "default": "now()" }
}
}Supported Dialects
- PostgreSQL
- MySQL
- SQLite
Configuration
Create a .schemagen/config.json file:
{
"dialect": "postgres",
"migrationsDir": "migrations",
"schemasDir": "schemas",
"connection": {
"host": "localhost",
"port": 5432,
"database": "mydb",
"user": "postgres",
"password": ""
}
}License
MIT
