Skip to content

Using custom naming strategy in migrations:generate #1482

Closed

Description

@yoz

Running typeorm migrations:generate generates a migration using the default naming strategy for table and column names. Is it possible to generate the migration using a different naming strategy? I can't find documentation on it.

Activity

  1. added this to the 0.2.0 milestone on Jan 23, 2018
  2. pleerock commented on Jan 23, 2018

    @pleerock
    Member

    no, there is no such possibility yet. You can contribute if you want btw.

  3. yoz commented on Jan 23, 2018

    @yoz
    Author

    Do you think it makes sense to add an ormconfig option that specifies a file to use for naming strategy with a default export? Something like

    "namingStrategy": "dist/some_path/naming_strategy.js" (it would have to point to the tsc-compiled js)

    Alternatively perhaps

    "namingStrategy": {
      "path": "dist/some_path/naming_strategy.js",
      "export": "MyNamingStrategy"
    }
    

    for specifying a different export than the default from naming_strategy.js.

  4. pleerock commented on Jan 31, 2018

    @pleerock
    Member

    yoz we can do that, but wouldn't it be a weird solution?

  5. yoz commented on Jan 31, 2018

    @yoz
    Author

    Yes, it would be unusual to say the least. I'm asking before I start writing code (I'm happy to contribute) in case you have a suggested approach.

  6. pleerock commented on Feb 5, 2018

    @pleerock
    Member

    Alternative approach currently is to manually load file with configuration and append naming strategy. This approach sounds better, maybe we can implement it, since its better and we can't find any better ways yet.

    Do you think its worth to do complicate things and support "export" as well? Maybe simply load default from the provided file?

  7. yoz commented on Feb 5, 2018

    @yoz
    Author

    The default export is fine, I think. It's always possible to use it, even if the naming strategy is not already a default export, by defining a new file like

    import { SomeNamingStrategy } from './some/path';
    export default SomeNamingStrategy;
    
  8. pleerock commented on Feb 5, 2018

    @pleerock
    Member

    correct, even in the same file. So yes, I think you can implement this functionality if you want.

  9. removed this from the 0.2.0 milestone on Mar 12, 2018
  10. yoz commented on Mar 21, 2018

    @yoz
    Author

    It turns out this is possible when using ormconfig.js (https://github.com/typeorm/typeorm/blob/master/docs/using-ormconfig.md#loading-from-ormconfigjs) - we can require() the naming strategy, e.g.

    const SomeNamingStrategy = require('./some/path').SomeNamingStrategy;
    module.exports = {
      ...
      namingStrategy: new SomeNamingStrategy(),
    };
    
  11. yoz commented on Mar 21, 2018

    @yoz
    Author

    I think it's ok to close this.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions