Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Merge release 1.0.0a21 #155

Merged
merged 15 commits into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[bumpversion]
current_version = 1.0.0a20
current_version = 1.0.0a21

parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)((?P<release>[a-z]+))(?P<release_version>\d+)
serialize =
{major}.{minor}.{patch}{release}{release_version}
Expand Down
100 changes: 100 additions & 0 deletions doc/documentation_page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Get Started with mssql-scripter

mssql-scripter is the command line equivalent of the widely used Generate Scripts Wizard experience in SSMS.

You can use mssql-scripter on Linux, macOS, Windows, and the Azure Cloud Shell to generate data definition language (DDL) and data manipulation language (DML) T-SQL scripts for database objects in SQL Server running anywhere, Azure SQL Database, and Azure SQL Data Warehouse. You can save the generated T-SQL script to a .sql file or pipe it to standard *nix utilities (for example, sed, awk, grep) for further transformations. You can edit the generated script or check it into source control and subsequently execute the script in your existing SQL database deployment processes and DevOps pipelines with standard multiplatform SQL command line tools such as sqlcmd.

## Install

For information about installation, please see the LINK/install guide/LINK.

The examples in this guide use the Adventureworks sample database. You can download the sample [here](https://www.microsoft.com/en-us/download/details.aspx?id=49502).

## Generate scripts
Use mssql-scripter to generate scripts for database schema and/or data by including specific objects, targeting server versions/editions, and piping the script to files.

### Dump database object schema

# generate DDL scripts for all objects in the Adventureworks database and save the script to a file
mssql-scripter -S localhost -d AdventureWorks -U sa

# alternatively, specify the schema only flag to generate DDL scripts for all objects in the Adventureworks database and save the script to a file
mssql-scripter -S localhost -d AdventureWorks -U sa -f ./adventureworks.sql

### Dump database object data

# generate DDL scripts for all objects in the Adventureworks database and save the script to stdout.
mssql-scripter -S localhost -d AdventureWorks -U sa --data-only

### Dump the database object schema and data

# script the database schema and data piped to a file.
mssql-scripter -S localhost -d AdventureWorks -U sa --schema-and-data > ./adventureworks.sql

# execute the generated above script with sqlcmd
sqlcmd -S mytestserver -U sa -i ./adventureworks.sql

### Include database objects

# generate DDL scripts for objects that contain 'Employee' in their name to stdout
mssql-scripter -S localhost -d AdventureWorks -U sa --include-objects Employee

# generate DDL scripts for the dbo schema and pipe the output to a file
mssql-scripter -S localhost -d AdventureWorks -U sa --include-objects dbo. > ./dboschema.sql

### Exclude database objects

# generate DDL scripts for objects that do not contain 'Sale' in their name to stdout
mssql-scripter -S localhost -d AdventureWorks -U sa --exclude-objects Sale

### Target server version

# specify the version of SQL Server the script will be run against
mssql-scripter -S myServer -d AdventureWorks -U myUser –-target-server-version "AzureDB" > myData.sql

### Target server edition

# specify the edition of SQL Server the script will be run against
mssql-scripter -S localhost -d AdventureWorks -U myUser –-target-server-edition "Enterprise" > myData.sql

### Pipe a generated script to sed
Note this example is for Linux and macOS usage.

# change a schema name in the generated DDL script
# 1) generate DDL scripts for all objects in the Adventureworks database
# 2) pipe generated script to sed and change all occurrences of SalesLT to SalesLT_test and save the script to a file
mssql-scripter -S localhost -d Adventureworks -U sa | sed -e "s/SalesLT./SalesLT_test./g" > adventureworks_SalesLT_test.sql

### Script data to a file

# script all the data to a file.
mssql-scripter -S localhost -d AdventureWorks -U sa --data-only > ./adventureworks-data.sql

### Set environment variables
You can set environment variables for your connection string through the following steps:


# set environment variable MSSQL_SCRIPTER_CONNECTION_STRING with a connection string.
export MSSQL_SCRIPTER_CONNECTION_STRING='Server=myserver;Database=mydb;User Id=myuser;Password=mypassword;'
mssql-scripter

# set environment variable MSSQL_SCRIPTER_PASSWORD so no password input is required.
export MSSQL_SCRIPTER_PASSWORD='ABC123'
mssql-scripter -S localhost -d AdventureWorks -U sa

## Generate and run scripts
In this example you will generate a script, send it to a file, and execute the script.

Generate a script and send it to a file using mssql-scripter.
# script all the data to a file.
mssql-scripter -S localhost -d AdventureWorks -U sa --data-only > ./adventureworks-data.sql

Now that you have generated a script for your database objects, you can execute the script using sqlcmd such as in the example below.

# execute the script from the file.
sqlcmd -S localhost -d AdventureWorks -U sa -i`./adventureworks-data.sql

You can find more details on using sqlcmd [here](https://docs.microsoft.com/en-us/sql/relational-databases/scripting/sqlcmd-use-the-utility).

## Use mssql-scripter in the Cloud Shell
You can use mssql-scripter in the Azure Cloud Shell to generate scripter for Azure SQL DB, Azure SQL DW, and SQL Server instances in Azure VMs. [Connect to the Azure Cloud Shell](https://docs.microsoft.com/en-us/azure/cloud-shell/overview?view=azure-cli-latest). Once connected, you can use mssql-scripter in the terminal as you would in a local terminal.
4 changes: 3 additions & 1 deletion mssqlscripter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

__version__ = '1.0.0a20'

__version__ = '1.0.0a21'

20 changes: 8 additions & 12 deletions mssqltoolsservice/buildwheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,16 @@
from urllib.request import urlopen


DOWNLOAD_URL_BASE = 'https://mssqlscripter.blob.core.windows.net/sqltoolsservice-08-16-2017/'

DOWNLOAD_URL_BASE = 'https://mssqlscripter.blob.core.windows.net/sqltoolsservice-10-12-2017/'

# Supported platform key's must match those in mssqlscript's setup.py.
SUPPORTED_PLATFORMS = {
'CentOS_7': DOWNLOAD_URL_BASE + 'microsoft.sqltools.servicelayer-centos-x64-netcoreapp2.0.tar.gz',
'Debian_8': DOWNLOAD_URL_BASE + 'microsoft.sqltools.servicelayer-debian-x64-netcoreapp2.0.tar.gz',
'Fedora_23': DOWNLOAD_URL_BASE + 'microsoft.sqltools.servicelayer-fedora-x64-netcoreapp2.0.tar.gz',
'openSUSE_13_2': DOWNLOAD_URL_BASE + 'microsoft.sqltools.servicelayer-opensuse-x64-netcoreapp2.0.tar.gz',
'OSX_10_11_64': DOWNLOAD_URL_BASE + 'microsoft.sqltools.servicelayer-osx-x64-netcoreapp2.0.tar.gz',
'RHEL_7': DOWNLOAD_URL_BASE + 'microsoft.sqltools.servicelayer-rhel-x64-netcoreapp2.0.tar.gz',
'Ubuntu_14': DOWNLOAD_URL_BASE + 'microsoft.sqltools.servicelayer-ubuntu14-x64-netcoreapp2.0.tar.gz',
'Ubuntu_16': DOWNLOAD_URL_BASE + 'microsoft.sqltools.servicelayer-ubuntu16-x64-netcoreapp2.0.tar.gz',
'Windows_7_64': DOWNLOAD_URL_BASE + 'microsoft.sqltools.servicelayer-win-x64-netcoreapp2.0.zip',
'Windows_7_86': DOWNLOAD_URL_BASE + 'microsoft.sqltools.servicelayer-win-x86-netcoreapp2.0.zip'
}
'Linux_64': DOWNLOAD_URL_BASE + 'Microsoft.SqlTools.ServiceLayer-linux-x64-netcoreapp2.0.tar.gz',
'OSX_10_11_64': DOWNLOAD_URL_BASE + 'Microsoft.SqlTools.ServiceLayer-osx-x64-netcoreapp2.0.tar.gz',
'Windows_7_64': DOWNLOAD_URL_BASE + 'Microsoft.SqlTools.ServiceLayer-win-x64-netcoreapp2.0.zip',
'Windows_7_86': DOWNLOAD_URL_BASE + 'Microsoft.SqlTools.ServiceLayer-win-x86-netcoreapp2.0.zip'


CURRENT_DIRECTORY = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))
BUILD_DIRECTORY = os.path.abspath(os.path.join(CURRENT_DIRECTORY, 'build'))
Expand Down Expand Up @@ -78,6 +73,7 @@ def build_sqltoolsservice_wheels(platforms):
os.environ[u'MSSQLTOOLSSERVICE_PLATFORM'] = platform

print(u'Calling setup bdist_wheel for platform:{}'.format(platform))
print(SUPPORTED_PLATFORMS[platform])
download_and_unzip(SUPPORTED_PLATFORMS[platform], directory=TARGET_DIRECTORY)
utility.exec_command(u'python setup.py check -r -s bdist_wheel', CURRENT_DIRECTORY)

Expand Down
4 changes: 3 additions & 1 deletion mssqltoolsservice/mssqltoolsservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import os
import platform

__version__ = '1.0.0a20'

__version__ = '1.0.0a21'



def get_executable_path():
Expand Down
4 changes: 3 additions & 1 deletion mssqltoolsservice/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

# This version number is in place in two places and must be in sync with
# mssqlscripter's version in setup.py.
MSSQLTOOLSSERVICE_VERSION = '1.0.0a20'

MSSQLTOOLSSERVICE_VERSION = '1.0.0a21'


# If we have source, validate version numbers match to prevent
# uploading releases with mismatched versions.
Expand Down
119 changes: 7 additions & 112 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

# This version number is in place in two places and must be in sync with
# mssqltoolsservice's version in setup.py.
MSSQLSCRIPTER_VERSION = '1.0.0a20'

MSSQLSCRIPTER_VERSION = '1.0.0a21'


# If we have the source, validate our setup version matches source version.
# This will prevent uploading releases with mismatched versions. This will
Expand Down Expand Up @@ -58,119 +60,12 @@

MSSQLTOOLSSERVICE_PACKAGE_NAME = 'mssqltoolsservice-{}=={}'
MSSQLTOOLSSERVICE_PACKAGE_SUFFIX = [
'CentOS_7',
'Debian_8',
'Fedora_23',
'openSUSE_13_2',
'OSX_10_11_64',
'RHEL_7',
'Ubuntu_14',
'Ubuntu_16',
'Windows_7_64',
'Windows_7_86'
'Windows_7_86',
'Linux_64'
]

LINUX_DISTRO_NO_VERSION = {
'centos': 'CentOS_7',
'ol': 'CentOS_7',
'fedora': 'Fedora_23',
'opensuse': 'OpenSUSE_13_2',
'rhel': 'RHEL_7',
'debian': 'Debian_8',
}

LINUX_DISTRO_WITH_VERSION = {
'ubuntu':
{
'14': 'Ubuntu_14',
'16': 'Ubuntu_16'
},
'elementary':
{
'0.3': 'Ubuntu_14',
'0.4': 'Ubuntu_16'
},
'elementaryOS':
{
'0.3': 'Ubuntu_14',
'0.4': 'Ubuntu_16'
},
'linuxmint':
{
'18': 'Ubuntu_16'
},
'galliumos':
{
'2.0': 'Ubuntu_16'
},
}


def _get_runtime_id_helper(name, version):
"""
Checks if linux distro name and version match to a supported package.
"""
if name in LINUX_DISTRO_NO_VERSION:
return LINUX_DISTRO_NO_VERSION[name]

if name in LINUX_DISTRO_WITH_VERSION:
for supported_version in LINUX_DISTRO_WITH_VERSION[name]:
if version.startswith(supported_version):
return LINUX_DISTRO_WITH_VERSION[name][supported_version]
return None


def _get_linux_distro_runtime_id(content):
"""
Parse content for linux distro run time id.
"""
name = None
version = None
id_like = None

# Try to find name, version and id_like best effort.
for line in content.splitlines():
key, value = line.rstrip().split('=')
value = value.strip('"')
if key == 'ID':
name = value
elif key == 'VERSION_ID':
version = value
elif key == 'ID_LIKE':
id_like = value.split(' ')
if name and version and id_like:
break
# First try the distribution name.
run_time_id = _get_runtime_id_helper(name, version)

# If we don't understand it, try the 'ID_LIKE' field.
if not run_time_id and id_like:
for name in id_like:
run_time_id = _get_runtime_id_helper(name, version)
if run_time_id:
break

return run_time_id


def _get_linux_distro_from_file():
"""
Find linux distro based on
https://www.freedesktop.org/software/systemd/man/os-release.html.
"""
os_release_info_file = None

if os.path.exists('/etc/os-release'):
os_release_info_file = '/etc/os-release'
elif os.path.exists('/usr/lib/os-release'):
os_release_info_file = '/usr/lib/os-release'
else:
raise EnvironmentError('Error detecting Linux distro version.')

with io.open(os_release_info_file, 'r', encoding='utf-8') as os_release_file:
content = os_release_file.read()
return _get_linux_distro_runtime_id(content)


def _get_runtime_id(
system=_platform.system(),
Expand All @@ -191,7 +86,7 @@ def _get_runtime_id(
run_time_id = 'OSX_10_11_64'
elif system == 'Linux':
if architecture == '64bit':
run_time_id = _get_linux_distro_from_file()
run_time_id = 'Linux_64'

return run_time_id

Expand Down Expand Up @@ -244,7 +139,7 @@ def get_mssqltoolsservice_package_name(run_time_id=_get_runtime_id()):
description='Microsoft SQL Scripter Command-Line Tool',
license='MIT',
author='Microsoft Corporation',
author_email='sqlxplatclieng@microsoft.com',
author_email='sqlcli@microsoft.com',
url='https://github.com/Microsoft/sql-xplat-cli/',
zip_safe=True,
long_description=open('README.rst').read(),
Expand Down