Improved flexibility in database initialization

I’m running into the following issue. My data model has a bunch of entities and user’s can only access some of them. I want to do fine-grained permissions for each entity. So each non-admin user should not be able to access any of the 8 default fields (e.g. id, version, create_ts…).

In my startup script 30.create-db.sql I have to have 4 inserts for entity level permissions 8 inserts for default fields and 1-10 inserts for actual entity fields the user should or should not have access to.

This creates a real mess in 30.create-db.sql, especially if I add or remove a field and then have to remember to go in and add or remove permissions.

This is still in the early development phase of the data model and application.

It would be helpful to be able to have an arbitrary number of 30.create-db.sql (each named differently of course) for specific permissions for each table and one for each lookup table that needs to be initialized (which can have thousands of additional rows), sort of like you allow an arbitrary number of update scripts.

I played around with moving a lot of the stuff from 30.create-db.sql to the earliest update scripts, one for each table, but am having difficulties making it work. When I create the database, it says it applies all the update scripts but I don’t actually see them applied in the DB. It could be that this is another manifestation of the problem I reported yesterday (https://www.cuba-platform.com/discuss/t/run-menu-update-database-doesnt-generate-db-scripts) in which case the capability basically already exists. But I haven’t been able to get it working with 6.4.0.

Hi,

you can just any number of update scripts you like. Just call it 40.create-entity-a-entries, 50.-… etc. They will get picked up during db Migration…

Bye

2 Likes

Thx a lot Mario. Didn’t realize that.

you can also consider using JSON as the way to import test & seed data. I wrote a blog post a couple of weeks ago about this topic: https://www.road-to-cuba-and-beyond.com/test-and-seed-data/

Bye
Mario

1 Like

Mario - Am still running into a problem –

I initially had my 40 and above initialization scripts in the init folder but it doesn’t pick them up when creating the DB, it just runs 10,20,30.

I put the 40 and above scripts in the update folder and it ran fine the first time. However, when I re-create the DB, these scripts have already been applied and don’t seem to get run again on the new database? I’ve tried cleaning and deleting the build folder but these update scripts are still seen as applied and don’t get run again.

What am I doing wrong?

Finally figured it out. The scripts in the init folder do get picked up but the file name has to end in exactly create-db.sql.

So 40.create-entity-a-entries-create-db.sql does work whereas 40.create-entity-a-entries.sql does not.

1 Like