Registry / database / mikro-orm-pg-migration-generator

mikro-orm-pg-migration-generator

JSON →
library0.1.6jsnpmunverified

A MikroORM migration generator extension that automatically creates PostgreSQL triggers and functions to manage `updated_at` column updates, compensating for PostgreSQL's lack of native ON UPDATE CURRENT_TIMESTAMP support. Version 0.1.6 integrates with `@mikro-orm/migrations` ^6.5.6 and supports PostgreSQL 13-17. Unlike `onUpdate` in MikroORM entities, this ensures `updated_at` is updated even when using query builders or raw SQL. It generates full up/down migration scripts with customizable column names, types, function/trigger naming, and SQL. Designed for projects that need reliable `updated_at` behavior outside ORM-managed code.

npm install mikro-orm-pg-migration-generator
INSTALL
IMPORT
SIG · MIKRO-ORM-PG-MIGRA
M
mikro-orm-pg-migration-generator
databasejavascriptv0.1.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createMigrationGeneratorClass
import { createMigrationGeneratorClass } from 'mikro-orm-pg-migration-generator'
import createMigrationGeneratorClass from 'mikro-orm-pg-migration-generator'
ESM default export not provided; use named export.

Configures MikroORM to use the migration generator with default options.

import { defineConfig } from "@mikro-orm/postgresql"; import { createMigrationGeneratorClass } from "mikro-orm-pg-migration-generator"; export default defineConfig({ migrations: { generator: createMigrationGeneratorClass() }, entities: ["dist/**/*.entity.js"], });
Debug
Known issues
breakingRequires @mikro-orm/migrations v6.5.6 or compatible
fix
Ensure package.json contains @mikro-orm/migrations@^6.5.6
affects: >=0.1.0
gotchaOnly works with PostgreSQL; not compatible with other databases.
fix
Use only in PostgreSQL projects.
affects: >=0.1.0
gotchaCustom columnNameMatcher, columnTypeMatcher, and SQL factories must return correct PostgreSQL syntax or parser may fail.
fix
Ensure custom factories produce valid PL/pgSQL and valid trigger/function definitions.
affects: >=0.1.0
gotchaFunction and trigger names must be unique per table/column combination to avoid conflicts.
fix
Customize functionNameFactory and triggerNameFactory to avoid collisions if multiple tables have updated_at columns.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'mikro-orm-pg-migration-generator'
Package not installed or missing from node_modules.
fix
Run 'npm install mikro-orm-pg-migration-generator' (or pnpm/yarn equivalent).
Property 'generator' does not match the schema for migrations config
Invalid TypeScript type for migrations.generator.
fix
Use 'createMigrationGeneratorClass()' (a function that returns a class, not a class directly).
Upgrade
Version history
0.1.6latest on npm
Audit
Dependencies
@mikro-orm/migrationsrequiredRequired peer dependency; the generator creates Migration classes that extend MikroORM's Migration base class.
Agent activity
12 hits · last 30 days
node
10
Resources
mikro-orm-pg-migration-generator — npm install mikro-orm-pg-migration-generator · libregistry