Best strategy to import existing data

What is the best strategy to import existing data - i.e., csv/excel in my Cuba entities?

  1. Directly in the database
  • Connected to my Cuba app DB with SqlSquirrel, I tried using the Import Data plugin, but do not now how to generate the long ID attribute.
  1. From the Cuba App
  • There is a button to Export to Excel. Anything already available to Import, or would I need to build that myself?

Thanks!

4 Likes

Hi Matthis,

There are no import facilities in CUBA yet, except the Generate model feature in Studio. You can use it if you want to create CUBA entities right from existing tables in your database.

If you want to create the database from scratch and just import some data, you have to do it directly in the database or write some code in your project.

Regarding Long ID - depending on the DBMS type, the long identifiers are generated from sequences (PostgreSQL, Oracle, MS SQL 2012+) or special tables with identity fields (MS SQL <2012, MySQL). So you can generate the records and then manually modify the current values of corresponding sequences (create a couple of entities through the standard UI and you will see what sequences are created - they start with “seq_id_”).
If you use entities with UUID keys, the things are much easier - there is newid() function for every database, which you can use to generate primary keys.

By the way, if you have data in CSV, there is a simple Excel trick that allows you to create SQL INSERT statements from your data. Look at the screenshots: you just create some columns with SQL parts around your data columns, and when you copy the range of cells as text, you get valid SQL.

As for more complex import when you need to insert data from several related tables, you can create a JMX-bean in your application, which will read data from a source, create entities and save them to the database. This is the usual practice for implementing migrations.

Image 1

Image 2

1 Like

Hi Konstantin,

Thank you for your detailed reply.
Best regards,

Matthis