如何管理开发和生产之间的 SQL 权限? [英] How can I manage SQL permissions between development and production?

查看:37
本文介绍了如何管理开发和生产之间的 SQL 权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个平稳的部署过程,我们可以使用单个部署脚本部署到生产或开发 SQL 服务器.

I'm trying to set up a smooth deployment process where we can deploy to a production or development SQL server with a single deploy script.

但是我不知道如何最好地管理两个环境之间的用户和权限.例如,在开发中,我们希望开发人员组具有 db_owner 数据库角色.在生产环境中,我们要么不需要访问权限,要么只需要 datareader 角色.

But I don't know how best to manage users and permissions between the two environments. For example, in development we want the developers group to have the db_owner database role. On production we either want no access or just the datareader role.

我认为最简单的方法是在每台服务器上设置一次用户,然后不要将它们保留在数据库项目中.但随后它们会在部署过程中被丢弃.

I think the easiest way to do this would be to set up the users once on each server and then not keep them in the database project. But then they get dropped during deployment.

有什么方法可以使用 Visual Studio 中的项目配置来做到这一点吗?

Is there some way I can do this using project configuration in Visual Studio?

我们使用的是完整的 Microsoft 堆栈

We're using a complete Microsoft stack

  • Visual Studio 2010 数据库项目
  • SQL Server 2008
  • TFS 版本控制和构建服务器
  • vsdbcmd 用于部署

推荐答案

以下几点让这件事变得更容易:

A couple of things make this easier:

  1. 在包含角色应具有的权限的数据库中创建有意义的角色名称.例如开发"或生产支持".只为这些角色和用户分配权限
  2. 在您的项目中,您大概有针对不同环境的不同部署配置.由于每个配置都可以使用不同的 sqlcmdvars 文件,因此请为您的环境创建一个 SQLCMD 变量并为其添加适当的值(例如,DEV"用于开发,PROD"用于生产)
  3. 创建一个部署后脚本,根据 SQLCMD 变量的值为正确的环境做正确的事情.类似于:

--

if ('$(Environment)' = 'DEV')
begin
   create user [domain\developers]
   exec sp_addrolemember @rolename='db_owner', @membername='domain\developers'
end

这篇关于如何管理开发和生产之间的 SQL 权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆