forked from excellarateinc/voyage-api-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-sql-script.bat
43 lines (31 loc) · 1.44 KB
/
generate-sql-script.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@echo off
:: Need to install - https://msdn.microsoft.com/en-us/library/mt204009.aspx
:: DacFx
SETLOCAL ENABLEEXTENSIONS
:: root is the folder containing this script (without trailing backslash)
set root=%~dp0
set root=%root:~0,-1%
::Path to the SqlPackage.exe
SET toolPath="C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130\SqlPackage.exe"
::Path to the dacpac
SET sourcePath=".\Voyage.Database\bin\Debug\Voyage.Database.dacpac"
::Connection string for the target
SET connectionString="Integrated Security=SSPI;Persist Security Info=False;Data Source=localhost;Initial Catalog=Voyage"
::Generate the default file name
::https://blogs.msdn.microsoft.com/myocom/2005/06/03/creating-unique-filenames-in-a-batch-file/
for /f "delims=/ tokens=1-3" %%a in ("%DATE:~4%") do (
for /f "delims=:. tokens=1-4" %%m in ("%TIME: =0%") do (
set outputPath=Voyage.Database-%%c-%%b-%%a-%%m%%n%%o%%p.sql
)
)
:: process command line
if not [%1]==[] if not [%1]==[-] set toolPath=%1
if not [%2]==[] if not [%2]==[-] set sourcePath=%2
if not [%3]==[] if not [%3]==[-] set connectionString=%3
if not [%4]==[] if not [%4]==[-] set outputPath=%4
:: report configuration
echo connectionString: %connectionString%
echo sourcePath: %sourcePath%
echo toolPath: %toolPath%
echo outputPath: %outputPath%
%toolPath% /TargetConnectionString:%connectionString% /SourceFile:%sourcePath% /Action:Script /OutputPath:%outputPath%