Skip to main content

Initial Data

The SQL expanders can expand initial setup data scripts, based on an XML based format which is mapped to the correct SQL syntax.

Setup

This initial data is defined per application, in a file located at [sourceBase]/applications/[applicationName]/init-data/[applicationName]-data.xml.

Example
Application Initial data file
database-test[sourceBase]/applications/database-test/init-data/database-test-data.xml
rocketManager[sourceBase]/applications/rocketManager/init-data/rocketManager-data.xml

File structure

The XML file has a root element dataInstances, which contains an ordered collection of dataInstance elements:

<?xml version="1.0" encoding="UTF-8"?>
<dataInstances xmlns="https://schemas.normalizedsystems.org/xsd/sql-expanders/2/5/0/dataInstances">
<dataInstance>
...
</dataInstance>
<dataInstance>
...
</dataInstance>
</dataInstances>

Data instances

Each data instance represents an instance of a specific DataElement. It includes a reference to the element, as well as a list of fields with the data required to initialize them. Any field that is not listed is set to NULL.

There are in total three different types of field definitions, where for each of them the name of the field in the DataElement is the name of the XML tag in the data instance:

TypeDescription
ValueA value definition is marked by the attribute type="value" or has no type attribute. The value that has to be inserted into the database is the text value of the XML tag. The value will be parsed by the expanders and mapped to the correct syntax for the type of the matching ValueField.
ScriptedSimilar to a value definition but marked with the attribute type="script". These definitions also apply to ValueFields. The name of a function used to generate a value for the field in the database is the text value of the XML tag. The expanders will map this function definition to the appropriate database function or generated value.
LinkedThe linked definition is used for link fields and contains a set of child elements that have the name of a field in the target element and a value it has to match to. All of these constraints will be matched to a target record as a conjunction.
caution

Unlike a field that is undefined, a value definition tag that is empty (<value/>), will not be mapped to NULL. Rather, it will be inserted as an empty string.

Script field functions

FunctionDescription
Date::nowThis function will be translated to a timestamp with or without a time included for the types DateLong and Date respectively. To generate the timestamp, the expanders will map it to an appropriate database function, which will generate the transaction timestamp on insertion. For most SQL databases, this is current_timestamp and current_date respectively.
UUID::newThis function will generate a random UUID in the script for String type fields.

Example

<?xml version="1.0" encoding="UTF-8"?>
<dataInstances xmlns="https://schemas.normalizedsystems.org/xsd/sql-expanders/2/5/0/dataInstances">
<!-- account.Account -->
<dataInstance dataElement="account::Account">
<address>Galileilaan 15</address>
<city>Niel</city>
<country>BE</country>
<email>i.love.ns@nsx.normalizedsystems.org</email>
<fullName>Normalized Systems</fullName>
<name>NSX</name>
<phone>03/123.45.67</phone>
<refId>1</refId>
<status>Activated</status>
<style>nsxbootstrap</style>
<zipCode>2845</zipCode>
</dataInstance>

<!-- account.Profile -->
<dataInstance dataElement="account::Account">
<name>admin</name>
<weight>1</weight>
</dataInstance>

<!-- account.User -->
<dataInstance dataElement="account::Account">
<account type="link">
<name>NSX</name>
</account>
<disabled>no</disabled>
<email>admin@nsx.normalizedsystems.org</email>
<enteredAt type="script">Date::now</enteredAt>
<firstName/>
<fullName>Beheerder</fullName>
<language>dutch</language>
<lastModifiedAt type="script">Date::now</lastModifiedAt>
<lastName/>
<mobile/>
<name>admin</name>
<password>myFavoritePassword</password>
<persNr/>
<profile type="link">
<name>admin</name>
</profile>
<timeout>3600</timeout>
</dataInstance>
</dataInstances>