Incomplete generation (model to model, not model to text) - is it possible in MPS? Follow
Example:
I have language L1 (entity model) and language L2 (entity model manipulation). I want to be able to generate new model written in L1 from old model written in L1 and model written in L2. Is it possible to generate model in L1 (not text) using MPS generator?
Also, more general question (problem): does anyone have an approach related to management and maintenance of persistent data scheme using only MPS? Is it even possible? Or should I just let an RDBMS admin to design a scheme and MPS application end user just to translate that scheme into MPS model every time there are any changes?
I have language L1 (entity model) and language L2 (entity model manipulation). I want to be able to generate new model written in L1 from old model written in L1 and model written in L2. Is it possible to generate model in L1 (not text) using MPS generator?
Also, more general question (problem): does anyone have an approach related to management and maintenance of persistent data scheme using only MPS? Is it even possible? Or should I just let an RDBMS admin to design a scheme and MPS application end user just to translate that scheme into MPS model every time there are any changes?
Please sign in to leave a comment.
This is the code, that is executed:
In TextPreviewUtil you can see, that it is possible to tell the generator when to stop:
You can stop the generation before textGen an get the output model.
I actually did that some time ago, but cannot find the code now.
Alternatively, you can always create and modify models using baseLanguage.
My approach to your second problem:
I created a language for modeling the database schema and an SQL language with the ability to simulate the execution against a schema model. This allowed me to write SQL scripts for the incremental changes of my schema. I had a third language for storing schema revisions together with the SQL script to move from one revision to the next. The scripts were validated automatically, if they produce the correct result. For simple cases as adding/removing columns/tables these scripts were generated automatically, but I was always able to manually change the result. So it was a half-automated process.
I generated the database schema from an entities model (as in your case). My final result was an changelog File for LiquiBase that I used to deploy my changes.
The final process after a change of my entities model:
I understood that what I need is not a Generator, but a baseLanguage transformer for my model.
Regarding to your answer on my second problem, do you reference database schema entities in another models? What's happening if you delete column that another rule from another model is referenced to? Do you store revisions only for db schema, or you do this for all models (fragments?)?
I only store revisions of the database schema, because I need to know the state of eventually existing databases that I want to migrate via SQL scripts.
Here MPS make is extended with a model-to-model transformation pre-step.
Models with the name structure_new in languages are converted into pair of models (structure and behavior), which are saved to disk and generated by the main generation step as usual.
1. structure_new is processed only if it is modified and it is in the make scope (or we are rebuilding it)
2. the separate language is used for the transformation
3. output models are merged into existing ones to preserve node ids (and therefore external references are kept alive)
4. output models are marked as modified to be processed by the default generation step
It works pretty well.