|
@echo off |
|
REM ============================================================================================= |
|
REM !! DESTRUCTIVE !! |
|
REM Resets a test database, runs upgrades, adds test data, adds test files. |
|
|
|
REM Must be run in visual studio command prompt to allow build. |
|
REM Requires SqlHawk, msbuild, and msdeploy (part of webdeploy) to be on the path. |
|
REM Environment variables can be overridden by caller / calling scripts. |
|
|
|
REM It is recommended that you set a buffer of 3000 lines on your command window to avoid losing output. |
|
REM ============================================================================================= |
|
|
|
REM allow use of !var! everywhere, the normal !var! version doesn't work with if / for etc. |
|
REM and avoid messing with variables in the command window scope: |
|
Setlocal EnableDelayedExpansion |
|
|
|
set localPublishPath=..\WebProject |
|
|
|
REM set variable defaults if not already set by caller |
|
if "!server!"=="" set server=localhost |
|
if "!database!"=="" set database=DevDb |
|
if "!batch!"=="" set batch=!USERNAME! on !COMPUTERNAME!; Manual run |
|
if "!publishPath!"=="" set publishPath=!localPublishPath! |
|
if "!mailbox!"=="" set [email protected] |
|
if "!siteUrl!"=="" set siteUrl=http://localhost:7031 |
|
if "!resetType!"=="" set resetType=backup |
|
if "!config!"=="" set config=Debug |
|
|
|
echo Server : !server! |
|
echo Database : !database! |
|
echo Batch : !batch! |
|
echo Publish path: !publishPath! |
|
echo Mailbox : !mailbox! |
|
echo Site url : !siteUrl! |
|
echo Config : !config! |
|
|
|
echo. |
|
echo !date! !time! Starting rebuild... |
|
|
|
if not "!publishPath!"=="!localPublishPath!" ( |
|
echo. |
|
@echo Taking app offline... |
|
copy app_offline.htm "!publishPath!" |
|
if !errorlevel! neq 0 exit /b !errorlevel! |
|
) |
|
|
|
if not "!skipDb!"=="" ( |
|
echo. |
|
@echo Skipping db rebuild. |
|
) else ( |
|
echo. |
|
@echo Reverting to clean backup of live db... |
|
@echo Do not interrupt this step as a broken connection can wedge the database. Ref http://stackoverflow.com/questions/520967 |
|
sqlcmd -b -S !server! -E -d master -i reset-to-!resetType!.sql -v database=!database! |
|
if !errorlevel! neq 0 exit /b !errorlevel! |
|
) |
|
|
|
REM this is the bit that will be done on the final deployment to live: |
|
echo. |
|
@echo Running upgrade... |
|
call upgrade.bat |
|
if !errorlevel! neq 0 exit /b !errorlevel! |
|
|
|
|
|
if "!skipDb!"=="" ( |
|
echo. |
|
@echo Applying test data... |
|
pushd . |
|
cd test-data\sql\ |
|
call test-data.bat |
|
if !errorlevel! neq 0 exit /b !errorlevel! |
|
popd |
|
|
|
echo. |
|
@echo Configuring global config... |
|
sqlcmd -b -S !server! -E -d !database! -i global-config.sql -v mailbox="!mailbox!" siteUrl="!siteUrl!" |
|
) |
|
|
|
echo. |
|
@echo Copying test files into publish directory... |
|
xcopy /S /Y test-data\upload !publishPath!\data\upload\ |
|
if !errorlevel! neq 0 exit /b !errorlevel! |
|
|
|
if not "!publishPath!"=="!localPublishPath!" ( |
|
echo. |
|
@echo Putting app back online... |
|
del !publishPath!\app_offline.htm |
|
) |
|
|
|
echo. |
|
@echo !date! !time! Done. |