Create DB for installed component

Hello. I created a little app-extension, which requires DB to work. Now I want it to be a part of my bigger app.
How could i make it create DB automatically as i install app component?
How could i share it to a proxy maven repository, and make it create DB as I build projects with it?
How could i make it more flexible, so it could work with different database types (and select it automatically)?

How could i make it create DB automatically as i install app component?

If you mean creating the database schema for entities provided by the component - just create DB init/update scripts as you do in an application, and these scripts will be incorporated into the app using the component.

How could i share it to a proxy maven repository, and make it create DB as I build projects with it?

See “Sharing the Customer Management component” section here.

How could i make it more flexible, so it could work with different database types (and select it automatically)?

Just make scripts for all databases that you want to support. The app will execute appropriate scripts depending on the selected DB type. Also, since 6.7, Studio generates scripts for components of the app, even if they are not provided by the component.

If you’re a docker user, take a look at this folder in one of my components: https://github.com/pfurini/cuba-component-forgot-password/tree/master/docker

There I created one small shell (bash) script to start and stop appropriate docker containers to be able to generate DB scripts for every major RDBMS supported by CUBA. Just substitute the name of containers and the DB name to reflect your component’s name, or alternatively just use “generic” ones to be able to reuse the scripts in all of your apps/components.

Paolo

1 Like

ADDENDUM to my previous comment, so that can help future users that read this post:

You can easily add a bunch of Gradle tasks in your extra.gradle file to ease the starting and stopping of various docker container, so you don’t have to leave Studio or IDEA to launch them:

1 Like