Pre Fill Database

Hey guys,

Is there any way to prefill the database volume on startup (so whenever someone pulls the Stack off docker) ?
The idea is to have some preconfigured Assets and Rules.
Thanks in advance !

Yes you can create what we call ‘Setup code’. This includes realms, users, assets, and rules.
The easiest way to do this is by using the custom-project template repository. That will have placeholders for this in the files named CustomKeycloakSetup and CustomManagerSetup (custom-project/setup/src/main/java/org/openremote/manager/setup/custom at main · openremote/custom-project · GitHub)
The rules can be added to the resources folder in setup (or anywhere as long as you reference them correctly)

You can also look at how it is done in the openremote repository for the Demo you can find on our website: openremote/setup/src/main/java/org/openremote/setup/demo at master · openremote/openremote · GitHub
Rules can be found here as referenced in RulesDemoSetup: openremote/setup/src/main/resources/demo/rules/smartcity at master · openremote/openremote · GitHub

Hope this helps you implement it. If you have any questions feel free to post them!

Don

1 Like

Thanks Don! that’s really helpful, I must have read the wiki so often that I totally overlooked that feature… :smiley: However, is there a way to export an existing Configuration (made on the platform) and use that as the initial setup ?

Thanks again!

Markus

Sadly, no(t yet) :frowning:

Good luck!

Oh well! still thanks for your fast reply!
have a good one :slight_smile:

(maybe i’ll collaborate and implement it myself when I can find the time)

Okay I found an easy solution for the Problem:

  • In the docker-compose.yml I expose Port 5433
  • I connect via psql/pgadmin/etc. and generate a dump of my Database (which has all the assets in it I created using the openremote platform)
  • I then run docker exec -i <container_name> pg_restore --verbose --clean --no-acl --no-owner -h localhost -U <PG_Username> -d <PG_Databasename> < ./path/to/your/Databasedump.sql
2 Likes