The general case: Let's say you have an entity Appuser with a field streetaddress and you create the jhipster app. It works, database is created, but you realize that you also need the postalcode. So you modified all the pieces you need, but the field is not created in your database. How am I missing?
Actually, I added a new relationship to an existing entity and I did modified:
modified: src/main/java/com/spingular/web/domain/Blog.java
modified: src/main/java/com/spingular/web/service/BlogQueryService.java
modified: src/main/java/com/spingular/web/service/dto/BlogCriteria.java
modified: src/main/java/com/spingular/web/service/dto/BlogDTO.java
modified: src/main/java/com/spingular/web/service/mapper/BlogMapper.java
modified: src/main/java/com/spingular/web/web/rest/BlogResource.java
modified: src/main/resources/.h2.server.properties
I drop the database and create a new one but the new relationship is not there. What am I missing here?
If you have any documentation, great. Thanks.
Related
I am trying out JHipster (version 6.4.1) using a Monolith and disk-based H2 database. I have created some entities in JDL and have the basic CRUD webpages working. Now that I feel comfortable with the process, I want to add fields and rename others. I figured I could simply update the JDL, re-import the JDL, start the application, and see the result of my changes. What I see is ValidationFailedException from Liquibase and the application throwing HTTP 500 errors due to database problems.
I have looked all over for guidance on the proper process for handling this seemingly common development scenario. Most of the places I have looked for guidance (such as https://www.jhipster.tech/creating-an-entity) discuss importing JDL as a one-time-only operation and do not discuss how to incrementally change and import the JDL.
I have tried a number of suggestions as seen on SO, such as not overwriting the changelogs, doing a liquibase:diff, and adding that to master.xml. This still causes the ValidationFailedException. In the master.xml I see the comment <!-- jhipster-needle-liquibase-add-changelog - JHipster will add liquibase changelogs here --> which leads me to believe that JHipster should be doing the heavy lifting, but I am just missing a step.
I am by no means a JHipster nor a Liquibase expert, but I want to learn. How I can perform simple entity updates without a huge hassle?
[Update with more detail]
After re-importing the updated JDL, I have managed to get rid of the DB Validation Errors by blowing away the database with rm -rf target/h2db/db.
I'm happy with my changes and feel like a commit is in order. What I see is
master.xml is unchanged
the changelog from the first JDL import has been modified to include the updates I made
If I understand how liquibase works, I would have expected
None of the existing changelogs would be touched
A brand new changelog file would be created that contained just the JDL changes I made this round
master.xml to have changed only in that it would contain an additional changelog entry, pointing to the file created in item 2
Am I misinterpreting how Liquibase represents evolution of the DB schema?
It appears that the page you referenced does have some instructions for updating entities. Farther down the page I saw this:
Updating an existing entity
The entity configuration is saved in a
specific .json file, in the .jhipster directory. So if you run the
sub-generator again, using an existing entity name, you can update or
regenerate the entity.
When you run the entity sub-generator for an existing entity, you will
be asked a question ‘Do you want to update the entity? This will
replace the existing files for this entity, all your custom code will
be overwritten’ with following options:
Yes, re generate the entity - This will just regenerate your entity.
Tip: This can be forced by passing a --regenerate flag when running
the sub-generator
Yes, add more fields and relationships - This will
give you questions to add more fields and relationships
Yes, remove fields and relationships - This will give you questions to remove
existing fields and relationships from the entity
No, exit - This will exit the sub-generator without changing anything
You might want to
update your entity for the following reasons:
You want to add/remove fields and relationships to an existing entity
You want to reset your entity code to its original state
You have updated JHipster, and would like to have your entity generated with
the new templates
You have modified the .json configuration file (the
format is quite close to the questions asked by the generator, so it’s
not very complicated), so you can have a new version of your entity
You have copy/pasted the .json file, and want a new entity that is
very close to the copied entity
Let's say I have a business network v1.0.0 which has a Participant with the following model:
participant Member identified by memberId {
o String memberId
o String firstName
}
After deploying the network I create a Member.
Later I want to add a field to the Member model. E.g.
participant Member identified by memberId {
o String memberId
o String firstName
o String lastName
}
So I create new network and upgrade the previous one:
composer network upgrade -c peeradmin#hlfv1 -n example-netowrk -V 2.0.0
What happens to the member I created before? Is it deleted? How can I keep that in the system and continue to use it and update it's information by only adding lastName?
The evolution of model definitions is described in the documentation here
https://hyperledger.github.io/composer/latest/reference/model-compatibility and should answer your question.
when you change the model, your api will change as well to reflect the changes. Your data won't disappear, it can't as it's on the ledger, but it won't have the new fields you added.
Once your new model is deployed you can then issue a GET request to that asset, this gives you all the existing data, you populate the new field with whatever you need and issue a PUT request on that asset. This will now give you an old asset with the new data.
Of course, I suggest you think carefully how you change existing assets. I am thinking here of a policy which says you should not rename anything, you should not delete anything. all you should do is add new properties. If you start messing around with renaming and deleting, this is bound to cause issue, especially in a production environment.
I'm working on a project based on Jhipster,and i will update update user entity; i will add external field to user entity for example add birthday field to my user entity.
how i can do it?
thanks
There's nothing in JHipster to help you doing so.
It's up to you to modify the generated code for your needs:
add your field to the User entity and UserDTO
create a new Liquibase changelog to add a new column in user table
modify html form and controller
I made the mistake of designing a scheme so that I have two collections where one has documents which contain a manual reference to the other. I realized now that I should have created it so that the parent collection contained the other collection as sub-documents instead.
The problem is, I've already put this scheme out into a production environment where hundreds of entries have already been created. What I'd like to do is somehow scan over all of the existing data, and copy the items to their referenced parent_id as a sub-document.
Here is an example of my schema:
Collection 1 - User
_id
Name
Collection 2 - Photos
_id
url
user_id
Is there a quick way to change the existing documents to be one collection like this:
Collection - User
_id
Name
Photos: [...]
Once I have the database setup correctly, I can easily modify my code to use the new one, but the problem I'm having is figuring out how to quickly/procedural copy the documents to their parent.
Additional detail - I'm using MongoHQ.com to host my MongoDB.
Thank You.
I don't know the specifics of your environment, but this sort of change usually involves the following kinds of steps:
Ensure that your old code doesn't complain if there is a Photos array in the User object.
"Freeze" the application so that new User and Photo documents are not created
Run a migration script that copies the Photo documents into the User documents. This should be pretty easy to create either in javaScript or through app code using the driver (see example below)
Deploy the new version of the application that expects Photos to be embedded in the array
"Unfreeze" the application to start creating new documents
If you cannot "Freeze/Unfreeze" you will need to run a delta script after step 4 that will migrate newly created Photo documents after the new application is deployed.
The script will look something like this (untested):
db.User.find().forEach(function (u) {
u.Photos = new Array();
db.Photo.find({user_id : u._id}).forEach(function (p) {
u.Photos.push(p);
}
db.User.Save(u);
}
I have an application that uses CoreData.
I previously had a class named Marker which was linked to the Marker entity in Core Data.
I renamed the Marker class to CoreDataMarker. So I created a new .xcdatamodel file with the new class name for the entity. Then I created a .xcmappingmodel and selected the old and the new .xcdatamodel files and it seemed to 'auto-setup' fine.
However, when I run my application it complains with: "Can't merge models with two different entities named 'Marker'". I understand that this happens, but I have no idea how to solve it.
Do you know how?
Thanks in advance!
You don't need a new xcdatamodel. Change the in the "Class" field in the entity description for your Marker entity to CoreDataMarker. That's all that's needed. The implementing class information does not require a schema migration.
And make sure ONLY the current version of the data model (latest xcdatamodel file) is included in target and mapping model file. It looks like putting other model files are being done automatically based on information from xcmappingmodel file.
It is unintuitive but this was what worked for me.