Skip to content

idan-h/schemazenPlus

 
 

Repository files navigation

Schema Zen Plus - Script and create SQL Server objects quickly & additional SSDT support

Schema Zen Plus has five main commands:

script

SchemaZen.exe script -c "server=localhost;database=db;trusted_connection=yes;" --scriptPath c:\somedir\script.sql

This will generate an sql script that creates objects in the database in the specified path:

c:\somedir\
	script.sql

The script's routines (procedures, functions etc) are generated by their dependency order, so you should be able to just run the script on an empty database and it will take care of everything. You can cancel this options by the --no-depends flag to make it load faster

Another added option, is to specify which object types to script from the below list:

[user_defined_types, tables, foreign_keys, assemblies, functions, procedures, triggers, views, xmlschemacollections, data, roles, users, synonyms, table_types, schemas, props, permissions, check_constraints, defaults, routines]

Use it like: --onlyTypes users,tables
If empty, includes all

create

SchemaZen.exe create -c "server=localhost;database=db;trusted_connection=yes;" --scriptPath c:\somedir\script.sql

This will create a database named db from the sql scripts in c:\somedir\script.sql

compare

SchemaZen.exe compare --source "server=dev;database=db" --target "server=qa;database=db" --outFile diff.sql

This will compare the databases named db between dev and qa and create a sql script called diff.sql that can be run on qa to make it's schema identical to dev.

Another added option, is to specify which object types to script from the below list:

[user_defined_types, tables, foreign_keys, assemblies, functions, procedures, triggers, views, xmlschemacollections, data, roles, users, synonyms, table_types, schemas, props, permissions, check_constraints, defaults, routines]

Use it like: --onlyTypes users,tables
If empty, includes all

export

SchemaZen.exe export -c "server=localhost;database=db;trusted_connection=yes;" --exportDir c:\somedir

This will export the data from the database to c:\somedir\data

import

SchemaZen.exe import -c "server=localhost;database=db;trusted_connection=yes;" --importDir c:\somedir

This will import the data from the folder c:\somedir\data to the database

See SchemaZen.exe help [command] for more information and options on each command.

SSDT

This project was meant to work with SSDT but without using their deployment system to enable more flexibility over the migrations.
You would need an additional library like DbUp or so. PS scripts will be added in the future to support this functionality.
The idea is, to do changes via SSDT (for example alter a stored procedure) and then run a command in the PM Console to generate a script from the changes. I Like to remove all the routines (stored procedures, views, functions etc) pre-migration and append them post-migration so they will only appear once in the migration process and to solve dependency issues (for example a procedure that references a table type).
An example usage project will be added in the future.

Contributing

Pull requests are welcome and appreciated. See contributing.md for guidelines.

Additional Notes

I forked this repo from sethreno/schemazen.
This was an amazing project, but it is a bit unmaintaned in the last couple of years.
I added and changed some functionality as I needed, and shared it here in case someone would also be interested in that.
I don't like the coding style so much, so I might change it in the future to a more appropriate one, although currently I have no time for that.
You are welcome to try it, tell me if it needs additional features or has bugs, and send pull requests.

About

Script and create SQL Server objects quickly

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 97.3%
  • TSQL 2.5%
  • PowerShell 0.2%