Migrations
Migrations
The platform provides a way to create migrations.
For this, we need to create a class annotated with @DataChangeSet
that implements CeapDataChangeSet
Bellow a litle example.
@DataChangeSet(id = "0001-01", author = "john", description = "Update the products name")
public class ProductNameChangeSet implements CeapDataChangeSet {
@Inject
private ProductManager productManager;
@Override
public void execute() {
List<Product> productList = productManager.getAll();
for (Product product : productList) {
product.setName("New Name");
productManager.save(product);
}
}
}
Migration XLS
Sometimes we need to handle a large volume of data.
The way to do this quickly is through xls files.
For do that, we need to create a resource file named app.xml.
Example: src/main/resources/app.xml
.
In the migrations section you need to inform each file that will be processed. For that we need to inform the file name and the change set parameters.
Example:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:configuration xmlns:ns2="http://meceap.me.com.br/schema/config-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://meceap.me.com.br/schema/config-mapping http://docs.miisy.me/xsd/config-mapping.xsd">
<migrations>
<changeSet id="0001-01" author="john" description="Product Update">
<dataFile fileName="products.data.xlsx"/>
</changeSet>
</migrations>
</ns2:configuration>
After that we need to crate a file using the following template.
Note: The sheet name must be equal to the data object name.
Example:
code | name |
---|---|
00001 | Product A |
00002 | Product B |
00003 | Product C |
The file path must be src/main/data
.
Example: src/main/data/products.data.xlsx
.
Attachment Field
The attachment
type allows you to include files in a record of your table
, to import data for this
fieldType
through the xlsx
file it's necessary to define in the corresponding column's field the public 'URLs' of each file separated by commas.
Note that if the attachment
field is not set tomultiple
only the first attachment defined by URL
will be imported.
Example:
code | name | attachment |
---|---|---|
00001 | Product A | url, url, url |
00002 | Product B | url, url |
00003 | Product C | url |
Important Note: You must pay attention to sharing services like Google Drive, One Drive and Dropbox, because although they make possible leave a public file, the URL
provided by them has an html
as response and not the desired file.