Objective: to update an existing CSV-based data source using the contents of a new or updated CSV file.
In this example it is presumed that a Data Source exists within Mi-Middleware containing the names of US states and their capitals:
Note that the Index column is selected as the Key column which serves as a unique identifier. The data contained in this Data Source can be visualized as follows:
Also note that this Data Source contains a single entity that uses the Data Source File named "state capitals.csv". The Data Source configuration page shows both.
Updating the Data Source
Periodically it may be necessary to update the CSV file, either because existing data rows have changed or new rows have been added. It may also be the case that columns have been added or removed. If data has been provided to you as an Excel file with a .xlsx or .xls extension, it must be first converted to a CSV file. If data has been provided already in CSV format, you may skip this next step.
Convert Excel File to CSV
Open the .xlsx or .xls file in Excel, select File -> Save As, and in the file type dropdown select "CSV UTF-8 (Comma delimited) (*.csv)". The filename can be anything you want, but for the sake of continuity it is easiest to use the same filename as the name of the existing Data Source File.
Press Save to complete the operation.
Replace the Data Source File
The Data Source File provides a representation of the CSV file in Mi-Middleware. From the MFS Data Sources page, click on the existing Data Source File to be replaced. NOTE: It is crucial to select the existing Data Source File so that it will be replaced. Do NOT press "Upload New Data Source File (.csv)" as this will create a new Data Source File and cause confusion between the old and the new Data Source Files.
On the Data Source File Details page, press "Choose File" to select the CSV file containing the new contents, then press "Upload." If the new CSV file has a different file name than the Data Source File, the Data Source File will be renamed to reflect the new file.
Update the Data Source
Finally, update the Data Source to refresh its contents with the updated Data Source File. On the Data Sources page of Mi-Middleware, select the Data Source to bring up the Data Source Details page.
In most cases all that is required is to press the "Update Data" button. The contents of the Data Source File that is already bound to the Entity will be pulled into the Data Source and the "Data Last Updated" timestamp will update to reflect this. Note that if this entire step is omitted, the Data Source will update itself automatically with the contents of the Data Source File based on the specified Refresh Interval. However, in most cases it makes sense to perform a manual refresh so that the Data Source is immediately up to date.
Update the Data Source Schema
If the schema of the CSV file has changed - meaning a column has been added or removed - it will be necessary to refresh the Entity. First make note of the Entity Name that is used as well as which column is selected as the Key column (there may be more than one). Then in the "CSV File Name" dropdown select any other Data Source File, then select the original Data Source File. This causes the Columns for the Entity to be refreshed. Now re-enter the Entity Name if it has changed, and re-select the Key column(s) and press Update to complete the operation.
The Data source is now updated, and and Mi-Apps client devices will receive this new data the next time they sync with the Mi-Middleware server.