Skip to content

Instantly share code, notes, and snippets.

@BasLijten
Created October 25, 2017 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BasLijten/78f8a736e13b652588666ec18d4e9c39 to your computer and use it in GitHub Desktop.
Save BasLijten/78f8a736e13b652588666ec18d4e9c39 to your computer and use it in GitHub Desktop.
: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