Automated SQL Server deployment tool that runs 'SqlPackage' and 'SqlCmd' based on JSON configuration
mssql-deploy
requires an installation of SqlPackage and SqlCmd
from Microsoft
SqlPackage
and SqlCmd
should be accessible from a directory on PATH
On Windows the tool also looks for the executalbes at:
%ProgramFiles%\Microsoft Sql Server\150\DAC\bin\SqlPackage.exe
and
%ProgramFiles%\Microsoft Sql Server\110\Tools\Binn\SQLCMD.exe
respectively.
Download the latest build for your OS
The executable requires a .json
configuration file as input,
each root element of the JSON document runs a single execution of sqlpackage
or sqlcmd
if that's the Action
with the arguments for the execution defined within.
All the possible sqlpackage
arguments can be found on Microsoft's website
Run the executable with your deployment configuration:
mssql-deploy deploy-config.json
Example configuration file: deply-config.json
{
"Erp2009_lite-destroy": {
"Action": "sqlcmd",
"S": "localhost",
"U": "SA",
"P": "12345678!",
"Q": "IF EXISTS(SELECT * FROM sys.databases WHERE name='nav2009_lite') BEGIN ALTER DATABASE [nav2009_lite] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; DROP DATABASE [nav2009_lite]; END"
},
"Erp2009_lite-deploy": {
"Action": "Import",
"SourceFile": "nav2009_lite.bacpac",
"TargetServerName": "localhost",
"TargetDatabaseName": "nav2009_lite",
"TargetUser": "SA",
"TargetPassword": "12345678!"
},
"Production": {
"Action": "Publish",
"SourceFile": "development/dev_prod/bin/Debug/dev_prod.dacpac",
"TargetDatabaseName": "prod",
"TargetServerName": "localhost",
"TargetUser": "SA",
"TargetPassword": "12345678!",
"p": {
"IncludeCompositeObjects": true,
"CompareUsingTargetCollation": true,
"CreateNewDatabase": true
}
},
"Staging": {
"Action": "Publish",
"SourceFile": "development/dev_stg_nav/bin/Debug/dev_stg_nav.dacpac",
"TargetDatabaseName": "stg_nav",
"TargetServerName": "localhost",
"TargetUser": "SA",
"TargetPassword": "12345678!",
"p": {
"IncludeCompositeObjects": true,
"CompareUsingTargetCollation": true,
"CreateNewDatabase": true
}
}
}
The project uses pipenv
for managing packages and virtual environment.
Install pipenv
with pip
or optionally brew
(MacOS)
pip install pipenv
Install packages:
pipenv install
Run the program within the virtualenv
pipenv run python app.py
Build the program from within the virtualenv with pyinstaller
pipenv shell
pyinstaller --onefile app.py -n mssql-deploy
exit
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.