Skip to content

How to bulk import data during migration

Rodel Dagumampan edited this page Feb 12, 2020 · 12 revisions

Master data and lookup tables almost comes natural as part of every database provisioning process. With this, you may prepare them in CSV files and yuniql will inspect them and bulk load into tables bearing same name as the CSV file. The following example demonstrates how to do this.

Install Yuniql CLI
https://github.com/rdagumampan/yuniql/wiki/Install-yuniql.

choco install yuniql --version 0.350.0

Initialize local version

yuniql init
yuniql vnext

Create script file setup_tables.sql on v0.01

CREATE TABLE Visitor (
	VisitorID INT IDENTITY(1000,1),
	FirstName NVARCHAR(255),
	LastName VARCHAR(255),
	Address NVARCHAR(255),
	Email NVARCHAR(255)
);

Create a Visitor.csv on version v0.01

"VisitorID","FirstName","LastName","Address","Email"
"1000","Jack","Poole","Manila","[email protected]"
"1001","Diana","Churchill","Makati","[email protected]"
"1002","Rebecca","Lyman","Rizal","[email protected]"
"1003","Sam","Macdonald","Batangas","[email protected]"
"1004","Matt","Paige","Laguna","[email protected]"

NOTE: The file name of the CSV file must match the destination table else an exception is thrown.

Run migration

yuniql run -a -c "<your-connection-string>"

INF   2019-10-22T18:36:08.7621330Z   Executed script file C:\temp\yuniql-nightly\v0.01\setup-tables.sql.
INF   2019-10-22T18:36:08.7638901Z   Found the 1 csv files on C:\temp\yuniql-nightly\v0.01
INF   2019-10-22T18:36:08.7649367Z   Visitor.csv
INF   2019-10-22T18:36:09.0854032Z   Imported csv file C:\temp\yuniql-nightly\v0.01\Visitor.csv.

Verify if all is good

SELECT * FROM [dbo].[Visitor]

Found bugs?

Help us improve further please create an issue.