How to let CUBA create the DB schema, but skip only the 30.create-table scripts

Hi, in my projects I tend to create a predefined structure of roles and access groups, plus other things that involves writing in system tables.

Dealing with inserts is not a problem, just put them in the 30.create-table scripts and the job is done.

Things get harder when I change some predefined CUBA entities, like the Administrators and Anonymous roles, because in that case I have to either delete first and then insert the new records in the tables (with the added complexity on dealing with FKs) or UPDATE them with WHERE clauses on other fields other than the UUID (that can change from one deploy to another).

But if I could opt-out from executing the 30-create-table scripts of the core CUBA modules (and other add-ons too) except my very own (application) script, I could simply generate a SQL data dump of the entire DB after the first full execution, put this dump in MY 30-create-table script, and then deactivate the other (upper) 30 create scripts…

Is it something that can be achieved with the current framework version (maybe something undocumented, but accessible from code) ?

Thx, P.

Hi Paolo,

I think it could be done if you redefine the cuba_DbUpdater bean (implemented by DbUpdaterImpl) in your application and override its List<ScriptResource> getScripts(ScriptType scriptType, @Nullable String moduleName) method.

But keep in mind that it will work only when the database is initialized by the app server. The Gradle task (and Studio) uses its own copy of this code.

Thanks for the hint @knstvk, I’ll try that in my code.
It’s unfortunate that I cannot use the same trick during development time, but good to know why.

I’ll open another thread in the near future, regarding the problems I see by having critical application logic (especially roles and access groups) in the database.

Thanks for your support,