简体   繁体   English

从VS2008部署数据库项目时忽略用户

[英]Ignoring users when deploying a database project from VS2008

I am currently working on an application that has different permissions/users for the local development environment and test. 我目前正在开发一个对本地开发环境和测试具有不同权限/用户的应用程序。 I want to be able to ignore the users and permissions when deploying to either environment. 我希望在部署到任一环境时能够忽略用户和权限。 Under the .sqldeployment file, there seems to only be options for ignoring permissions (IgnorePermissions) and role membership (IgnoreRoleMembership) for a user, but not for ignoring the users themselves. 在.sqldeployment文件下,似乎只有用于忽略用户的权限(IgnorePermissions)和角色成员身份(IgnoreRoleMembership)的选项,而不是忽略用户自己。 Is this possible? 这可能吗?

抱歉,目前无法在2008版的Visual Studio中使用。

There isn't an obvious way - lots of requests for this feature here . 没有一个明显的方式-许多这种功能要求在这里 The command-line tool, vsdbcmd.exe, suffers from the same problem. 命令行工具vsdbcmd.exe遇到同样的问题。

As a workaround, I use a PowerShell script to remove users and schema authorization from the deployment SQL script. 作为解决方法,我使用PowerShell脚本从部署SQL脚本中删除用户和架构授权。 This could be run as a post-deploy step (not tried), or a TeamCity build step etc. 这可以作为部署后步骤(未尝试)或TeamCity构建步骤等运行。

$rxUser = New-Object System.Text.RegularExpressions.Regex "PRINT[^;]*;\s*GO\s*CREATE USER \[[^\]]*](\s*WITH DEFAULT_SCHEMA = \[[^\]]*])?;\s*GO\s*", SingleLine
$rxSchema = New-Object System.Text.RegularExpressions.Regex "PRINT[^;]*;\s*GO\s*CREATE SCHEMA \[[^\]]*]\s*AUTHORIZATION \[[^\]]*];\s*GO\s*", SingleLine

Get-Item "*.sql" | ForEach-Object {
    $input = [System.IO.File]::ReadAllText($_.FullName)
    $input = $rxUser.Replace($input, "")
    $input = $rxSchema.Replace($input, "")

    $output = [System.IO.File]::CreateText($_.FullName)
    $output.Write($input)
    $output.Close()
}

The regex could be modified to ignore DROP USER statements too. 可以修改正则表达式以忽略DROP USER语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM