-
Notifications
You must be signed in to change notification settings - Fork 64
How to apply token replacement
Rodel E. Dagumampan edited this page Jan 31, 2020
·
2 revisions
A series of key/value pairs of tokens can be passed to yuniql. During migration run, yuniql inspects all script files and replaces them. This is particulary useful in cases such as cross-database and linked-server queries where the databases and server names varies per environment.
The following script would fail when run in TEST where EMPLOYEEDB_DEV database does not exists but EMPLOYEEDB_TEST.
SELECT E.FirstName, E.LastName, E.Address, E.Email
FROM [EMPLOYEEDB_DEV].[dbo].[Employee] E
ORDER BY E.FirstName ASCTo resolve this, let's pre-pare your script with token %{ENV-DBNAME-SUFFIX}. You can of course use whatever token name.
SELECT E.FirstName, E.LastName, E.Address, E.Email
FROM EMPLOYEEDB_%{ENV-DBNAME-SUFFIX}.[dbo].[Employee] E
ORDER BY E.FirstName ASCPass the tokens when you run migration
yuniql run -k "ENV-DBNAME-SUFFIX=DEV" -c "<you-dev-connection-string>"
yuniql run -k "ENV-DBNAME-SUFFIX=TEST" -c "<you-test-connection-string>"
yuniql run -k "ENV-DBNAME-SUFFIX=PROD" -c "<you-prod-connection-string>"You may also pass the tokens as a series of key/value pairs separated by comma.
yuniql run -k "token-key1=token-value1,token-key2=token-value2" -c "<you-dev-connection-string>"
yuniql run -k "token-key1=token-value1" -k "token-key2=token-value2" -c "<you-dev-connection-string>"Help us improve further please create an issue.