grumpyTofu / nx-mongo-migrate

database migrations for mongoose & mongodb
0 stars 2 forks source link

Cannot find module project/migration.config #2

Closed erbilsilik closed 1 year ago

erbilsilik commented 1 year ago

Describe the bug Cannot find module project/migration.config when running migration commands, e.g npx nx run projection:migrate-up

To Reproduce Followed the steps from Readme file

Current Output Cannot find module project/migration.config

Expected behavior To be able run the migration commands successfully

Environment (please complete the following information):

Additional context

grumpyTofu commented 1 year ago

Hi @erbilsilik,

Firstly, thank you for trying out this library!

EDIT: Can you clarify if "project" in "project/migration.confg" is the root of your nx repo, or if it is a specific app or lib?

As an additional note: I have just added an example project for usage reference in this repo to the packages/example folder along with some modifications to the executors. Can you please try to upgrade to version 0.0.5 and try again?

erbilsilik commented 1 year ago

Hi @grumpyTofu

Thanks for the example. It is on the root directory. It generates on the root directory, but I don't understand why?

grumpyTofu commented 1 year ago

Great question! It is currently designed this way because it is possible to have multiple apps/libs inside of one Nx monorepo, each responsible for managing different schemas & migrations. I would actually recommend this kind of pattern because it makes your code more maintainable in the long term and keeping all of your migrations scripts in one project can become overwhelming over time. However, most apps will still likely connect to the same database so there isn't much of a need for a project specific db config.

I hope that helps answer your question. Please let me know if you are still having issues with the latest version, or if you think there is a way that the library would need to be modified to fit your specific use case.

erbilsilik commented 1 year ago

Thank you for the explanation.

My question was solely related to the migration.config. As you have already mentioned, Nx is designed to accommodate multiple apps/libs. This implies that each app/service should have its own migration.config in order to adhere to best practices. Without individual configuration files for each app/service, it would not be considered best practice (see: https://microservices.io/patterns/data/database-per-service.html)

Unfortunately, I cannot use this version of the library where only one database is supported.

grumpyTofu commented 1 year ago

That is a really cool pattern example you have provided. I don't know if everyone will follow this pattern, but if this is the architecture pattern that you are looking to follow, then it sounds like you have a need for a project specific migration config. I don't think it would require a huge change in this library to incorporate that.

I would like this library to follow a similar pattern to how Nx handles other configuration files such as .env, eslintrc, tsconfig files, etc. For those, you can have a global configuration for all apps, but also a project configuration that either replaces, or partially overrides the global config. This will keep the configuration as DRY as possible but allow for maximum customization.

How would you expect that the project specific configuration behaves?

erbilsilik commented 1 year ago

Yes, actually it depends on the usage of Nx. If Nx is used for creating microservices, we need a database-per-service approach. However, if it's more like a modular monolith, there is no need for it. Considering this, I would prefer the first approach, as it allows for both.

If you have a project level migration.config exists, then the library would only read from the project level migration.config and ignore the global migration.config file, if it exists?

grumpyTofu commented 1 year ago

Sounds great! I think this should be a relatively easy change to make. Are you looking to make that contribution yourself?

erbilsilik commented 1 year ago

Sounds great! I think this should be a relatively easy change to make. Are you looking to make that contribution yourself?

Sure, I will. 👍