Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not (exclusively) rely on class name to execute migration steps (e.g. use decorator instead) #2549

Closed
dominic-simplan opened this issue Jul 20, 2018 · 2 comments

Comments

@dominic-simplan
Copy link

Issue type:

[ ] question
[ ] bug report
[x] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[x] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Currently migrations seem to rely on the class name to execute migrations correctly. This causes issues if the mangle option of UglifyJS is enabled, as the class names are mangled. Wouldn't it be possible to use a decorator to define the timestamp instead? E.g:

@Migration(1529582677992)
export class InitialTables implements MigrationInterface {
}

As a workaround I currently pass the migration class names to the reserved option of UglifyJS, which is quite error-prone in the long run:

mangle: {
    reserved: ["InitialTables1529582677992", "AddForeignKeys1529588981853", "AddTable1531748224253"]
}
@pleerock
Copy link
Member

I would like to avoid using another decorator. What we can do is to add extra optional properties into MigrationInterface that users can implement and use for custom migration name. Feel free to contribute!

@liangchunn
Copy link

I've hit a similar issue with normal relations as well (webpack build).

When EntityMetadataValidator.validateDependencies() is executed in a mangled file, it can happen that there are duplicate identifiers for a particular class as a result of the Function.prototype.name call

  entityMetadatas.forEach(entityMetadata => {
    graph.addNode(entityMetadata.name);
+   console.log(entityMetadata.name)
  });

With keep_fnames: false with terser/uglify,

p
u
d  <--
c
l
y
d  <--
(node:31945) UnhandledPromiseRejectionWarning: 
CircularRelationsError: Circular relations detected: p -> d -> d. 
...

Using keep_fnames: true fixes this and no error is thrown:

UserSpace
Space
Comment
Reaction
PostReaction
Post
User

If a webpack build is being managed by another tool (like create-react-app), it might be almost impossible to override terser's/uglifyjs's configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants