-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQLCMD Script Support #1
Comments
My apologies for three pull requests on this issue, @JakeGinnivan... that's my inexperience again. I realize now that, instead of editing the markdown files directly on GitHub, I should have done the editing locally in the same branch as the code changes... then you'd just have one pull request to deal with. 😜 Next time for sure. The good news is that I think I got the code changes right this time. All the unit tests are green and I even added a new BDDfy test for the sqlcmd variable substitution. Looking forward to your feedback. |
@JakeGinnivan please mark as an enhancement for 4.0 and assign to me |
sqlcmd support would be great. bumping this :) |
It would be awesome if SQLCMD was supported. Is there any chance of reviving this? |
Well spotted @droyad, I'll have a look what was done previously, it seems like some work has been done, but it was too much for a single PR. I'll see if I can make something for the SQLCMD only. |
Any more news on this? I have a question about how this is going to work:
If |
bumping it again. Would be great if SQLCMD supported. |
Bump again, the use of SQLCMD script support would be greatly appreciated |
@mduiveman84 I think that @dazinator's question above stands. How would this support work? From what I can tell on the original issue, the request is simply to comment-out the SQLCMD statements. That should be a pretty simple script pre-processor to develop if you needed to do it yourself, however I'll happily review & merge a PR which introduces such a thing as an optional extension to DbUp. When you say that the "...use of SQLCMD script support..." would be good, do you mean for DbUp to actually parse and implement the commands? If so, that's a much more complicated proposition and will require some extensive work I'd imagine. For starters there would need to be some additional work done on the script parser to properly identify the commands & all their parts. Then implementations made for each... You can see how this gets complicated. I've never used SQLCMD statements so don't know what's available or how they are useful, so I at least am looking to those who would like this functionality to expand on what is necessary and how it would be beneficial. Someone who is familiar and uses SQLCMD would also need to implement it, as I don't believe I have the proper context to do so. |
@AdrianJSClark The same goes for me, I also haven'tworked witch SQLCMD statements before, only T-SQL. And for the latter, where I couldn't use Entity Framework Migrations to propogate changes to the target database, I used dbup.... primarily to register processed scripts. I understand now that adding support for SQLCMD in dbUp is complicated, which explains why this issue is open for such a long time :) I'm affraid I'm just a fan of dbUp and not the right person to implement this feature. For now, I resorted to writing a ps-script to suit my needs. |
DbUp's SQL Server support should allow the processing of .sql scripts that make use of
sqlcmd
utility commands and scripting variables.sqlcmd
Scripting Variablessqlcmd
scripting variables are referenced using$(variableName)
. This is only slightly different than a DbUp variable reference which uses$variableName$
. In order for DbUp to properly handlesqlcmd
scripting variable references, two DbUp classes must be changed.DbUp.Engine.Preprocessors.StripSchemaPreprocessor.cs
This class removes references to the "schema" variable when no value is provided by the caller. In addition to removing DbUp references to the variable, e.g.,
$schema$.
, it must also removesqlcmd
references, e.g.,$(schema)
.DbUp.Engine.Preprocessors.VariableSubstitutionPreprocessor.cs
.This class replaces variable references with their values from the variables array passed to the constructor. This class must recognize both
sqlcmd
and DbUp variable references for replacement.Note that these changes should be non-breaking. That is to say that scripts that use the existing DbUp variables references will still be handled properly. In fact, the use of both DbUp-style variable references, e.g.,
$variableName$
, andsqlcmd
-style variable references, e.g.,$(variableName)
should be supported.sqlcmd
Commandssqlcmd
supports a number of commands. These commands are processed bysqlcmd
before the Transact-SQL script is submitted to the SQL Server engine for processing.These
sqlcmd
commands must start in column 1 of the line and should be prefaced with a colon character, ":". Technically, the colon character is optional in order to support backward compatibility with theosql
command-line utility. However, in the real world,sqlcmd
commands almost always begin with a colon character, e.g.,:setvar
or:r
.DbUp should not attempt to support the functionality of the
sqlcmd
commands. Rather, DbUp should convert everysqlcmd
command to a double-dash comment and return it as part of the content of the script to be processed by SQL Server. So, the followingsqlcmd
commandsbecomes the following.
This requires the following changes.
This class reads individual Transact-SQL commands out of a script file. When parsing the script text, this class must recognize a
sqlcmd` command and convert it to a comment before returning it.The text was updated successfully, but these errors were encountered: