Skip to content

Commit

Permalink
PD-5659: loadUpdateData
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-velonis1 committed Jan 30, 2025
1 parent f5773d6 commit dbae79f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<tr MadCap:conditions="change-type-load-data-attributes.loadUpdateData">
<td><code>primaryKey</code>
</td>
<td>Comma delimited list of the columns for the primary key</td>
<td>A list of columns representing the primary key of the table (can be composite). Separate multiple values with commas. <MadCap:variable name="General.Liquibase" /> uses the primary key column(s) to determine which columns need records to be inserted or updated. You must specify columns that exist in your CSV.</td>
<td>all</td>
<td>all</td>
<td>
Expand Down
15 changes: 15 additions & 0 deletions Content/change-types/load-update-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@
<h1 id="change-loadupdatedata">loadUpdateData</h1>
<p>Loads or updates data from a CSV file into an existing table. Differs from <MadCap:xref href="load-data.html">loadData</MadCap:xref> by issuing a SQL batch that checks for the existence of a record. If found, the record is UPDATEd, else the record is INSERTed. Also, generates DELETE statements for a rollback.</p>
<p>A value of NULL in a cell will be converted to a database NULL rather than the string <code>NULL</code>.</p>
<h2>Uses</h2>
<p>You can use <code>loadUpdateData</code> to update an existing CSV with new data. For example, consider a CSV&#160;called <code>users.csv</code>:</p><pre xml:space="preserve"><code class="language-text">id,name
0,samantha
1,john
2,zelda</code></pre>
<p>Imagine that you use <code>loadData</code> to insert these records into a table in your database whose primary key is <code>id</code>. Then imagine that the user John wants to go by Johnny instead, and you also get a new user named Tamanend. You can represent this in your CSV:</p><pre xml:space="preserve"><code class="language-text">id,name
0,samantha
1,johnny
2,zelda
3,tamanend</code></pre>
<p>Then use <code>loadUpdateData</code> to deploy the change to your database. Specify your CSV&#160;file, the name of the table to update, and the primary key of the table. For each row, <MadCap:variable name="General.Liquibase" /> uses the primary key to determine whether the record exists:</p>
<ul>
<li><b>If the record exists</b>, <MadCap:variable name="General.Liquibase" /> checks whether the database matches the CSV, and alters the table with the value in the CSV if needed. In this case, <MadCap:variable name="General.Liquibase" /> replaces <code>john</code> with <code>johnny</code>.</li>
<li><b>If the record doesn't exist</b>, <MadCap:variable name="General.Liquibase" /> inserts it as a new row in the table. In this case, <MadCap:variable name="General.Liquibase" /> adds a new row for <code>tamanend</code>.</li>
</ul>
<h2>Run <code>loadUpdateData</code></h2>
<MadCap:snippetBlock src="../Z_Resources/Snippets/text/change-type-run-syntax.flsnp" />
<MadCap:snippetBlock src="../Z_Resources/Snippets/text/change-type-load-data-nested.flsnp" MadCap:conditionTagExpression="include[change-type-load-data-attributes.loadUpdateData]" />
Expand Down

0 comments on commit dbae79f

Please sign in to comment.