Automatically add new database field from new model field

Posts   
 
    
Posts: 4
Joined: 09-Jan-2025
# Posted on: 09-Jan-2025 10:43:20   

I did a Database First model creation from a Postgres database. As a test, I tried add a new string field to one of the tables. To my surprise, a corresponding new field for the mapped database table was not automatically created. I dug around the settings and the documentation for a significant time but couldn't see how to make this happen. Essentially I'd like to use the model as "Model First" going forward.

Help?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39797
Joined: 17-Aug-2003
# Posted on: 09-Jan-2025 13:30:24   

Please see: https://www.llblgen.com/Documentation/5.11/Designer/Functionality%20Reference/SyncTab.htm Essentially you have to switch the 'source' for the relational model data, which can be done in the sync window as described in the link above.

We don't automatically create fields for new entity fields, you always have to start a sync action. This is done because if you use model first development, it's not always immediately clear what to generate on the relational model side, so we don't do that automatically. Once you're done with the entity model changes, you can then start a sync which will create the relational model data changes and will export a DDL SQL script for you optionally.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 4
Joined: 09-Jan-2025
# Posted on: 09-Jan-2025 22:47:37   

Thanks for the clarification, I got that to work.

Can you elaborate a little on the difference between "mixed" and "model/database"?

Incidentally the documentation search does not work on the local filesystem installed docs, just on your website.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39797
Joined: 17-Aug-2003
# Posted on: 10-Jan-2025 09:26:51   

NewIntellectual wrote:

Thanks for the clarification, I got that to work.

Can you elaborate a little on the difference between "mixed" and "model/database"?

Incidentally the documentation search does not work on the local filesystem installed docs, just on your website.

Search on the locally installed docs is a javascript issue that is caused by browsers not executing the required javascript locally... Firefox did work for a long time but I think that's also not working anymore. For search you have to use the online version.

Mixed means there are database-sourced elements in the relational model data, e.g. views, stored procedures, as these are always sourced from the database system. Model means it's always using the entity model as source, and therefore views/stored procedures can't be added nor are they refreshed when synced. Database means everything, including tables, are sourced from the database.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 4
Joined: 09-Jan-2025
# Posted on: 13-Jan-2025 04:31:27   

As an experiment I added a new test table to my model with three fields (Id, Testlong, Teststring). With the sync settings all at Model, the sync generated the DDL which added the table to my database. Good so far.

Then I deleted Testlong, did code regeneration, and performed a sync again. The sync essentially stated that no changes had occurred. :\

Clearly the sync should recognize the deletion of the Testlong field and generate DDL to do so in the database. It isn't.

Thoughts?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39797
Joined: 17-Aug-2003
# Posted on: 13-Jan-2025 09:20:20   

NewIntellectual wrote:

As an experiment I added a new test table to my model with three fields (Id, Testlong, Teststring). With the sync settings all at Model, the sync generated the DDL which added the table to my database. Good so far.

Then I deleted Testlong, did code regeneration, and performed a sync again. The sync essentially stated that no changes had occurred. :\

Clearly the sync should recognize the deletion of the Testlong field and generate DDL to do so in the database. It isn't.

Thoughts?

It's not, by default. A warning is generated instead by default after the sync (and also by the real time validation). This is configurable in the project settings -> Entity model -> Model First Development -> Validation/Relational mode data adjustment. At the bottom you have 2 settings. A table is excludable from the project, a field isn't (as it belongs to a table and metadata is always obtained for a whole table). If you set the Non-excludable orphaned element detected action to 'Mark for deletion' it's marked for deletion and the DDL SQL script will contain the delete statement.

The warning also contains an action you can click to do this for you on a per element basis if you want to keep this on the default.

Frans Bouma | Lead developer LLBLGen Pro