You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instead of running the migration file using Knex and change the DB schema, we should implement the same functions / API exposed by Knex and generate the VSM.
As you can see, the structure is the same as the VSD. It means it is agnostic to the database type. So in the future, we could support other libs like Sequelize or TypeORM.
Diff VSD and VSM and generate the new migrations
Since we have the VSD as the desired state and the VSM as the current state, we can diff them and generate the new migrations.
Once the diff format is generated, we can use the Knex API to generate the migration files.
Conclusion
As far as I know, there is no such tool that does anything similar to what I described above. Been able to change your domain and your database will follow is a game changer.
This is no small task and I bet there are lots of corner cases that would make this task harder than I described above. But I think it is feasible and worth the effort.
Extra Info
There are other issues and efforts related to this topic that I think are worth mentioning:
The reason I suggested this is beacuse it is more generic, works not only with new entities but also with existing ones: if you change a existing entity, it should generate the new migrations.
The text was updated successfully, but these errors were encountered:
Problem
Changing a working software is hard. Especially when it is connected to a database.
Keeping the database schema in sync with the domain is timing consuming and error prone.
Solution
Herbs mantra is to make developers focus on the domain and let the tools handle the infrastructure code.
Herbs DB Migrations should help developers to keep your database schema in sync with your domain in a simple and easy way.
Ex: on
herbs update
it should check if the database schema is in sync with the domain and if not, it should update the database schema.How it should work
The idea is to have a three phase process:
Generate a Virtual Schema from Domain (VSD)
The VSD is a representation of the domain in a database schema. It should be generated from the domain entities.
It should handle the one-to-many and many-to-many relationships. It also should be agnostic to the database type.
Ex:
Should generate something like this:
Generate a Virtual Schema from Migrations (VSM)
The VSM is a representation of the database schema from the migration files. In the example above, it comes from the Knex migration files.
Example of Knex migration files:
Instead of running the migration file using Knex and change the DB schema, we should implement the same functions / API exposed by Knex and generate the VSM.
Should generate something like this:
As you can see, the structure is the same as the VSD. It means it is agnostic to the database type. So in the future, we could support other libs like Sequelize or TypeORM.
Diff VSD and VSM and generate the new migrations
Since we have the VSD as the desired state and the VSM as the current state, we can diff them and generate the new migrations.
There are some libs that can help us to do this diff. Ex: https://github.com/flitbit/diff
Once the diff format is generated, we can use the Knex API to generate the migration files.
Conclusion
As far as I know, there is no such tool that does anything similar to what I described above. Been able to change your domain and your database will follow is a game changer.
This is no small task and I bet there are lots of corner cases that would make this task harder than I described above. But I think it is feasible and worth the effort.
Extra Info
There are other issues and efforts related to this topic that I think are worth mentioning:
herbsjs/herbs-cli#145
The reason I suggested this is beacuse it is more generic, works not only with new entities but also with existing ones: if you change a existing entity, it should generate the new migrations.
The text was updated successfully, but these errors were encountered: