Skip to content

Conversation

crazycrank
Copy link
Contributor

@crazycrank crazycrank commented Jun 13, 2018

So, we required some features in the office for the dbup-scripter, since we are heavily dependent on database, and use the dbup pretty often. I decided it was probably easiest to implement them myself, so here we go.

Bugfixes:

  • When called with --scriptAllDefinitions functions weren't scripted. This is fixed now

Features

  • Added new Option "ScriptBatchTerminator" which, if set to true, inserts GO (and a newline) between all batches of the definition
  • When the migration is unsuccessful, the migrator now analyzes which scripts were successfully applied and scripts the definitions for those. This makes sure, that no defintions are lost, when an error occurs during migration
  • If objects have changed multiple times during migration, all except the newest get removed from the list of objects to script. This a) achieves better performance and b) avoids errors, when an object has been changed and later been dropped during the same migration run
  • added support for SQL 2016 features CREATE OR ALTER and DROP IF EXISTS
  • added support for renaming objects with sp_rename. This creates a Drop for the original name and a create for the new name

this last feature has been somewhat of a pain to implement, but I got it to run in the end. This lead to a pretty complicated regex. Also sp_rename allows the renaming of columns, indexes and keys, which I have not implemented, and am not sure how to best do that (it's certainly possible, but will require further changes). Also, to find out what type of object has been renamed, I need to scan the db context. This sadly also means, that if an object has been renamed and later dropped (or renamed again), its impossible to find out what object type needs to be scripted. In this case a warning gets printed in the end, to inform the user he has to check the file manually and delete it if necessary.

If you have any request for changes, please let me know. I have tried to keep my changes as clean as possible, but I'll gladly implement some feedback if we can use that in our code soon :)

Regards,
Max

Edit: by the way, I tested the changes on our database. Around 220 scripts with sometimes pretty elaborate migrations. Besides the above named problems regarding renaming of indexes and the like, and the problem when using sp_rename and later dropping the object, everything worked perfectly

@bradymholt bradymholt requested review from kkrol and bradymholt June 14, 2018 13:38
@bradymholt
Copy link
Owner

Wow, this looks great @crazycrank ! Any chance you could update README to reflect details on these changes where it makes sense?

@kkrol What do you think of these changes?

@kkrol
Copy link
Collaborator

kkrol commented Jun 14, 2018 via email

@crazycrank
Copy link
Contributor Author

@bradymholt I was just checking out the readme, but the only thing I updated was the addition of User Defined Types to the list of supported object types, since im mostly just extending. I can add some info about the supported statements (DROP IF EXISTS/CREATE OR ALTER) if you want, or add a list of known issues regarding the problems with renaming and later dropping items? Or what were you thinking about?

@bradymholt
Copy link
Owner

@crazycrank Ah, makes sense. Yeah, a "Known Issues" section would be great. Thank you! Once you're able to add this, I can merge and push this out to NuGet.

@crazycrank
Copy link
Contributor Author

@bradymholt Awesome! I have added a list of known issues and also of supported statements. If there's anything else, just message me ;)

@bradymholt bradymholt merged commit b61672e into bradymholt:master Jun 14, 2018
@bradymholt
Copy link
Owner

Released as 2.1.0: https://www.nuget.org/packages/dbup-sqlserver-scripting/2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants