fix: preserve class names in production builds for TypeORM migrations#781
fix: preserve class names in production builds for TypeORM migrations#781f1sherman wants to merge 1 commit intoBlueBubblesApp:developmentfrom
Conversation
Webpack's Terser minification mangles class names in production builds, which breaks TypeORM's migration runner — it parses the timestamp from the class name to determine migration identity and ordering. Configure Terser with keep_classnames: true to prevent this. The bug hasn't surfaced before because existing installs either use synchronize (fresh install) or have no pending migrations (subsequent launches). It only triggers when a new migration is added and the app is upgraded on a machine with an existing config.db.
|
I ran into this bug while testing #780. Let me know if I did something wrong, thank you! |
|
Thanks for the contribution! Just FYI, I'm not ignoring this by any means. My priorities are with the Android/Desktop app complete rewrite and this is next on my list. The rewrite is going well, but it's a lot of refactors and migrations, so it may take some time. I plan to do a beta/alpha in the near future. But just don't think this is being ignored. It's not! |
|
@zlshames sounds great, thanks so much! Just let me know if I need to change anything due to the re-write. |
|
Any way this PR can be merged for the current version @zlshames ? |
Is there a high urgency to it? I'm currently spending all my time working on the App rewrite. It's almost done, I'm just ironing out a few things before releasing a beta for it. Then I plan to work on all of the PRs and other work items for the server |
Summary
Fix a latent bug where TypeORM migrations fail in production builds due to webpack's Terser minification mangling class names.
Problem
TypeORM's
MigrationExecutorparses the timestamp from migration class names at runtime (e.g.,WebhookChatGuids1710720000000→ timestamp1710720000000). In production builds, webpack's default Terser config minifies class names (e.g.,ei), causing TypeORM to throw:The server hangs at "Initializing server database..." and never starts.
Why it hasn't been noticed
The existing release builds have the same minification behavior, but it doesn't surface because:
config.dbdoesn't exist, soshouldSync = true, which setsmigrationsRun: false— TypeORM usessynchronize: trueinstead of running migrations.The bug only triggers when a new migration is added and the app is upgraded on a machine that already has
config.db.Fix
Configure Terser to preserve class names in
webpack.main.prod.config.js:terser-webpack-pluginis already available as a transitive dependency of webpack 5 — no new dependencies needed. Bundle size impact is minimal.Alternatives considered
keep_classnames(migration files only): Terser doesn't support per-file class name preservation without a more complex setupoptimization.minimize: false: Fixes the issue but disables all minificationnameproperty on migration classes: TypeORM checks the class name, not anameproperty, for timestamp parsing