Created
October 25, 2017 19:36
-
-
Save BasLijten/78f8a736e13b652588666ec18d4e9c39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:SETVAR DatabasePrefix xp0 | |
:SETVAR UserName collectionuser | |
:SETVAR Password Test12345 | |
:SETVAR ShardMapManagerDatabaseNameSuffix _Xdb.Collection.ShardMapManager | |
:SETVAR Shard0DatabaseNameSuffix _Xdb.Collection.Shard0 | |
:SETVAR Shard1DatabaseNameSuffix _Xdb.Collection.Shard1 | |
GO | |
IF(SUSER_ID('$(UserName)') IS NULL) | |
BEGIN | |
CREATE LOGIN [$(UserName)] WITH PASSWORD = '$(Password)'; END; | |
GO | |
USE [$(DatabasePrefix)$(ShardMapManagerDatabaseNameSuffix)] | |
IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'$(UserName)') BEGIN | |
CREATE USER [$(UserName)] FOR LOGIN [$(UserName)] | |
GRANT SELECT ON SCHEMA :: __ShardManagement TO [$(UserName)] GRANT EXECUTE ON SCHEMA :: __ShardManagement TO [$(UserName)] END; | |
GO | |
USE [$(DatabasePrefix)$(Shard0DatabaseNameSuffix)] | |
IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'$(UserName)') BEGIN | |
CREATE USER [$(UserName)] FOR LOGIN [$(UserName)] | |
EXEC [xdb_collection].[GrantLeastPrivilege] @UserName = '$(UserName)' END; | |
GO | |
USE [$(DatabasePrefix)$(Shard1DatabaseNameSuffix)] | |
IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'$(UserName)') BEGIN | |
CREATE USER [$(UserName)] FOR LOGIN [$(UserName)] | |
EXEC [xdb_collection].[GrantLeastPrivilege] @UserName = '$(UserName)' END; | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment