-
Notifications
You must be signed in to change notification settings - Fork 42
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
SqlCmdVariable support #6
Comments
Hi @molszews, thanks for reporting this. This currently doesn't seem to be supported, but would be a great addition. We would probably have to add those SQLCMD variables to the |
|
Hmm, if that's part of the |
I already have it working in PackageBuilder class, but there is a long pipeline of passing parameters etc. I can submit a PR for this, if you are intserested?
|
Yeah, that's pretty much the bulk of what this project does, passing parameters around ;). That already looks like a good start though. We'll probably need to add an argument to the |
Would it be an option to simply treat SqlCmdVariables like other properties? (And then of course special case when adding this property)
|
I'm not entirely sure that is going to work. I don't think you can have the same property defined multiple times, so if you have multiple SQLCMD variables you want to define you'll need to separate them with semi-colons. Also, how are we going to define the value and default value? Also, having an easy way to migrate from |
Agree - though I am not sure the value and defaultvalue are need in the dacpac - they are for VS use only. |
SQLCMD Variables In SQL Server Database Projects you can utilize SQLCMD variables to provide dynamic substitution to be used for debugging or publishing. You enter the variable name and values and during build, the values will be substituted. If there are no local values, the default value will be used. By entering these variables in project properties, they will automatically be offered in publishing and are stored in publishing profiles. You can pull in the project values of the variables into publish via the Load Values button. |
So compatible syntax would be: <ItemGroup>
<SqlCmdVariable Include="DbReaderPassword" />
<SqlCmdVariable Include="DbUserPassword" />
</ItemGroup>
|
Thanks to the effort of @ErikEJ we now have a prerelease version available that supports SQLCMD variables. It would be great if @molszews and @ErikEJ could try this out in a real world project, since I'm not using SQLCMD variables myself. I have seen them ending up in the resulting Please let me know of this works for you so I can close this issue. I'll also add it to the README. |
I think this is impossible to test atm, seems to me that SQLCMD support (incl variables) is limited to post/pre deployment scripts which are subject of the different issue |
You can also use them in model scripts - https://sqlplayer.net/2019/03/tokenization-of-database-project-in-ssdt/ - but we only use them in post deploy script. |
It looks like the pre- and postdeployment scripts are exposed through the. |
That looks like a good place to start. I just did a little experiment with something similar and it looks like the script file ends up in the package. Haven't tested yet if it also gets executed at deployment time though. But if that works, we'll only need to figure out how we can support referencing other files. I'll try to do some more research on that when I have the time. |
Maybe we could skip supporting multiple files for now? see #9 (comment) |
I would be honoured to become a maintainer! It's a great project. And I plan to blog about it soon, as it is currently semi ready for prime time. |
Cool. I've sent you an invite. |
Seems like there is no way to create dacpac that accepts params:
![image](https://user-images.githubusercontent.com/2878612/79868184-d56f2c80-83df-11ea-878f-cc139215d22c.png)
you only need to have sql like that:
INSERT INTO $(TasksDb).[schema].[table] ...
so you can pass the variable during runtime:
sqlpackage.exe /Action:Publish /SourceFile:pkg.dacpac /Target(..) /v:TasksDb=Tasks
btw such params are present in sqlproj as well:
The text was updated successfully, but these errors were encountered: