@echo off
set ProjectRoot=C:\JenkinsHomeDir\workspace\Production-RCCP\
set EF6Directory=packages\EntityFramework.6.4.4\tools\net45\any\
set BuildDirectory=RetailCamControlPanel\bin\
set EF6exeName=ef6.exe
set RCCPdll=RetailCamControlPanel.dll
set DBCon="Data Source=dbcontent6848.footfallcam.com,41433;Initial Catalog=RetailCamControlPanel;User ID=sa;Password=5d$Q^rdp2ZZ4*$5K;Max Pool Size=3000"
REM set DBCon="Data Source=192.168.2.72,1433;Initial Catalog=RetailCamControlPanel;User ID=ffc_user;Password=qwer!234;Max Pool Size=3000"

for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set folderName=%ldt:~0,4%%ldt:~4,2%%ldt:~6,2%_%ldt:~8,2%%ldt:~10,2%%ldt:~12,2%
echo %folderName%
set DBMigrationDirectory=C:\RetailCamUpdater-v2\DBMigrations\Production\RCCP\
set DBMigrationFile=%DBMigrationDirectory%Migration_RCCP_%folderName%.txt
echo %DBMigrationFile%


if not exist %DBMigrationDirectory% (
    echo create dir %DBMigrationDirectory%
    mkdir %DBMigrationDirectory%
) 

cd %ProjectRoot%%BuildDirectory%

if not exist %ProjectRoot%%BuildDirectory%%EF6exeName% (
    echo not exist file
    copy %ProjectRoot%%EF6Directory%%EF6exeName% %ProjectRoot%%BuildDirectory%%EF6exeName%
)



if exist %ProjectRoot%%BuildDirectory%%EF6exeName% (
    echo exist file
    %EF6exeName% database update --assembly RetailCamControlPanel.dll --connection-string=%DBCon% --connection-provider="System.Data.SqlClient" --script --force >> %DBMigrationFile%
    @echo off
    echo Waiting for 10 seconds...
    ping 127.0.0.1 -n 10 > nul
    echo Done waiting.
    %EF6exeName% database update --assembly RetailCamControlPanel.dll --connection-string=%DBCon% --connection-provider="System.Data.SqlClient" --verbose --force
)





